Skip to content

[js-api] Validate import resolution in InitializeEnvironment - #130

Merged
guybedford merged 1 commit into
mainfrom
esm-validate-import-resolution
Dec 2, 2026
Merged

guybedford merged 1 commit into
mainfrom
esm-validate-import-resolution

Conversation

@guybedford

Copy link
Copy Markdown
Collaborator

This implements validation of WebAssembly module imports when linking, throwing a SyntaxError for an import that does not resolve.

ExecuteModule asserts that the ResolveExport result for each import is a ResolvedBinding Record "as validated during environment initialization", but InitializeEnvironment never performed that validation. A WebAssembly module importing a name that its dependency does not export, or one that is ambiguous between two export * declarations, reached that assertion with null or ~ambiguous~ instead of throwing.

InitializeEnvironment now resolves each external import and throws a SyntaxError when the result is null or ~ambiguous~, the same way Source Text Module Records do for their import entries:

  • this is a link error, so no module in the graph is evaluated
  • builtin and string constant imports are skipped, since they are not requested modules
(module (import "./dep.js" "missing" (func)))
await import("./importer.wasm"); // SyntaxError, without evaluating dep.js

Tests are added to resolve-export.tentative.any.js for an export missing from a JavaScript module, an export missing from a WebAssembly module, and an ambiguous star export. Each also checks that the dependency was not evaluated. The new fixtures are:

;; resolve-import-target.wasm
(module (func (export "f")))
;; resolve-import-missing-js.wasm
(module (import "./resolve-import-target.js" "g" (func)))
;; resolve-import-missing-wasm.wasm
(module (import "./resolve-import-target.wasm" "g" (func)))
;; resolve-import-ambiguous.wasm
(module (import "./resolve-import-ambiguous.js" "f" (func)))

ExecuteModule asserts that each import resolves to a ResolvedBinding
Record as validated during environment initialization, but no such
validation was performed. Resolve each external import when
initializing the environment and throw a SyntaxError when the result
is null or ambiguous, matching Source Text Module Records.
eqrion pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 23, 2026
Upstreams the tests from WebAssembly/esm-integration#130, covering a
WebAssembly module import of a missing or ambiguous export failing to
link with a SyntaxError, without evaluating its dependencies.
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Nov 27, 2026
…tion validation tests, a=testonly

Automatic update from web-platform-tests
[wasm] Add ESM Integration import resolution validation tests

Upstreams the tests from WebAssembly/esm-integration#130, covering a
WebAssembly module import of a missing or ambiguous export failing to
link with a SyntaxError, without evaluating its dependencies.

--

wpt-commits: 90c06a918d0a4a718bf62cbef7d03a23a8f44b3d
wpt-pr: 65184
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Nov 30, 2026
…tion validation tests, a=testonly

Automatic update from web-platform-tests
[wasm] Add ESM Integration import resolution validation tests

Upstreams the tests from WebAssembly/esm-integration#130, covering a
WebAssembly module import of a missing or ambiguous export failing to
link with a SyntaxError, without evaluating its dependencies.

--

wpt-commits: 90c06a918d0a4a718bf62cbef7d03a23a8f44b3d
wpt-pr: 65184

UltraBlame original commit: 0d4e6221e7841cf84e874a6b78d0d89f99a4468d
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Nov 30, 2026
…tion validation tests, a=testonly

Automatic update from web-platform-tests
[wasm] Add ESM Integration import resolution validation tests

Upstreams the tests from WebAssembly/esm-integration#130, covering a
WebAssembly module import of a missing or ambiguous export failing to
link with a SyntaxError, without evaluating its dependencies.

--

wpt-commits: 90c06a918d0a4a718bf62cbef7d03a23a8f44b3d
wpt-pr: 65184

UltraBlame original commit: 0d4e6221e7841cf84e874a6b78d0d89f99a4468d
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Nov 30, 2026
…tion validation tests, a=testonly

Automatic update from web-platform-tests
[wasm] Add ESM Integration import resolution validation tests

Upstreams the tests from WebAssembly/esm-integration#130, covering a
WebAssembly module import of a missing or ambiguous export failing to
link with a SyntaxError, without evaluating its dependencies.

--

wpt-commits: 90c06a918d0a4a718bf62cbef7d03a23a8f44b3d
wpt-pr: 65184

UltraBlame original commit: 0d4e6221e7841cf84e874a6b78d0d89f99a4468d
@guybedford
guybedford merged commit b8ebe75 into main Dec 2, 2026
12 checks passed
@guybedford
guybedford deleted the esm-validate-import-resolution branch December 2, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant