-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Assert if MODULARIZE
factory function is used with new
.
#23210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
112b953
to
7aca82a
Compare
new
.MODULARIZE
factory function is used with new
.
f04ba5a
to
4f32743
Compare
kripken
reviewed
Dec 18, 2024
ae674ad
to
ced299a
Compare
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.
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.
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
async
for for this function thennew
stopsworking: #23157.
Using
new
in this was always an antipattern but there was nothingstopping users from doing this.