Remove js.ExecutionWorld

The ExecutionWorld doesn't do anything meaningful. It doesn't map to, or
abstract any, v8 concepts. It creates a js.Context, destroys the context and
points to the context. Those all all things the Env can do (and it isn't like
the Env is over-burdened as-is).

Plus the benefit of going through the Env is that we can track/collect all
known Contexts for an isolate in 1 place (the Env), which can facilitate things
like context creation/deletion notifications.
This commit is contained in:
Karl Seguin
2026-01-29 11:22:01 +08:00
parent 232e7a1759
commit 1a05da9e55
11 changed files with 132 additions and 192 deletions

View File

@@ -467,15 +467,13 @@ pub fn BrowserContext(comptime CDP_T: type) type {
}
pub fn createIsolatedWorld(self: *Self, world_name: []const u8, grant_universal_access: bool) !*IsolatedWorld {
var executor = try self.cdp.browser.env.newExecutionWorld();
errdefer executor.deinit();
const owned_name = try self.arena.dupe(u8, world_name);
const world = try self.isolated_worlds.addOne(self.arena);
world.* = .{
.context = null,
.name = owned_name,
.executor = executor,
.env = &self.cdp.browser.env,
.grant_universal_access = grant_universal_access,
};
@@ -746,15 +744,20 @@ pub fn BrowserContext(comptime CDP_T: type) type {
/// An object id is unique across all contexts, different object ids can refer to the same Node in different contexts.
const IsolatedWorld = struct {
name: []const u8,
executor: js.ExecutionWorld,
env: *js.Env,
context: ?*js.Context = null,
grant_universal_access: bool,
pub fn deinit(self: *IsolatedWorld) void {
self.executor.deinit();
if (self.context) |ctx| {
self.env.destroyContext(ctx);
self.context = null;
}
}
pub fn removeContext(self: *IsolatedWorld) !void {
if (self.executor.context == null) return error.NoIsolatedContextToRemove;
self.executor.removeContext();
const ctx = self.context orelse return error.NoIsolatedContextToRemove;
self.env.destroyContext(ctx);
self.context = null;
}
// The isolate world must share at least some of the state with the related page, specifically the DocumentHTML
@@ -762,19 +765,16 @@ const IsolatedWorld = struct {
// We just created the world and the page. The page's state lives in the session, but is update on navigation.
// This also means this pointer becomes invalid after removePage until a new page is created.
// Currently we have only 1 page/frame and thus also only 1 state in the isolate world.
pub fn createContext(self: *IsolatedWorld, page: *Page) !void {
// if (self.executor.context != null) return error.Only1IsolatedContextSupported;
if (self.executor.context != null) {
pub fn createContext(self: *IsolatedWorld, page: *Page) !*js.Context {
if (self.context == null) {
self.context = try self.env.createContext(page, false);
} else {
log.warn(.cdp, "not implemented", .{
.feature = "createContext: Not implemented second isolated context creation",
.info = "reuse existing context",
});
return;
}
_ = try self.executor.createContext(
page,
false,
);
return self.context.?;
}
};

View File

@@ -288,7 +288,7 @@ fn resolveNode(cmd: anytype) !void {
ls.?.deinit();
ls = null;
const ctx = &(isolated_world.executor.context orelse return error.ContextNotFound);
const ctx = (isolated_world.context orelse return error.ContextNotFound);
ls = undefined;
ctx.localScope(&ls.?);
if (ls.?.local.debugContextId() == context_id) {

View File

@@ -190,8 +190,7 @@ fn createIsolatedWorld(cmd: anytype) !void {
const world = try bc.createIsolatedWorld(params.worldName, params.grantUniveralAccess);
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
try world.createContext(page);
const js_context = &world.executor.context.?;
const js_context = try world.createContext(page);
// Create the auxdata json for the contextCreated event
// Calling contextCreated will assign a Id to the context and send the contextCreated event
@@ -292,7 +291,7 @@ pub fn pageRemove(bc: anytype) !void {
pub fn pageCreated(bc: anytype, page: *Page) !void {
for (bc.isolated_worlds.items) |*isolated_world| {
try isolated_world.createContext(page);
_ = try isolated_world.createContext(page);
}
}
@@ -375,7 +374,7 @@ pub fn pageNavigated(arena: Allocator, bc: anytype, event: *const Notification.P
// Calling contextCreated will assign a new Id to the context and send the contextCreated event
var ls: js.Local.Scope = undefined;
(isolated_world.executor.context orelse continue).localScope(&ls);
(isolated_world.context orelse continue).localScope(&ls);
defer ls.deinit();
bc.inspector.contextCreated(