From c11fa122af9bb7b6601560c5e0f840e4dbf78c24 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 28 Jan 2026 12:17:07 +0800 Subject: [PATCH] Update page.js based on the current context. page.js currently always references the page context. But through the inspector JavaScript can be executed in different contexts. When we go from V8->Zig we correctly capture the current context within the caller's Local. And, because of this, mapping or anything else that happens against local.ctx, happens in the right context. EXCEPT...our code still accesses page.js. So you can have a v8->zig call happening in Context-2, and our Zig call then tries to do something on Context-1 via page.js. I'm introducing a change that updates page.js based on the current Caller and restores it at the end of the Caller. This change is super small, but potentially has major impact. It's hard to imagine that we haven't run into problems with this before, and it's hard to imagine what problems this change might introduce. Certainly, if anyone copies page.js, they'll be in for a rude surprise, but i don't think we do that anywhere. --- src/browser/js/Caller.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/browser/js/Caller.zig b/src/browser/js/Caller.zig index 9f48d345..b999c6e0 100644 --- a/src/browser/js/Caller.zig +++ b/src/browser/js/Caller.zig @@ -35,6 +35,7 @@ const IS_DEBUG = @import("builtin").mode == .Debug; const Caller = @This(); local: js.Local, prev_local: ?*const js.Local, +prev_context: *Context, // Takes the raw v8 isolate and extracts the context from it. pub fn init(self: *Caller, v8_isolate: *v8.Isolate) void { @@ -53,7 +54,9 @@ pub fn init(self: *Caller, v8_isolate: *v8.Isolate) void { .isolate = .{ .handle = v8_isolate }, }, .prev_local = ctx.local, + .prev_context = ctx.page.js, }; + ctx.page.js = ctx; ctx.local = &self.local; } @@ -79,6 +82,7 @@ pub fn deinit(self: *Caller) void { ctx.call_depth = call_depth; ctx.local = self.prev_local; + ctx.page.js = self.prev_context; } pub const CallOpts = struct {