Skip to content

Commit 9dd0174

Browse files
committed
browsercontext arena
1 parent 9c4df41 commit 9dd0174

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/browser/browser.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ pub const Session = struct {
126126
//
127127
// The arena is initialised with self.alloc allocator.
128128
// all others Session deps use directly self.alloc and not the arena.
129+
// The arena is also used in the BrowserContext
129130
arena: std.heap.ArenaAllocator,
130131

131132
window: Window,

src/cdp/cdp.zig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ pub fn BrowserContext(comptime CDP_T: type) type {
284284
// RELATION TO SESSION_ID
285285
session: *CDP_T.Session,
286286

287+
// Points to the session arena
288+
arena: Allocator,
289+
287290
// Maps to our Page. (There are other types of targets, but we only
288291
// deal with "pages" for now). Since we only allow 1 open page at a
289292
// time, we only have 1 target_id.
@@ -316,6 +319,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
316319
var registry = Node.Registry.init(allocator);
317320
errdefer registry.deinit();
318321

322+
const session = try cdp.browser.newSession(self);
319323
self.* = .{
320324
.id = id,
321325
.cdp = cdp,
@@ -324,7 +328,8 @@ pub fn BrowserContext(comptime CDP_T: type) type {
324328
.security_origin = URL_BASE,
325329
.secure_context_type = "Secure", // TODO = enum
326330
.loader_id = LOADER_ID,
327-
.session = try cdp.browser.newSession(self),
331+
.session = session,
332+
.arena = session.arena.allocator(),
328333
.page_life_cycle_events = false, // TODO; Target based value
329334
.node_registry = registry,
330335
.node_search_list = undefined,
@@ -365,7 +370,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
365370
executor.context.exit(); // The default context should remain open
366371

367372
self.isolated_world = .{
368-
.name = try self.session.arena.allocator().dupe(u8, world_name), // TODO allocator
373+
.name = try self.arena.dupe(u8, world_name),
369374
.grant_universal_access = grant_universal_access,
370375
.executor = executor,
371376
};
@@ -468,6 +473,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
468473
};
469474
}
470475

476+
/// see: https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/bindings/core/v8/V8BindingDesign.md#world
471477
/// The current understanding. An isolated world lives in the same isolate, but a separated context.
472478
/// Clients create this to be able to create variables and run code without interfering with the
473479
/// normal namespace and values of the webpage. Similar to the main context we need to pretend to recreate it after

src/cdp/domains/page.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ fn createIsolatedWorld(cmd: anytype) !void {
117117

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

123123
return cmd.sendResult(.{ .executionContextId = world.executor.context.debugContextId() }, .{});
124124
}
@@ -213,16 +213,14 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void
213213
}, .{ .session_id = session_id });
214214
}
215215

216-
// Send Runtime.executionContextsCleared event
217-
// TODO: noop event, we have no env context at this point, is it necesarry?
218216
// When we actually recreated the context we should have the inspector send this event, see: resetContextGroup
219217
// Sending this event will tell the client that the context ids they had are invalid and the context shouls be dropped
220218
// The client will expect us to send new contextCreated events, such that the client has new id's for the active contexts.
221219
try cdp.sendEvent("Runtime.executionContextsCleared", null, .{ .session_id = session_id });
222220

223221
if (bc.isolated_world) |*isolated_world| {
224-
// TODO change the allocator
225-
const aux_json = try std.fmt.allocPrint(bc.session.arena.allocator(), "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{bc.target_id.?});
222+
var buffer: [256]u8 = undefined;
223+
const aux_json = try std.fmt.bufPrint(&buffer, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{bc.target_id.?});
226224

227225
// Calling contextCreated will assign a new Id to the context and send the contextCreated event
228226
bc.session.inspector.contextCreated(

0 commit comments

Comments
 (0)