From 7d87fb80ec819f746037756a9b6380405987cb67 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 14 Jan 2026 15:12:22 +0800 Subject: [PATCH] Make Global Function explicit. This is the first in a series of changes to make globals explicit. The ultimate goal of having explicit Globals is to move away from the global HandleScope and to explicit HandleScopes. Currently, we treat globals and locals interchangeably. In fact, for Global -> Local, we just ptrCast. This works because we have 1 global HandleScope, which effectively disables V8's GC and thus nothing ever gets moved. If we're going to introduce explicit HandleScopes, then we need to first have correct Globals. Specifically, when we want to act on the global, we need to get the local value, and that will eventually mean making sure there's a HandleScope. While adding explicit globals, we're keeping the global HandleScope so that we can minimize the change. So, given that we still have the global HandleScope the change is largely two things: 1 - js.Function.persit() returns a js.Function.Global. Types that persist global functions must be updated to js.Function.Global. 2 - To turn js.Function.Global -> js.Function, we need to call .local() on it. The bridge has been updated to support js.Function.Global for both input and output parameters. Thus, window.setOnLoad can now directly take a js.Function.Global, and window.getOnLoad can directly return that js.Function.Global. --- src/browser/js/Context.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/browser/js/Context.zig b/src/browser/js/Context.zig index 2e9f6bed..2d97fdbf 100644 --- a/src/browser/js/Context.zig +++ b/src/browser/js/Context.zig @@ -77,6 +77,7 @@ identity_map: std.AutoHashMapUnmanaged(usize, js.Global(js.Object)) = .empty, // the @intFromPtr(js_obj.handle). But v8 can re-use address. Without // a reliable way to know if an object has already been persisted, // we now simply persist every time persist() is called. + global_values: std.ArrayList(v8.Global) = .empty, global_objects: std.ArrayList(v8.Global) = .empty, global_modules: std.ArrayList(v8.Global) = .empty,