Skip to content

ExecuteModule export loop uses unbound names and skips only v128 #123

Closed

Description

@chicoxyzzy

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) …
  • externval is only set in the import loop, and only on the wasm-to-wasm path. The last import wins, or the name is unbound.
  • store is only set on some JS-global import branches.
  • resolution.[[BindingName]] is the last import resolution, not the export name.
  • |module| is rebound to the imported core module in the wasm-import branch, then reused for instantiate the core and module_exports. Sequential Let means 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)

  1. Keep the executing core module in a name the import loop does not overwrite.
  2. After instantiate-the-core: initialize an instance object and store that JS Instance on the module record.
  3. Export loop: externval = instance_export(coreInstance, name); store = agent store; skip if globaltype matches v128 or exnref; live binding uses name.
  4. 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

  1. guybedford commented on Sep 20, 2026

    @guybedford
    Collaborator

    @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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions