Self-initializing ES modules#27151
Conversation
|
The reason we have the If the user doesn't want that configuration then yes we could just async initialize the module. However, I wonder if we could just ifer that intent via Note that I'm not necessarily opposed to some kind explicit option but as always I'll try to resist adding new settings :) |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I'm not sure we need to worry too much about that use case. We have the ability to generate normal non-ESM modules. If somebody want to opt into ESM output, I think its fair to assume they will be consume it as an ESM module. Also, the majority of our users are targeting the web where |
780f1c0 to
2b8df73
Compare
|
Agreed, ok, I've refactored this PR to be based on |
Great. @brendandahl WDYT? Is this too magical to automatically opt-out of the |
…configure In MODULARIZE=instance (and WASM_ESM_INTEGRATION) the `init` function exists so the caller can configure the instance via `moduleArg` before it starts. When there are no configuration points (INCOMING_MODULE_JS_API is empty, as implied by STRICT) there is nothing to configure, so the module now self-initializes via top-level await and `init` is no longer exported; the named Wasm/runtime exports are ready to use as soon as the module is imported. For WASM_ESM_INTEGRATION pthread workers self-initialize from within the module (via the load message) rather than the wrapper exporting init.
99410af to
702984c
Compare
Use the @esm_integration decorator instead of hand-rolling the setup so the test inherits the wasm64 skip (ESM integration has no export wrappers, so pointer-returning exports stay BigInt and writeStackCookie fails).
Under MODULARIZE=instance and WASM_ESM_INTEGRATION, when
INCOMING_MODULE_JS_APIis empty, or when-sSTRICTis passed, the ES module initializes itself via top-level await rather than exporting aninitfunction. The named Wasm/runtime exports are ready to use as soon as the module is imported. Also works with pthreads.Initial version used a
-pTLA, but was adapted to not require a custom option since there is already existing use of top-level await.This PR was made with AI assistance