Assert if MODULARIZE factory function is used with new. - #23210
Merged
Conversation
sbc100
force-pushed
the
modularize_misuse
branch
2 times, most recently
from
December 18, 2024 04:17
112b953 to
7aca82a
Compare
new.MODULARIZE factory function is used with new.
sbc100
force-pushed
the
modularize_misuse
branch
2 times, most recently
from
December 18, 2024 17:06
f04ba5a to
4f32743
Compare
kripken
reviewed
Dec 18, 2024
sbc100
force-pushed
the
modularize_misuse
branch
5 times, most recently
from
December 18, 2024 20:37
ae674ad to
ced299a
Compare
Collaborator
Author
|
I re-wrote this change is much more minimal way. PTAL |
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
force-pushed
the
modularize_misuse
branch
from
December 18, 2024 20:44
ced299a to
1a2ee30
Compare
kripken
approved these changes
Dec 18, 2024
sbc100
added a commit
that referenced
this pull request
Dec 19, 2024
The advantage if using `await` in the cases where we can is that it avoids the generation or wrapper function for each export. So instead of: ``` var wasmExport = createWasm(); // returns empty object ... var malloc = (..) => (malloc = wasmExports['malloc'])(..); ``` We can generate: ``` var wasmExport = await createWasm(); // returns actual exports ... var malloc = wasmExports['malloc']; ``` This only currently works in MODULARIZE mode where the code is running inside a factory function. Otherwise it would end up using top-level-await. One wrinkle here is that this is not currently supported when closure is enabled because we run closure only on the contents of the factory function so closure ends up seeing this as a top level await when its not. There are two minor observable effects of this change: 1. In `MODULARIZE` mode its no longer possible to call `new Foo()` with factory function. We already added a debug error for in #23210. 2. Because we now can `await` for createWasm to return, the `run` method can run on first call, which means it runs `main` on first call, which means main will now run before `postjs` code, just like it would with sync instantiation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Once we start using
asyncfor for this function thennewstopsworking: #23157.
Using
newin this was always an antipattern but there was nothingstopping users from doing this.