Skip to content

Commit 2f6e021

Browse files
committed
rename scope jscontext
1 parent 9bd5ff6 commit 2f6e021

File tree

12 files changed

+306
-306
lines changed

12 files changed

+306
-306
lines changed

src/browser/page.zig

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

8686
// Our JavaScript context for this specific page. This is what we use to
8787
// execute any JavaScript
88-
scope: *Env.Scope,
88+
main_context: *Env.JsContext,
8989

9090
// List of modules currently fetched/loaded.
9191
module_map: std.StringHashMapUnmanaged([]const u8),
@@ -118,13 +118,13 @@ pub const Page = struct {
118118
.request_factory = browser.http_client.requestFactory(.{
119119
.notification = browser.notification,
120120
}),
121-
.scope = undefined,
121+
.main_context = undefined,
122122
.module_map = .empty,
123123
};
124-
self.scope = try session.executor.startScope(&self.window, self, self, true);
124+
self.main_context = try session.executor.createJsContext(&self.window, self, self, true);
125125

126126
// load polyfills
127-
try polyfill.load(self.arena, self.scope);
127+
try polyfill.load(self.arena, self.main_context);
128128

129129
_ = try session.browser.app.loop.timeout(1 * std.time.ns_per_ms, &self.microtask_node);
130130
}
@@ -166,7 +166,7 @@ pub const Page = struct {
166166

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

172172
try self.session.browser.app.loop.run();
@@ -798,7 +798,7 @@ pub const Page = struct {
798798

799799
pub fn stackTrace(self: *Page) !?[]const u8 {
800800
if (comptime builtin.mode == .Debug) {
801-
return self.scope.stackTrace();
801+
return self.main_context.stackTrace();
802802
}
803803
return null;
804804
}
@@ -982,14 +982,14 @@ const Script = struct {
982982

983983
fn eval(self: *const Script, page: *Page, body: []const u8) !void {
984984
var try_catch: Env.TryCatch = undefined;
985-
try_catch.init(page.scope);
985+
try_catch.init(page.main_context);
986986
defer try_catch.deinit();
987987

988988
const src = self.src orelse "inline";
989989
_ = switch (self.kind) {
990-
.javascript => page.scope.exec(body, src),
990+
.javascript => page.main_context.exec(body, src),
991991
.module => blk: {
992-
switch (try page.scope.module(body, src)) {
992+
switch (try page.main_context.module(body, src)) {
993993
.value => |v| break :blk v,
994994
.exception => |e| {
995995
log.warn(.user_script, "eval module", .{
@@ -1023,9 +1023,9 @@ const Script = struct {
10231023
switch (callback) {
10241024
.string => |str| {
10251025
var try_catch: Env.TryCatch = undefined;
1026-
try_catch.init(page.scope);
1026+
try_catch.init(page.main_context);
10271027
defer try_catch.deinit();
1028-
_ = page.scope.exec(str, typ) catch {
1028+
_ = page.main_context.exec(str, typ) catch {
10291029
if (try try_catch.err(page.arena)) |msg| {
10301030
log.warn(.user_script, "script callback", .{
10311031
.src = self.src,

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, js_context: *Env.JsContext) !void {
3434
var try_catch: Env.TryCatch = undefined;
35-
try_catch.init(scope);
35+
try_catch.init(js_context);
3636
defer try_catch.deinit();
3737

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

src/browser/session.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ pub const Session = struct {
116116
// phase. It's important that we clean these up, as they're holding onto
117117
// limited resources (like our fixed-sized http state pool).
118118
//
119-
// First thing we do, is endScope() which will execute the destructor
119+
// First thing we do, is removeJsContext() which will execute the destructor
120120
// of any type that registered a destructor (e.g. XMLHttpRequest).
121121
// This will shutdown any pending sockets, which begins our cleaning
122122
// processed
123-
self.executor.endScope();
123+
self.executor.removeJsContext();
124124

125125
// Second thing we do is reset the loop. This increments the loop ctx_id
126126
// so that any "stale" timeouts we process will get ignored. We need to

src/cdp/cdp.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ const IsolatedWorld = struct {
555555
self.executor.deinit();
556556
}
557557
pub fn removeContext(self: *IsolatedWorld) !void {
558-
if (self.executor.scope == null) return error.NoIsolatedContextToRemove;
559-
self.executor.endScope();
558+
if (self.executor.js_context == null) return error.NoIsolatedContextToRemove;
559+
self.executor.removeJsContext();
560560
}
561561

562562
// The isolate world must share at least some of the state with the related page, specifically the DocumentHTML
@@ -565,8 +565,8 @@ const IsolatedWorld = struct {
565565
// This also means this pointer becomes invalid after removePage untill a new page is created.
566566
// Currently we have only 1 page/frame and thus also only 1 state in the isolate world.
567567
pub fn createContext(self: *IsolatedWorld, page: *Page) !void {
568-
if (self.executor.scope != null) return error.Only1IsolatedContextSupported;
569-
_ = try self.executor.startScope(&page.window, page, {}, false);
568+
if (self.executor.js_context != null) return error.Only1IsolatedContextSupported;
569+
_ = try self.executor.createJsContext(&page.window, page, {}, false);
570570
}
571571
};
572572

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 js_context = page.main_context;
263263
if (params.executionContextId) |context_id| {
264-
if (scope.context.debugContextId() != context_id) {
264+
if (js_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+
js_context = &(isolated_world.executor.js_context orelse return error.ContextNotFound);
267267

268-
if (scope.context.debugContextId() != context_id) return error.ContextNotFound;
268+
if (js_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+
js_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 js_context = &world.executor.js_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(js_context, world.name, "", aux_data, false);
126126

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

130130
fn navigate(cmd: anytype) !void {
@@ -253,7 +253,7 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
253253
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
254254
const aux_data = try std.fmt.allocPrint(arena, "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{target_id});
255255
bc.inspector.contextCreated(
256-
page.scope,
256+
page.main_context,
257257
"",
258258
try page.origin(arena),
259259
aux_data,
@@ -264,7 +264,7 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
264264
const aux_json = try std.fmt.allocPrint(arena, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{target_id});
265265
// Calling contextCreated will assign a new Id to the context and send the contextCreated event
266266
bc.inspector.contextCreated(
267-
&isolated_world.executor.scope.?,
267+
&isolated_world.executor.js_context.?,
268268
isolated_world.name,
269269
"://",
270270
aux_json,
@@ -286,7 +286,7 @@ pub fn pageCreated(bc: anytype, page: *Page) !void {
286286
try isolated_world.createContext(page);
287287

288288
const polyfill = @import("../../browser/polyfill/polyfill.zig");
289-
try polyfill.load(bc.arena, &isolated_world.executor.scope.?);
289+
try polyfill.load(bc.arena, &isolated_world.executor.js_context.?);
290290
}
291291
}
292292

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)