@@ -156,16 +156,16 @@ pub const Session = struct {
156
156
157
157
const ContextT = @TypeOf (ctx );
158
158
const InspectorContainer = switch (@typeInfo (ContextT )) {
159
- .Struct = > ContextT ,
160
- .Pointer = > | ptr | ptr .child ,
161
- .Void = > NoopInspector ,
159
+ .@"struct" = > ContextT ,
160
+ .pointer = > | ptr | ptr .child ,
161
+ .void = > NoopInspector ,
162
162
else = > @compileError ("invalid context type" ),
163
163
};
164
164
165
165
// const ctx_opaque = @as(*anyopaque, @ptrCast(ctx));
166
166
self .inspector = try jsruntime .Inspector .init (
167
167
arena ,
168
- self .env , // TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
168
+ & self .env ,
169
169
if (@TypeOf (ctx ) == void ) @constCast (@ptrCast (&{})) else ctx ,
170
170
InspectorContainer .onInspectorResponse ,
171
171
InspectorContainer .onInspectorEvent ,
@@ -231,7 +231,7 @@ pub const Session = struct {
231
231
232
232
// load polyfills
233
233
// TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
234
- try polyfill .load (self .arena .allocator (), self .env );
234
+ try polyfill .load (self .arena .allocator (), & self .env );
235
235
236
236
// inspector
237
237
self .contextCreated (page , aux_data );
@@ -264,7 +264,7 @@ pub const Session = struct {
264
264
265
265
fn contextCreated (self : * Session , page : * Page , aux_data : ? []const u8 ) void {
266
266
log .debug ("inspector context created" , .{});
267
- self .inspector .contextCreated (self .env , "" , page .origin orelse "://" , aux_data );
267
+ self .inspector .contextCreated (& self .env , "" , page .origin orelse "://" , aux_data );
268
268
}
269
269
};
270
270
@@ -316,15 +316,15 @@ pub const Page = struct {
316
316
pub fn wait (self : * Page ) ! void {
317
317
// try catch
318
318
var try_catch : jsruntime.TryCatch = undefined ;
319
- try_catch .init (self .session .env );
319
+ try_catch .init (& self .session .env );
320
320
defer try_catch .deinit ();
321
321
322
322
self .session .env .wait () catch | err | {
323
323
// the js env could not be started if the document wasn't an HTML.
324
324
if (err == error .EnvNotStarted ) return ;
325
325
326
326
const arena = self .arena ;
327
- if (try try_catch .err (arena , self .session .env )) | msg | {
327
+ if (try try_catch .err (arena , & self .session .env )) | msg | {
328
328
defer arena .free (msg );
329
329
log .info ("wait error: {s}" , .{msg });
330
330
return ;
@@ -591,9 +591,7 @@ pub const Page = struct {
591
591
// TODO handle charset attribute
592
592
const opt_text = try parser .nodeTextContent (parser .elementToNode (s .element ));
593
593
if (opt_text ) | text | {
594
- // TODO: change to &self.session.env when
595
- // https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
596
- try s .eval (self .arena , self .session .env , text );
594
+ try s .eval (self .arena , & self .session .env , text );
597
595
return ;
598
596
}
599
597
@@ -656,11 +654,8 @@ pub const Page = struct {
656
654
// received.
657
655
fn fetchScript (self : * const Page , s : * const Script ) ! void {
658
656
const arena = self .arena ;
659
-
660
657
const body = try self .fetchData (arena , s .src , null );
661
- // TODO: change to &self.session.env when
662
- // https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
663
- try s .eval (arena , self .session .env , body );
658
+ try s .eval (arena , & self .session .env , body );
664
659
}
665
660
666
661
const Script = struct {
@@ -683,9 +678,8 @@ pub const Page = struct {
683
678
684
679
return .{
685
680
.element = e ,
686
- .kind = kind (try parser .elementGetAttribute (e , "type" )),
681
+ .kind = parseKind (try parser .elementGetAttribute (e , "type" )),
687
682
.is_async = try parser .elementGetAttribute (e , "async" ) != null ,
688
-
689
683
.src = try parser .elementGetAttribute (e , "src" ) orelse "inline" ,
690
684
};
691
685
}
@@ -695,15 +689,15 @@ pub const Page = struct {
695
689
// > type indicates that the script is a "classic script", containing
696
690
// > JavaScript code.
697
691
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type
698
- fn kind (stype : ? []const u8 ) Kind {
692
+ fn parseKind (stype : ? []const u8 ) Kind {
699
693
if (stype == null or stype .? .len == 0 ) return .javascript ;
700
694
if (std .mem .eql (u8 , stype .? , "application/javascript" )) return .javascript ;
701
695
if (std .mem .eql (u8 , stype .? , "module" )) return .module ;
702
696
703
697
return .unknown ;
704
698
}
705
699
706
- fn eval (self : Script , arena : Allocator , env : Env , body : []const u8 ) ! void {
700
+ fn eval (self : Script , arena : Allocator , env : * const Env , body : []const u8 ) ! void {
707
701
var try_catch : jsruntime.TryCatch = undefined ;
708
702
try_catch .init (env );
709
703
defer try_catch .deinit ();
0 commit comments