@@ -57,8 +57,8 @@ pub const Platform = struct {
5757// The `S` parameter is arbitrary state. When we start an Executor, an instance
5858// of S must be given. This instance is available to any Zig binding.
5959// The `types` parameter is a tuple of Zig structures we want to bind to V8.
60- pub fn Env (comptime S : type , comptime types : anytype ) type {
61- const Types = @typeInfo (@TypeOf ( types ) ).@"struct" .fields ;
60+ pub fn Env (comptime S : type , comptime WebApis : type ) type {
61+ const Types = @typeInfo (WebApis . Interfaces ).@"struct" .fields ;
6262
6363 // Imagine we have a type Cat which has a getter:
6464 //
@@ -97,14 +97,14 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
9797 // TypeLookup. But we put it here, early, so that the rest of the
9898 // code doesn't have to worry about checking if Struct.prototype is
9999 // a pointer.
100- const Struct = @field ( types , s . name ) ;
100+ const Struct = s . defaultValue () .? ;
101101 if (@hasDecl (Struct , "prototype" ) and @typeInfo (Struct .prototype ) != .pointer ) {
102102 @compileError (std .fmt .comptimePrint ("Prototype '{s}' for type '{s} must be a pointer" , .{ @typeName (Struct .prototype ), @typeName (Struct ) }));
103103 }
104104
105105 const subtype : ? SubType = if (@hasDecl (Struct , "subtype" )) Struct .subtype else null ;
106106
107- const R = Receiver (@field ( types , s . name ) );
107+ const R = Receiver (Struct );
108108 fields [i ] = .{
109109 .name = @typeName (R ),
110110 .type = TypeMeta ,
@@ -141,7 +141,7 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
141141 const TYPE_LOOKUP = TypeLookup {};
142142 for (Types , 0.. ) | s , i | {
143143 var prototype_index = i ;
144- const Struct = @field ( types , s . name ) ;
144+ const Struct = s . defaultValue () .? ;
145145 if (@hasDecl (Struct , "prototype" )) {
146146 const TI = @typeInfo (Struct .prototype );
147147 const proto_name = @typeName (Receiver (TI .pointer .child ));
@@ -225,13 +225,13 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
225225 const templates = & env .templates ;
226226 inline for (Types , 0.. ) | s , i | {
227227 @setEvalBranchQuota (10_000 );
228- templates [i ] = v8 .Persistent (v8 .FunctionTemplate ).init (isolate , generateClass (@field ( types , s . name ) , isolate )).castToFunctionTemplate ();
228+ templates [i ] = v8 .Persistent (v8 .FunctionTemplate ).init (isolate , generateClass (s . defaultValue () .? , isolate )).castToFunctionTemplate ();
229229 }
230230
231231 // Above, we've created all our our FunctionTemplates. Now that we
232232 // have them all, we can hook up the prototypes.
233233 inline for (Types , 0.. ) | s , i | {
234- const Struct = @field ( types , s . name ) ;
234+ const Struct = s . defaultValue () .? ;
235235 if (@hasDecl (Struct , "prototype" )) {
236236 const TI = @typeInfo (Struct .prototype );
237237 const proto_name = @typeName (Receiver (TI .pointer .child ));
@@ -360,7 +360,7 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
360360 // are now going to get associated with our global instance.
361361 const templates = & self .env .templates ;
362362 inline for (Types , 0.. ) | s , i | {
363- const Struct = @field ( types , s . name ) ;
363+ const Struct = s . defaultValue () .? ;
364364 const class_name = v8 .String .initUtf8 (isolate , comptime classNameForStruct (Struct ));
365365 global_template .set (class_name .toName (), templates [i ], v8 .PropertyAttribute .None );
366366 }
@@ -387,7 +387,7 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
387387 // https://groups.google.com/g/v8-users/c/qAQQBmbi--8
388388 // TODO: see if newer V8 engines have a way around this.
389389 inline for (Types , 0.. ) | s , i | {
390- const Struct = @field ( types , s . name ) ;
390+ const Struct = s . defaultValue () .? ;
391391
392392 if (@hasDecl (Struct , "prototype" )) {
393393 const proto_type = Receiver (@typeInfo (Struct .prototype ).pointer .child );
@@ -463,7 +463,7 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
463463 // NOTE: there is no way in v8 to subclass the Error built-in type
464464 // TODO: this is an horrible hack
465465 inline for (Types ) | s | {
466- const Struct = @field ( types , s . name ) ;
466+ const Struct = s . defaultValue () .? ;
467467 if (@hasDecl (Struct , "ErrorSet" )) {
468468 const script = comptime classNameForStruct (Struct ) ++ ".prototype.__proto__ = Error.prototype" ;
469469 _ = try scope .exec (script , "errorSubclass" );
0 commit comments