Skip to content

Commit 83ef21e

Browse files
committed
page handlescope clarification
1 parent 7dde0be commit 83ef21e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/runtime/js.zig

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
345345
const isolate = env.isolate;
346346
const Global = @TypeOf(global.*);
347347

348-
var context: v8.Context = undefined;
349-
{
348+
var context: v8.Context = blk: {
350349
var handle_scope: v8.HandleScope = undefined;
351350
v8.HandleScope.init(&handle_scope, isolate);
352351
defer handle_scope.deinit();
@@ -379,7 +378,7 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
379378
}
380379

381380
const context_local = v8.Context.init(isolate, global_template, null);
382-
context = v8.Persistent(v8.Context).init(isolate, context_local).castToContext();
381+
const context = v8.Persistent(v8.Context).init(isolate, context_local).castToContext();
383382
context.enter();
384383
errdefer if (enter) context.exit();
385384
defer if (!enter) context.exit();
@@ -404,8 +403,12 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
404403
_ = self_obj.setPrototype(context, proto_obj);
405404
}
406405
}
407-
}
406+
break :blk context;
407+
};
408408

409+
// For a Page we only create one HandleScope, it is stored in the main World (enter==true). A page can have multple contexts, 1 for each World.
410+
// The main Context/Scope that enters and holds the HandleScope should therefore always be created first. Following other worlds for this page
411+
// like isolated Worlds, will thereby place their objects on the main page's HandleScope. Note: In the furure the number of context will multiply multiple frames support
409412
var handle_scope: ?v8.HandleScope = null;
410413
if (enter) {
411414
handle_scope = @as(v8.HandleScope, undefined);

0 commit comments

Comments
 (0)