Repository navigation
Description
ExecuteModule’s export-binding loop (added in #104) does not type-check as written, and the v128 TDZ skip is incomplete.
Unbound / leftover names
After instantiate, the algorithm does:
For each (name, externtype) of module_exports(module),
If externtype is of the form global mut globaltype,
Assert: externval is of the form global globaladdr.
Let global_value be global_read(store, globaladdr).
If globaltype is not v128,
InitializeBinding(name, ToJSValue(global_value))
… GetBindingValue(resolution.[[BindingName]], true) …
externvalis only set in the import loop, and only on the wasm-to-wasm path. The last import wins, or the name is unbound.storeis only set on some JS-global import branches.resolution.[[BindingName]]is the last import resolution, not the exportname.|module|is rebound to the imported core module in the wasm-import branch, then reused forinstantiate the coreandmodule_exports. SequentialLetmeans a module that imports another Wasm module instantiates the wrong module.
create an exports object already does this correctly: externval = instance_export(instance, name) on a core instance.
Core instance vs JS Instance
instantiate the core of a WebAssembly module returns a core instance. The same algorithm then does Get(instance.[[Exports]], name) and namespaceInstance is specified to return a JS Instance. Those are different objects.
The wasm-to-wasm import path has the inverse mix-up: it asserts [[Instance]] is a JS Instance, then passes it to instance_export (a core embedding op). That should be instance_export(jsInstance.[[Instance]], name).
exnref should stay TDZ like v128
ToJSValue asserts the value is not v128 and not ref.exn. GetGlobalValue already throws for both. The export skip only names v128. Initializing an exnref binding would be an illegal ToJSValue.
No other current ToJSValue holes (i31 / struct / array / func / extern are defined). Shared globals are the future case already mentioned in the note.
WPT coverage for the exnref TDZ: web-platform-tests/wpt#62353
Engines
WebKit implements the intended object graph (prepareLink stores a JS Instance, then evaluate fills the namespace) and leaves both v128 and exnref in TDZ.
V8’s JS API already treats those types as non-values (WebAssembly.Global.value is a TypeError for v128; JSToWasmObject rejects exn). Blink evaluation-phase ESM looks source-phase-only (WasmModuleScript / “Wasm module imports are only supported in the source phase”). A Chrome ExecuteModule that unwraps namespace globals has not been verified.
Firefox can fetch Wasm as a module (bug 1994828) but follows the spec’s incomplete-implementation note: ResolveExport returns null, InitializeEnvironment / ExecuteModule throw SyntaxError. No evaluation-phase namespace bindings yet.
Proposed fix (one algorithm)
- Keep the executing core module in a name the import loop does not overwrite.
- After instantiate-the-core:
initialize an instance objectand store that JSInstanceon the module record. - Export loop:
externval = instance_export(coreInstance, name);store= agent store; skip ifglobaltypematchesv128orexnref; live binding usesname. - Wasm-to-wasm import:
instance_export(jsInstance.[[Instance]], name).
Happy to send a bikeshed PR on document/js-api/index.bs if this scope looks right.
Activity
guybedford commentedon Sep 20, 2026
@chicoxyzzy thanks for your patience here, this one nearly dropped out of my inbox! I was finally able to verify both claims and I agree with your assessment.
Thanks for working on the WPT addition as well, yes that is the correct integration for exception refs.
I would gladly review a PR, or if you want to split it up, separate PRs for these fixes. I can make sure not to leave it three weeks next time as well!
[js-api] Fix ExecuteModule export bindings