Skip to content

[js-api] Allow a missing importObject for builtin imports - #2264

Open
chicoxyzzy wants to merge 2 commits into
WebAssembly:mainfrom
chicoxyzzy:js-api-optional-import-object
Open

chicoxyzzy wants to merge 2 commits into
WebAssembly:mainfrom
chicoxyzzy:js-api-optional-import-object

Conversation

@chicoxyzzy

Copy link
Copy Markdown
Member

Fixes #2102.

read the imports threw a TypeError whenever module_imports was non-empty and importObject was missing. That includes a module whose imports are all wasm:js-string builtins, or all imported string constants. Those imports are supplied by the host. Chrome instantiates them with no import object.

The check now runs only when importObject is missing, and it throws only if some import is not supplied by an enabled builtin or by the imported string constants module. It runs before builtin instances are allocated.

A user import, an unknown name under wasm:js-string, and a builtin mixed with a user import still throw TypeError. Omitting importObject and passing undefined are the same.

Fixes WebAssembly#2102.

read the imports threw TypeError whenever module_imports was non-empty
and importObject was missing. A module whose imports are all satisfied
by an enabled builtin, or by the imported string constants module, does
not read importObject.

Throw only if importObject is missing and some import is not supplied
by those sources. Do that before allocating builtin instances.
Comment thread document/js-api/index.bs
Comment on lines 509 to 514
1. If |builtinOrStringImports|[|moduleName|] [=map/exists=],
1. Let |o| be |builtinOrStringImports|[|moduleName|].
1. If |o| [=is not an Object=] or if [=?=] [$HasProperty$](|o|, |componentName|) is false,
1. Set |o| to [=?=] [$Get$](|importObject|, |moduleName|).
1. Else,
1. Let |o| be [=?=] [$Get$](|importObject|, |moduleName|).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick read does not convince me that we'll never call Get with a missing argument. This needs at least a note to explain the invariant that prevents that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If importObject is missing, the opening check throws unless every import is an enabled builtin or an imported string constant. Those are own properties of builtinOrStringImports, so these Gets are not reached. Noted that after the algorithm, and asserted it before each call.

Get requires an Object. importObject can be missing when every import
is an enabled builtin or an imported string constant, but those names
are own properties of builtinOrStringImports, so the fallback Gets are
not reached. Assert that before each fallback Get, and note it with the
other notes on this algorithm.
@chicoxyzzy
chicoxyzzy force-pushed the js-api-optional-import-object branch from 7e669ba to 598c350 Compare October 5, 2026 21:31

This branch has not been deployed

No deployments
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.

[js-api] Ambiguity in WebAssembly.instance() importObject requirement with JS builtins imports

2 participants