@@ -53,8 +53,8 @@ pub const Platform = struct {
5353
5454// The Env maps to a V8 isolate, which represents a isolated sandbox for
5555// executing JavaScript. The Env is where we'll define our V8 <-> Zig bindings,
56- // and it's where we'll start Executors , which actually execute JavaScript.
57- // The `S` parameter is arbitrary state. When we start an Executor , an instance
56+ // and it's where we'll start ExecutionWorlds , which actually execute JavaScript.
57+ // The `S` parameter is arbitrary state. When we start an ExecutionWorld , an instance
5858// of S must be given. This instance is available to any Zig binding.
5959// The `types` parameter is a tuple of Zig structures we want to bind to V8.
6060pub fn Env (comptime State : type , comptime WebApis : type ) type {
@@ -259,7 +259,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
259259 self .isolate .performMicrotasksCheckpoint ();
260260 }
261261
262- pub fn newExecutor (self : * Self ) ! Executor {
262+ pub fn newExecutionWorld (self : * Self ) ! ExecutionWorld {
263263 return .{
264264 .env = self ,
265265 .scope = null ,
@@ -280,32 +280,35 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
280280 self .isolate .lowMemoryNotification ();
281281 }
282282
283- pub const Executor = struct {
283+ // ExecutionWorld closely models a JS World.
284+ // https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/bindings/core/v8/V8BindingDesign.md#World
285+ // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/ExecutionWorld
286+ pub const ExecutionWorld = struct {
284287 env : * Self ,
285288
286289 // Arena whose lifetime is for a single getter/setter/function/etc.
287290 // Largely used to get strings out of V8, like a stack trace from
288291 // a TryCatch. The allocator will be owned by the Scope, but the
289- // arena itself is owned by the Executor so that we can re-use it
292+ // arena itself is owned by the ExecutionWorld so that we can re-use it
290293 // from scope to scope.
291294 call_arena : ArenaAllocator ,
292295
293296 // Arena whose lifetime is for a single page load, aka a Scope. Where
294297 // the call_arena lives for a single function call, the scope_arena
295298 // lives for the lifetime of the entire page. The allocator will be
296- // owned by the Scope, but the arena itself is owned by the Executor
299+ // owned by the Scope, but the arena itself is owned by the ExecutionWorld
297300 // so that we can re-use it from scope to scope.
298301 scope_arena : ArenaAllocator ,
299302
300303 // A Scope maps to a Browser's Page. Here though, it's only a
301- // mechanism to organization page-specific memory. The Executor
304+ // mechanism to organization page-specific memory. The ExecutionWorld
302305 // does all the work, but having all page-specific data structures
303306 // grouped together helps keep things clean.
304307 scope : ? Scope = null ,
305308
306- // no init, must be initialized via env.newExecutor ()
309+ // no init, must be initialized via env.newExecutionWorld ()
307310
308- pub fn deinit (self : * Executor ) void {
311+ pub fn deinit (self : * ExecutionWorld ) void {
309312 if (self .scope != null ) {
310313 self .endScope ();
311314 }
@@ -320,7 +323,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
320323 // when the handle_scope is freed.
321324 // We also maintain our own "scope_arena" which allows us to have
322325 // all page related memory easily managed.
323- pub fn startScope (self : * Executor , global : anytype , state : State , module_loader : anytype , enter : bool ) ! * Scope {
326+ pub fn startScope (self : * ExecutionWorld , global : anytype , state : State , module_loader : anytype , enter : bool ) ! * Scope {
324327 std .debug .assert (self .scope == null );
325328
326329 const ModuleLoader = switch (@typeInfo (@TypeOf (module_loader ))) {
@@ -338,9 +341,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
338341 const Global = @TypeOf (global .* );
339342
340343 var context : v8.Context = blk : {
341- var handle_scope : v8.HandleScope = undefined ;
342- v8 .HandleScope .init (& handle_scope , isolate );
343- defer handle_scope .deinit ();
344+ var temp_scope : v8.HandleScope = undefined ;
345+ v8 .HandleScope .init (& temp_scope , isolate );
346+ defer temp_scope .deinit ();
344347
345348 const js_global = v8 .FunctionTemplate .initDefault (isolate );
346349 attachClass (Global , isolate , js_global );
@@ -466,7 +469,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
466469 return scope ;
467470 }
468471
469- pub fn endScope (self : * Executor ) void {
472+ pub fn endScope (self : * ExecutionWorld ) void {
470473 self .scope .? .deinit ();
471474 self .scope = null ;
472475 _ = self .scope_arena .reset (.{ .retain_with_limit = SCOPE_ARENA_RETAIN });
@@ -1517,7 +1520,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
15171520 }
15181521
15191522 // Retrieves the RemoteObject for a given value.
1520- // The value is loaded through the Executor 's mapZigInstanceToJs function,
1523+ // The value is loaded through the ExecutionWorld 's mapZigInstanceToJs function,
15211524 // just like a method return value. Therefore, if we've mapped this
15221525 // value before, we'll get the existing JS PersistedObject and if not
15231526 // we'll create it and track it for cleanup when the scope ends.
@@ -2198,7 +2201,7 @@ fn isEmpty(comptime T: type) bool {
21982201}
21992202
22002203// Responsible for calling Zig functions from JS invokations. This could
2201- // probably just contained in Executor , but having this specific logic, which
2204+ // probably just contained in ExecutionWorld , but having this specific logic, which
22022205// is somewhat repetitive between constructors, functions, getters, etc contained
22032206// here does feel like it makes it clenaer.
22042207fn Caller (comptime E : type , comptime State : type ) type {
0 commit comments