Skip to content

Commit 712aa2a

Browse files
committed
rename scope to context
1 parent 7075120 commit 712aa2a

File tree

12 files changed

+255
-255
lines changed

12 files changed

+255
-255
lines changed

src/browser/page.zig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub const Page = struct {
8383

8484
// Our JavaScript context for this specific page. This is what we use to
8585
// execute any JavaScript
86-
scope: *Env.Scope,
86+
main_context: *Env.Context,
8787

8888
// For a Page we only create one HandleScope and keep it alive for the duration of the page.
8989
// If needed JS Locals' lifetimes can be reduced by layering on additional Scopes.
@@ -112,22 +112,22 @@ pub const Page = struct {
112112
.microtask_node = .{ .func = microtaskCallback },
113113
.window_clicked_event_node = .{ .func = windowClicked },
114114
.request_factory = browser.http_client.requestFactory(browser.notification),
115-
.scope = undefined,
115+
.main_context = undefined,
116116
.handle_scope = undefined,
117117
.module_map = .empty,
118118
};
119119

120-
self.scope = try session.executor.startScope(&self.window, self, self);
120+
self.main_context = try session.executor.createContext(&self.window, self, self);
121121

122122
// Start a scope (stackframe) for JS Local variables.
123123
Env.HandleScope.init(&self.handle_scope, browser.env.isolate);
124124
errdefer self.handle_scope.deinit();
125125

126-
self.scope.enter();
127-
errdefer self.scope.exit();
126+
self.main_context.enter();
127+
errdefer self.main_context.exit();
128128

129129
// load polyfills
130-
try polyfill.load(self.arena, self.scope);
130+
try polyfill.load(self.arena, self.main_context);
131131

132132
_ = try session.browser.app.loop.timeout(1 * std.time.ns_per_ms, &self.microtask_node);
133133
}
@@ -169,7 +169,7 @@ pub const Page = struct {
169169

170170
pub fn wait(self: *Page) !void {
171171
var try_catch: Env.TryCatch = undefined;
172-
try_catch.init(self.scope);
172+
try_catch.init(self.main_context);
173173
defer try_catch.deinit();
174174

175175
try self.session.browser.app.loop.run();
@@ -664,14 +664,14 @@ const Script = struct {
664664

665665
fn eval(self: *const Script, page: *Page, body: []const u8) !void {
666666
var try_catch: Env.TryCatch = undefined;
667-
try_catch.init(page.scope);
667+
try_catch.init(page.main_context); // Sjors: Is this always the main context?
668668
defer try_catch.deinit();
669669

670670
const src = self.src orelse "inline";
671671
const res = switch (self.kind) {
672-
.javascript => page.scope.exec(body, src),
672+
.javascript => page.main_context.exec(body, src),
673673
.module => blk: {
674-
switch (try page.scope.module(body, src)) {
674+
switch (try page.main_context.module(body, src)) {
675675
.value => |v| break :blk v,
676676
.exception => |e| {
677677
log.warn(.page, "eval module", .{ .src = src, .err = try e.exception(page.arena) });
@@ -688,7 +688,7 @@ const Script = struct {
688688
_ = res;
689689

690690
if (self.onload) |onload| {
691-
_ = page.scope.exec(onload, "script_on_load") catch {
691+
_ = page.main_context.exec(onload, "script_on_load") catch {
692692
if (try try_catch.err(page.arena)) |msg| {
693693
log.warn(.page, "eval onload", .{ .src = src, .err = msg });
694694
}

src/browser/polyfill/fetch.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test "Browser.fetch" {
1616
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
1717
defer runner.deinit();
1818

19-
try @import("polyfill.zig").load(testing.allocator, runner.page.scope);
19+
try @import("polyfill.zig").load(testing.allocator, runner.page.main_context);
2020

2121
try runner.testCases(&.{
2222
.{

src/browser/polyfill/polyfill.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ const modules = [_]struct {
3030
.{ .name = "polyfill-fetch", .source = @import("fetch.zig").source },
3131
};
3232

33-
pub fn load(allocator: Allocator, scope: *Env.Scope) !void {
33+
pub fn load(allocator: Allocator, context: *Env.Context) !void {
3434
var try_catch: Env.TryCatch = undefined;
35-
try_catch.init(scope);
35+
try_catch.init(context);
3636
defer try_catch.deinit();
3737

3838
for (modules) |m| {
39-
_ = scope.exec(m.source, m.name) catch |err| {
39+
_ = context.exec(m.source, m.name) catch |err| {
4040
if (try try_catch.err(allocator)) |msg| {
4141
defer allocator.free(msg);
4242
log.err(.polyfill, "exec error", .{ .name = m.name, .err = msg });

src/browser/session.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ pub const Session = struct {
110110
// Reset all existing callbacks.
111111
self.browser.app.loop.reset();
112112

113-
self.executor.scope.?.exit();
114-
self.executor.endScope();
113+
self.executor.context.?.exit();
114+
self.executor.destroyContext();
115115

116116
self.page.?.handle_scope.deinit();
117117
self.page = null;

src/cdp/cdp.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ const IsolatedWorld = struct {
544544
self.executor.deinit();
545545
}
546546
pub fn removeContext(self: *IsolatedWorld) !void {
547-
if (self.executor.scope == null) return error.NoIsolatedContextToRemove;
548-
self.executor.endScope();
547+
if (self.executor.context == null) return error.NoIsolatedContextToRemove;
548+
self.executor.destroyContext();
549549
}
550550

551551
// The isolate world must share at least some of the state with the related page, specifically the DocumentHTML
@@ -554,8 +554,8 @@ const IsolatedWorld = struct {
554554
// This also means this pointer becomes invalid after removePage untill a new page is created.
555555
// Currently we have only 1 page/frame and thus also only 1 state in the isolate world.
556556
pub fn createContext(self: *IsolatedWorld, page: *Page) !void {
557-
if (self.executor.scope != null) return error.Only1IsolatedContextSupported;
558-
_ = try self.executor.startScope(&page.window, page, {});
557+
if (self.executor.context != null) return error.Only1IsolatedContextSupported;
558+
_ = try self.executor.createContext(&page.window, page, {});
559559
}
560560
};
561561

src/cdp/domains/dom.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,13 @@ fn resolveNode(cmd: anytype) !void {
259259
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
260260
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
261261

262-
var scope = page.scope;
262+
var context = page.main_context;
263263
if (params.executionContextId) |context_id| {
264-
if (scope.context.debugContextId() != context_id) {
264+
if (context.v8_context.debugContextId() != context_id) {
265265
var isolated_world = bc.isolated_world orelse return error.ContextNotFound;
266-
scope = &(isolated_world.executor.scope orelse return error.ContextNotFound);
266+
context = &(isolated_world.executor.context orelse return error.ContextNotFound);
267267

268-
if (scope.context.debugContextId() != context_id) return error.ContextNotFound;
268+
if (context.v8_context.debugContextId() != context_id) return error.ContextNotFound;
269269
}
270270
}
271271

@@ -275,7 +275,7 @@ fn resolveNode(cmd: anytype) !void {
275275
// node._node is a *parser.Node we need this to be able to find its most derived type e.g. Node -> Element -> HTMLElement
276276
// So we use the Node.Union when retrieve the value from the environment
277277
const remote_object = try bc.inspector.getRemoteObject(
278-
scope,
278+
context,
279279
params.objectGroup orelse "",
280280
try dom_node.Node.toInterface(node._node),
281281
);

src/cdp/domains/page.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ fn createIsolatedWorld(cmd: anytype) !void {
117117
const world = try bc.createIsolatedWorld(params.worldName, params.grantUniveralAccess);
118118
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
119119
try pageCreated(bc, page);
120-
const scope = &world.executor.scope.?;
120+
const context = &world.executor.context.?;
121121

122122
// Create the auxdata json for the contextCreated event
123123
// Calling contextCreated will assign a Id to the context and send the contextCreated event
124124
const aux_data = try std.fmt.allocPrint(cmd.arena, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{params.frameId});
125-
bc.inspector.contextCreated(scope, world.name, "", aux_data, false);
125+
bc.inspector.contextCreated(context, world.name, "", aux_data, false);
126126

127-
return cmd.sendResult(.{ .executionContextId = scope.context.debugContextId() }, .{});
127+
return cmd.sendResult(.{ .executionContextId = context.v8_context.debugContextId() }, .{});
128128
}
129129

130130
fn navigate(cmd: anytype) !void {
@@ -239,7 +239,7 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
239239
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
240240
const aux_data = try std.fmt.allocPrint(arena, "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{target_id});
241241
bc.inspector.contextCreated(
242-
page.scope,
242+
page.main_context,
243243
"",
244244
try page.origin(arena),
245245
aux_data,
@@ -250,7 +250,7 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
250250
const aux_json = try std.fmt.allocPrint(arena, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{target_id});
251251
// Calling contextCreated will assign a new Id to the context and send the contextCreated event
252252
bc.inspector.contextCreated(
253-
&isolated_world.executor.scope.?,
253+
&isolated_world.executor.context.?,
254254
isolated_world.name,
255255
"://",
256256
aux_json,
@@ -272,7 +272,7 @@ pub fn pageCreated(bc: anytype, page: *Page) !void {
272272
try isolated_world.createContext(page);
273273

274274
const polyfill = @import("../../browser/polyfill/polyfill.zig");
275-
try polyfill.load(bc.arena, &isolated_world.executor.scope.?);
275+
try polyfill.load(bc.arena, &isolated_world.executor.context.?);
276276
}
277277
}
278278

src/cdp/domains/target.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn createTarget(cmd: anytype) !void {
127127
{
128128
const aux_data = try std.fmt.allocPrint(cmd.arena, "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{target_id});
129129
bc.inspector.contextCreated(
130-
page.scope,
130+
page.main_context,
131131
"",
132132
try page.origin(cmd.arena),
133133
aux_data,

src/main_wpt.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn run(arena: Allocator, test_file: []const u8, loader: *FileLoader, err_out: *?
113113
});
114114
defer runner.deinit();
115115

116-
try polyfill.load(arena, runner.page.scope);
116+
try polyfill.load(arena, runner.page.main_context);
117117

118118
// loop over the scripts.
119119
const doc = parser.documentHTMLToDocument(runner.page.window.document);
@@ -155,7 +155,7 @@ fn run(arena: Allocator, test_file: []const u8, loader: *FileLoader, err_out: *?
155155
{
156156
// wait for all async executions
157157
var try_catch: Env.TryCatch = undefined;
158-
try_catch.init(runner.page.scope);
158+
try_catch.init(runner.page.main_context);
159159
defer try_catch.deinit();
160160
try runner.page.loop.run();
161161

0 commit comments

Comments
 (0)