@@ -35,12 +35,11 @@ templates: []v8.FunctionTemplate,
3535// references the Env.meta_lookup
3636meta_lookup : []types.Meta ,
3737
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 ,
4140
42- // An arena for the lifetime of the context
43- context_arena : Allocator ,
41+ // The page.call_arena
42+ call_arena : Allocator ,
4443
4544// Because calls can be nested (i.e.a function calling a callback),
4645// we can only reset the call_arena when call_depth == 0. If we were
@@ -179,7 +178,7 @@ pub fn deinit(self: *Context) void {
179178}
180179
181180fn trackCallback (self : * Context , pf : PersistentFunction ) ! void {
182- return self .callbacks .append (self .context_arena , pf );
181+ return self .callbacks .append (self .arena , pf );
183182}
184183
185184// 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:
236235
237236 const m = try compileModule (self .isolate , src , url );
238237
239- const arena = self .context_arena ;
238+ const arena = self .arena ;
240239 const owned_url = try arena .dupe (u8 , url );
241240
242241 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:
258257 owned_url ,
259258 .{ .alloc = .if_needed , .null_terminated = true },
260259 );
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 );
262261 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 );
264263 gop .key_ptr .* = owned_specifier ;
265264 gop .value_ptr .* = .{};
266265 try self .script_manager .? .getModule (owned_specifier );
@@ -522,26 +521,26 @@ pub fn zigValueToJs(self: *Context, value: anytype) !v8.Value {
522521// we can just grab it from the identity_map)
523522pub fn mapZigInstanceToJs (self : * Context , js_obj_or_template : anytype , value : anytype ) ! PersistentObject {
524523 const v8_context = self .v8_context ;
525- const context_arena = self .context_arena ;
524+ const arena = self .arena ;
526525
527526 const T = @TypeOf (value );
528527 switch (@typeInfo (T )) {
529528 .@"struct" = > {
530529 // Struct, has to be placed on the heap
531- const heap = try context_arena .create (T );
530+ const heap = try arena .create (T );
532531 heap .* = value ;
533532 return self .mapZigInstanceToJs (js_obj_or_template , heap );
534533 },
535534 .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 ));
537536 if (gop .found_existing ) {
538537 // we've seen this instance before, return the same
539538 // PersistentObject.
540539 return gop .value_ptr .* ;
541540 }
542541
543542 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 ));
545544 }
546545
547546 // 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
563562 // The TAO contains the pointer ot our Zig instance as
564563 // well as any meta data we'll need to use it later.
565564 // See the TaggedAnyOpaque struct for more details.
566- const tao = try context_arena .create (TaggedAnyOpaque );
565+ const tao = try arena .create (TaggedAnyOpaque );
567566 const meta_index = @field (types .LOOKUP , @typeName (ptr .child ));
568567 const meta = self .meta_lookup [meta_index ];
569568
@@ -768,7 +767,7 @@ fn jsValueToStruct(self: *Context, comptime named_function: NamedFunction, compt
768767 }
769768
770769 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 }) };
772771 }
773772
774773 const js_obj = js_value .castTo (v8 .Object );
@@ -1062,7 +1061,7 @@ pub fn createPromiseResolver(self: *Context, comptime lifetime: PromiseResolverL
10621061 const persisted = v8 .Persistent (v8 .PromiseResolver ).init (self .isolate , resolver );
10631062
10641063 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 );
10661065 }
10671066
10681067 return .{
@@ -1122,7 +1121,7 @@ pub fn dynamicModuleCallback(
11221121 };
11231122
11241123 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
11261125 specifier ,
11271126 resource ,
11281127 .{ .alloc = .if_needed , .null_terminated = true },
@@ -1172,7 +1171,7 @@ fn _resolveModuleCallback(self: *Context, referrer: v8.Module, specifier: []cons
11721171 .{ .alloc = .if_needed , .null_terminated = true },
11731172 );
11741173
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 );
11761175 if (gop .found_existing ) {
11771176 if (gop .value_ptr .module ) | m | {
11781177 return m .handle ;
@@ -1229,7 +1228,7 @@ const DynamicModuleResolveState = struct {
12291228
12301229fn _dynamicModuleCallback (self : * Context , specifier : [:0 ]const u8 ) ! v8.Promise {
12311230 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 );
12331232 if (gop .found_existing and gop .value_ptr .resolver_promise != null ) {
12341233 // This is easy, there's already something responsible
12351234 // for loading the module. Maybe it's still loading, maybe
@@ -1238,10 +1237,10 @@ fn _dynamicModuleCallback(self: *Context, specifier: [:0]const u8) !v8.Promise {
12381237 }
12391238
12401239 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 );
12421241 var resolver = persistent_resolver .castToPromiseResolver ();
12431242
1244- const state = try self .context_arena .create (DynamicModuleResolveState );
1243+ const state = try self .arena .create (DynamicModuleResolveState );
12451244 state .* = .{
12461245 .module = null ,
12471246 .context = self ,
0 commit comments