@@ -36,6 +36,7 @@ pub const ModuleLoadFn = *const fn (ctx: *anyopaque, referrer: ?Module, specifie
3636pub const LoadFnType = @import ("generate.zig" ).LoadFnType ;
3737pub const loadFn = @import ("generate.zig" ).loadFn ;
3838const setNativeObject = @import ("generate.zig" ).setNativeObject ;
39+ const setNativeType = @import ("generate.zig" ).setNativeType ;
3940const loadFunctionTemplate = @import ("generate.zig" ).loadFunctionTemplate ;
4041const bindObjectNativeAndJS = @import ("generate.zig" ).bindObjectNativeAndJS ;
4142const getTpl = @import ("generate.zig" ).getTpl ;
@@ -351,6 +352,25 @@ pub const Env = struct {
351352 }
352353 }
353354
355+ // Currently used for DOM nodes
356+ // - value Note: *parser.Node should be converted to dom/node.zig.Union to get the most precise type
357+ pub fn findOrAddValue (env : * Env , value : anytype ) ! v8.Value {
358+ comptime var ret : refl.Type = undefined ;
359+ comptime {
360+ @setEvalBranchQuota (150_000 ); // Needed when this is called with a dom/node.zig.Union
361+ ret = try refl .Type .reflect (@TypeOf (value ), null );
362+ try ret .lookup (gen .Types );
363+ }
364+ return try setNativeType (
365+ env .nat_ctx .alloc ,
366+ & env .nat_ctx ,
367+ ret ,
368+ value ,
369+ env .js_ctx .? ,
370+ env .isolate ,
371+ );
372+ }
373+
354374 // compile and run a JS script
355375 // It doesn't wait for callbacks execution
356376 pub fn exec (
@@ -720,29 +740,11 @@ pub const Inspector = struct {
720740 return self .session .dispatchProtocolMessage (env .isolate , msg );
721741 }
722742
723- // Inspector's wrapObject for use in resolveNode . We may extend the interface here to include:
743+ // Retrieves the RemoteObject for a given JsValue . We may extend the interface here to include:
724744 // backendNodeId, objectGroup, executionContextId. For a complete resolveNode implementation at this level.
725- // node_ptr is expected to be a sub-type of *parser.Node
726- pub fn wrapObject (self : Inspector , env : * Env , node_ptr : anytype ) ! v8.RemoteObject {
727- // Find or bind Native and JS objects together, if it does not already exist
728- // NOTE: We're not using env.addObject(..) as it registers a named variable at global scope
729- const T_refl = comptime gen .getType (@TypeOf (node_ptr ));
730- const js_object = try setNativeObject (
731- env .nat_ctx .alloc ,
732- & env .nat_ctx ,
733- T_refl ,
734- T_refl .value .underT (),
735- node_ptr ,
736- null ,
737- env .isolate ,
738- env .js_ctx .? ,
739- );
740- const js_value = js_object .toValue ();
741-
742- // Temporary defaults for which we do not know yet what they are for
743- const group_name = "AGroupName" ;
744- const generate_preview = false ;
745- return self .session .wrapObject (env .isolate , env .js_ctx .? , js_value , group_name , generate_preview );
745+ pub fn getRemoteObject (self : Inspector , env : * Env , jsValue : v8.Value , groupName : []const u8 ) ! v8.RemoteObject {
746+ const generatePreview = false ; // We do not want to expose this as a parameter for now
747+ return self .session .wrapObject (env .isolate , env .js_ctx .? , jsValue , groupName , generatePreview );
746748 }
747749};
748750
0 commit comments