-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
In MODULARIZE mode avoid modifying the incoming moduleArg. NFC #21775
Conversation
@@ -21,7 +21,7 @@ | |||
// before the code. Then that object will be used in the code, and you | |||
// can continue to use Module afterwards as well. | |||
#if MODULARIZE | |||
var Module = moduleArg; | |||
var Module = Object.assign({}, moduleArg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could take this further and fully separate the arguments and return value at some point too (i.e. not put all the module arg inputs on the module return value)? It would be a bigger breaking change, but IIRC it doesn't seem like many people rely on that behavior when using modularize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean, yes. I think it might be possible yes.
This avoids leaking of the partially constructed module and means that only way to get access the module instance is via waiting on the promise. Previously we were attaching all our module properties to the incoming object, but not, as far as I can tell for any good reason. In case anybody was actually depending on this, inject thunks into the moduleArg that abort on access with an actionable error.
var promise = Module(arg); | ||
arg._foo();''') | ||
|
||
expected = "Aborted(Access to module property ('_foo') is no longer possible via the incoming module contructor argument; Instead, use the result of the module promise" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contructor
=> constructor
var promise = Module(arg); | ||
arg._foo();''') | ||
|
||
expected = "Aborted(Access to module property ('_foo') is no longer possible via the incoming module contructor argument; Instead, use the result of the module promise" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read this comment a few times and I'm not actually sure what the user is expected to do to fix it? This is post-js code so it is inside the emitted JS, how can the module Promise be accessed?
Also, this seems like a breaking change that should be mentioned in the changelog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is --extern-post-js
code.. where we run the Module()
constructor, but we ignore the return value and instead try to use a method on the argument we passed into the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks, I missed the -extern-
.
- Add changelog entry - Fix typo in error message - Improve error message
The change that was made back in emscripten-core#21775 means that its no longer OK to ignore the return value of the `MODULARIZE` constructor function. Fixes: emscripten-core#21908
The change that was made back in emscripten-core#21775 means that its no longer OK to ignore the return value of the `MODULARIZE` constructor function. Fixes: emscripten-core#21908
The change that was made back in emscripten-core#21775 means that its no longer OK to ignore the return value of the `MODULARIZE` constructor function. Fixes: emscripten-core#21908
emscripten-core#21775)" This change effectively reverts 4dac6d6. It turns out that there is at least one use case where accessing the partially constructed module prior to the promise resolution is necessary. Specifically when using `--preload-files` the file packager output expects to be able to use the `Module.FS` functions before the module is loaded.
emscripten-core#21775)" This change effectively reverts 4dac6d6. It turns out that there is at least one use case where accessing the partially constructed module prior to the promise resolution is necessary. Specifically when using `--preload-files` the file packager output expects to be able to use the `Module.FS` functions before the module is loaded. This PR adds a test for this scenario.
#21775)" (#21994) This change effectively reverts 4dac6d6. It turns out that there is at least one use case where accessing the partially constructed module prior to the promise resolution is necessary. Specifically when using `--preload-files` the file packager output expects to be able to use the `Module.FS` functions before the module is loaded. This PR adds a test for this scenario.
emscripten-core#21775)" (emscripten-core#21994) This change effectively reverts 4dac6d6. It turns out that there is at least one use case where accessing the partially constructed module prior to the promise resolution is necessary. Specifically when using `--preload-files` the file packager output expects to be able to use the `Module.FS` functions before the module is loaded. This PR adds a test for this scenario.
callRuntimeCallbacks passes the actual Module, so use it
…FC (emscripten-core#21775)" This change was reverted in emscripten-core#21994 because the file_packager generated code expected to be able to use propertied on the Module object that was passed to the constructor/factor function. However that issue was fixed in emscripten-core#22086 so we can try to land this once again.
This avoids leaking of the partially constructed module and means that only way to get access the module instance is via waiting on the promise.
Previously we were attaching all our module properties to the incoming object, but not, as far as I can tell, for any good reason.
In case anybody was actually depending on this, inject thunks into the moduleArg that abort on access with an actionable error.