Skip to content

Commit 130c749

Browse files
committed
update zig-jsruntime
1 parent 9fe1074 commit 130c749

File tree

5 files changed

+24
-29
lines changed

5 files changed

+24
-29
lines changed

src/browser/browser.zig

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub const Session = struct {
166166
// const ctx_opaque = @as(*anyopaque, @ptrCast(ctx));
167167
self.inspector = try jsruntime.Inspector.init(
168168
arena,
169-
self.env, // TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
169+
&self.env,
170170
if (@TypeOf(ctx) == void) @constCast(@ptrCast(&{})) else ctx,
171171
InspectorContainer.onInspectorResponse,
172172
InspectorContainer.onInspectorEvent,
@@ -231,8 +231,7 @@ pub const Session = struct {
231231
}
232232

233233
// load polyfills
234-
// TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
235-
try polyfill.load(self.arena.allocator(), self.env);
234+
try polyfill.load(self.arena.allocator(), &self.env);
236235

237236
// inspector
238237
self.contextCreated(page, aux_data);
@@ -265,7 +264,7 @@ pub const Session = struct {
265264

266265
fn contextCreated(self: *Session, page: *Page, aux_data: ?[]const u8) void {
267266
log.debug("inspector context created", .{});
268-
self.inspector.contextCreated(self.env, "", page.origin orelse "://", aux_data);
267+
self.inspector.contextCreated(&self.env, "", page.origin orelse "://", aux_data);
269268
}
270269
};
271270

@@ -317,15 +316,15 @@ pub const Page = struct {
317316
pub fn wait(self: *Page) !void {
318317
// try catch
319318
var try_catch: jsruntime.TryCatch = undefined;
320-
try_catch.init(self.session.env);
319+
try_catch.init(&self.session.env);
321320
defer try_catch.deinit();
322321

323322
self.session.env.wait() catch |err| {
324323
// the js env could not be started if the document wasn't an HTML.
325324
if (err == error.EnvNotStarted) return;
326325

327326
const arena = self.arena;
328-
if (try try_catch.err(arena, self.session.env)) |msg| {
327+
if (try try_catch.err(arena, &self.session.env)) |msg| {
329328
defer arena.free(msg);
330329
log.info("wait error: {s}", .{msg});
331330
return;
@@ -592,8 +591,6 @@ pub const Page = struct {
592591
// TODO handle charset attribute
593592
const opt_text = try parser.nodeTextContent(parser.elementToNode(s.element));
594593
if (opt_text) |text| {
595-
// TODO: change to &self.session.env when
596-
// https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
597594
try s.eval(self.arena, self.session.env, text);
598595
return;
599596
}
@@ -659,8 +656,6 @@ pub const Page = struct {
659656
const arena = self.arena;
660657

661658
const body = try self.fetchData(arena, s.src, null);
662-
// TODO: change to &self.session.env when
663-
// https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
664659
try s.eval(arena, self.session.env, body);
665660
}
666661

@@ -704,24 +699,24 @@ pub const Page = struct {
704699
return .unknown;
705700
}
706701

707-
fn eval(self: Script, arena: Allocator, env: Env, body: []const u8) !void {
702+
fn eval(self: Script, arena: Allocator, env: Env, body: []const u8) !void { // TODO use an *const Env
708703
var try_catch: jsruntime.TryCatch = undefined;
709-
try_catch.init(env);
704+
try_catch.init(&env);
710705
defer try_catch.deinit();
711706

712707
const res = switch (self.kind) {
713708
.unknown => return error.UnknownScript,
714-
.javascript => env.exec(body, self.src),
715-
.module => env.module(body, self.src),
709+
.javascript => env.exec(body, self.src), // TODO use an *const Env
710+
.module => env.module(body, self.src), // TODO use an *const Env
716711
} catch {
717-
if (try try_catch.err(arena, env)) |msg| {
712+
if (try try_catch.err(arena, &env)) |msg| {
718713
log.info("eval script {s}: {s}", .{ self.src, msg });
719714
}
720715
return FetchError.JsErr;
721716
};
722717

723718
if (builtin.mode == .Debug) {
724-
const msg = try res.toString(arena, env);
719+
const msg = try res.toString(arena, &env);
725720
log.debug("eval script {s}: {s}", .{ self.src, msg });
726721
}
727722
}

src/polyfill/fetch.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn testExecFn(
2020
alloc: std.mem.Allocator,
2121
js_env: *jsruntime.Env,
2222
) anyerror!void {
23-
try @import("polyfill.zig").load(alloc, js_env.*);
23+
try @import("polyfill.zig").load(alloc, js_env);
2424

2525
var fetch = [_]Case{
2626
.{

src/polyfill/polyfill.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const modules = [_]struct {
3333
.{ .name = "polyfill-fetch", .source = @import("fetch.zig").source },
3434
};
3535

36-
pub fn load(alloc: std.mem.Allocator, env: Env) !void {
36+
pub fn load(alloc: std.mem.Allocator, env: *const Env) !void {
3737
var try_catch: jsruntime.TryCatch = undefined;
3838
try_catch.init(env);
3939
defer try_catch.deinit();

src/wpt/run.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
7777
defer js_env.stop();
7878

7979
// load polyfills
80-
try polyfill.load(alloc, js_env);
80+
try polyfill.load(alloc, &js_env);
8181

8282
// display console logs
8383
defer {
84-
const res = evalJS(js_env, alloc, "console.join('\\n');", "console") catch unreachable;
84+
const res = evalJS(&js_env, alloc, "console.join('\\n');", "console") catch unreachable;
8585
defer res.deinit(alloc);
8686

8787
if (res.msg != null and res.msg.?.len > 0) {
@@ -104,7 +104,7 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
104104
\\ console.push("debug", ...arguments);
105105
\\};
106106
;
107-
var res = try evalJS(js_env, alloc, init, "init");
107+
var res = try evalJS(&js_env, alloc, init, "init");
108108
if (!res.ok) return res;
109109
res.deinit(alloc);
110110

@@ -123,14 +123,14 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
123123
path = try fspath.join(alloc, &.{ "/", dirname, path });
124124
}
125125

126-
res = try evalJS(js_env, alloc, try loader.get(path), src);
126+
res = try evalJS(&js_env, alloc, try loader.get(path), src);
127127
if (!res.ok) return res;
128128
res.deinit(alloc);
129129
}
130130

131131
// If the script as a source text, execute it.
132132
const src = try parser.nodeTextContent(s) orelse continue;
133-
res = try evalJS(js_env, alloc, src, "");
133+
res = try evalJS(&js_env, alloc, src, "");
134134
if (!res.ok) return res;
135135
res.deinit(alloc);
136136
}
@@ -147,22 +147,22 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
147147

148148
// wait for all async executions
149149
var try_catch: jsruntime.TryCatch = undefined;
150-
try_catch.init(js_env);
150+
try_catch.init(&js_env);
151151
defer try_catch.deinit();
152152
js_env.wait() catch {
153153
return .{
154154
.ok = false,
155-
.msg = try try_catch.err(alloc, js_env),
155+
.msg = try try_catch.err(alloc, &js_env),
156156
};
157157
};
158158

159159
// Check the final test status.
160-
res = try evalJS(js_env, alloc, "report.status;", "teststatus");
160+
res = try evalJS(&js_env, alloc, "report.status;", "teststatus");
161161
if (!res.ok) return res;
162162
res.deinit(alloc);
163163

164164
// return the detailed result.
165-
return try evalJS(js_env, alloc, "report.log", "teststatus");
165+
return try evalJS(&js_env, alloc, "report.log", "teststatus");
166166
}
167167

168168
pub const Res = struct {
@@ -176,7 +176,7 @@ pub const Res = struct {
176176
}
177177
};
178178

179-
fn evalJS(env: jsruntime.Env, alloc: std.mem.Allocator, script: []const u8, name: ?[]const u8) !Res {
179+
fn evalJS(env: *const jsruntime.Env, alloc: std.mem.Allocator, script: []const u8, name: ?[]const u8) !Res {
180180
var try_catch: jsruntime.TryCatch = undefined;
181181
try_catch.init(env);
182182
defer try_catch.deinit();

0 commit comments

Comments
 (0)