@@ -35,12 +35,11 @@ templates: []v8.FunctionTemplate,
35
35
// references the Env.meta_lookup
36
36
meta_lookup : []types.Meta ,
37
37
38
- // An arena for the lifetime of a call-group. Gets reset whenever
39
- // call_depth reaches 0.
40
- call_arena : Allocator ,
38
+ // Arena for the lifetime of the context
39
+ arena : Allocator ,
41
40
42
- // An arena for the lifetime of the context
43
- context_arena : Allocator ,
41
+ // The page.call_arena
42
+ call_arena : Allocator ,
44
43
45
44
// Because calls can be nested (i.e.a function calling a callback),
46
45
// we can only reset the call_arena when call_depth == 0. If we were
@@ -179,7 +178,7 @@ pub fn deinit(self: *Context) void {
179
178
}
180
179
181
180
fn trackCallback (self : * Context , pf : PersistentFunction ) ! void {
182
- return self .callbacks .append (self .context_arena , pf );
181
+ return self .callbacks .append (self .arena , pf );
183
182
}
184
183
185
184
// Given an anytype, turns it into a v8.Object. The anytype could be:
@@ -236,7 +235,7 @@ pub fn module(self: *Context, comptime want_result: bool, src: []const u8, url:
236
235
237
236
const m = try compileModule (self .isolate , src , url );
238
237
239
- const arena = self .context_arena ;
238
+ const arena = self .arena ;
240
239
const owned_url = try arena .dupe (u8 , url );
241
240
242
241
try self .module_identifier .putNoClobber (arena , m .getIdentityHash (), owned_url );
@@ -258,9 +257,9 @@ pub fn module(self: *Context, comptime want_result: bool, src: []const u8, url:
258
257
owned_url ,
259
258
.{ .alloc = .if_needed , .null_terminated = true },
260
259
);
261
- const gop = try self .module_cache .getOrPut (self .context_arena , normalized_specifier );
260
+ const gop = try self .module_cache .getOrPut (self .arena , normalized_specifier );
262
261
if (! gop .found_existing ) {
263
- const owned_specifier = try self .context_arena .dupeZ (u8 , normalized_specifier );
262
+ const owned_specifier = try self .arena .dupeZ (u8 , normalized_specifier );
264
263
gop .key_ptr .* = owned_specifier ;
265
264
gop .value_ptr .* = .{};
266
265
try self .script_manager .? .getModule (owned_specifier );
@@ -522,26 +521,26 @@ pub fn zigValueToJs(self: *Context, value: anytype) !v8.Value {
522
521
// we can just grab it from the identity_map)
523
522
pub fn mapZigInstanceToJs (self : * Context , js_obj_or_template : anytype , value : anytype ) ! PersistentObject {
524
523
const v8_context = self .v8_context ;
525
- const context_arena = self .context_arena ;
524
+ const arena = self .arena ;
526
525
527
526
const T = @TypeOf (value );
528
527
switch (@typeInfo (T )) {
529
528
.@"struct" = > {
530
529
// Struct, has to be placed on the heap
531
- const heap = try context_arena .create (T );
530
+ const heap = try arena .create (T );
532
531
heap .* = value ;
533
532
return self .mapZigInstanceToJs (js_obj_or_template , heap );
534
533
},
535
534
.pointer = > | ptr | {
536
- const gop = try self .identity_map .getOrPut (context_arena , @intFromPtr (value ));
535
+ const gop = try self .identity_map .getOrPut (arena , @intFromPtr (value ));
537
536
if (gop .found_existing ) {
538
537
// we've seen this instance before, return the same
539
538
// PersistentObject.
540
539
return gop .value_ptr .* ;
541
540
}
542
541
543
542
if (comptime @hasDecl (ptr .child , "destructor" )) {
544
- try self .destructor_callbacks .append (context_arena , DestructorCallback .init (value ));
543
+ try self .destructor_callbacks .append (arena , DestructorCallback .init (value ));
545
544
}
546
545
547
546
// Sometimes we're creating a new v8.Object, like when
@@ -563,7 +562,7 @@ pub fn mapZigInstanceToJs(self: *Context, js_obj_or_template: anytype, value: an
563
562
// The TAO contains the pointer ot our Zig instance as
564
563
// well as any meta data we'll need to use it later.
565
564
// See the TaggedAnyOpaque struct for more details.
566
- const tao = try context_arena .create (TaggedAnyOpaque );
565
+ const tao = try arena .create (TaggedAnyOpaque );
567
566
const meta_index = @field (types .LOOKUP , @typeName (ptr .child ));
568
567
const meta = self .meta_lookup [meta_index ];
569
568
@@ -768,7 +767,7 @@ fn jsValueToStruct(self: *Context, comptime named_function: NamedFunction, compt
768
767
}
769
768
770
769
if (T == js .String ) {
771
- return .{ .string = try self .valueToString (js_value , .{ .allocator = self .context_arena }) };
770
+ return .{ .string = try self .valueToString (js_value , .{ .allocator = self .arena }) };
772
771
}
773
772
774
773
const js_obj = js_value .castTo (v8 .Object );
@@ -1062,7 +1061,7 @@ pub fn createPromiseResolver(self: *Context, comptime lifetime: PromiseResolverL
1062
1061
const persisted = v8 .Persistent (v8 .PromiseResolver ).init (self .isolate , resolver );
1063
1062
1064
1063
if (comptime lifetime == .page ) {
1065
- try self .persisted_promise_resolvers .append (self .context_arena , persisted );
1064
+ try self .persisted_promise_resolvers .append (self .arena , persisted );
1066
1065
}
1067
1066
1068
1067
return .{
@@ -1122,7 +1121,7 @@ pub fn dynamicModuleCallback(
1122
1121
};
1123
1122
1124
1123
const normalized_specifier = @import ("../../url.zig" ).stitch (
1125
- self .context_arena , // might need to survive until the module is loaded
1124
+ self .arena , // might need to survive until the module is loaded
1126
1125
specifier ,
1127
1126
resource ,
1128
1127
.{ .alloc = .if_needed , .null_terminated = true },
@@ -1172,7 +1171,7 @@ fn _resolveModuleCallback(self: *Context, referrer: v8.Module, specifier: []cons
1172
1171
.{ .alloc = .if_needed , .null_terminated = true },
1173
1172
);
1174
1173
1175
- const gop = try self .module_cache .getOrPut (self .context_arena , normalized_specifier );
1174
+ const gop = try self .module_cache .getOrPut (self .arena , normalized_specifier );
1176
1175
if (gop .found_existing ) {
1177
1176
if (gop .value_ptr .module ) | m | {
1178
1177
return m .handle ;
@@ -1229,7 +1228,7 @@ const DynamicModuleResolveState = struct {
1229
1228
1230
1229
fn _dynamicModuleCallback (self : * Context , specifier : [:0 ]const u8 ) ! v8.Promise {
1231
1230
const isolate = self .isolate ;
1232
- const gop = try self .module_cache .getOrPut (self .context_arena , specifier );
1231
+ const gop = try self .module_cache .getOrPut (self .arena , specifier );
1233
1232
if (gop .found_existing and gop .value_ptr .resolver_promise != null ) {
1234
1233
// This is easy, there's already something responsible
1235
1234
// for loading the module. Maybe it's still loading, maybe
@@ -1238,10 +1237,10 @@ fn _dynamicModuleCallback(self: *Context, specifier: [:0]const u8) !v8.Promise {
1238
1237
}
1239
1238
1240
1239
const persistent_resolver = v8 .Persistent (v8 .PromiseResolver ).init (isolate , v8 .PromiseResolver .init (self .v8_context ));
1241
- try self .persisted_promise_resolvers .append (self .context_arena , persistent_resolver );
1240
+ try self .persisted_promise_resolvers .append (self .arena , persistent_resolver );
1242
1241
var resolver = persistent_resolver .castToPromiseResolver ();
1243
1242
1244
- const state = try self .context_arena .create (DynamicModuleResolveState );
1243
+ const state = try self .arena .create (DynamicModuleResolveState );
1245
1244
state .* = .{
1246
1245
.module = null ,
1247
1246
.context = self ,
0 commit comments