ReviewOS

zig-utils/zig-js

Realm: resolve global bindings from stable environment ownership

#793
Closed chris opened this 9 days ago ·
9 days ago

Parent: #790. Related: #786, #791.

The environment-declaration integration run exposed a real identity bug: currentGlobalObject resolves the writable globalThis binding instead of the canonical global object. The existing low-level test vm: sloppy recursive calls retain their function realm global fails when exact variable Reference plans replace forced global definitions.

Simply preferring Interpreter.global_object is insufficient: an ambient native call can still belong to the caller while a foreign generator executes in its own closure environment. The existing dynamic generator functions validate params and prototype realms test caught this with ReferenceError on the foreign calls binding.

Implement stable per-realm ownership on the root environment, initialized before publication and traced/relocated as an owned managed edge. Resolve function and global binding realm identity through that environment, including dynamic constructors, indirect eval, evalScript and ShadowRealm entry. Neither writable nor lexically shadowed globalThis can select a realm. Do not modify Promise/job lifecycle or use ambient-global special cases for individual tests.

Acceptance: reassigned and shadowed globalThis, foreign dynamic generator/async-generator construction, child realm evalScript, precise edge relocation, no-GIL/TSan and full integration. The initial ambient-only candidate is not landable.

Completed integration

CI run 33113309062 completed successfully on main commit 8a1398ffc04e9e30987f968693667c7271ca3ce1, a descendant containing this implementation. All 53 executed jobs succeeded (unit and TSan-unit shards, Linux no-GIL TSan, functional/no-GIL corpus gates, fuzz profiles, ABI, Wasm, Test262 parallel, and docs); the scheduled-only nightly job was skipped. Together with the measured local evidence in the comments, this completes this issue's acceptance.

9 days ago

The stable environment-owned identity candidate passes the existing foreign dynamic generator/async-generator test and the existing sloppy recursive realm-global test. Added forced-tree-walker/required-bytecode cases for reassigned globalThis, lexical shadowing, and child-realm evalScript plus dynamic construction; these pass ReleaseSafe+TSan. The exact Environment relocation test now rewrites and checks the canonical-global edge. Final combined local sharded integration with #790/#791: 2006 passed, 1 platform skip, 0 failed, 0 leaked. Conformance and fuzz evidence are running before issue-linked landing; pushed required integration is not yet measured.

9 days ago

Landed 11c00cab on main. Canonical root-environment identity, tracing/relocation, indirect-eval/child-realm entry and forced-tier mutable/shadowed globalThis checks are included. Final combined local integration: 2006 pass, 1 platform skip, 0 failure/leak; TSan realm check passes. Fifteen default-tier reports remain byte-identical (3215 passes, one existing failure). Required pushed CI is pending; details are in #790 and the commit body.

Sign in to comment on this issue.