Skip to content
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

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Apr 17, 2024

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.

src/postamble_modularize.js Outdated Show resolved Hide resolved
@@ -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);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.
@sbc100 sbc100 enabled auto-merge (squash) April 17, 2024 18:09
@sbc100 sbc100 merged commit 4dac6d6 into emscripten-core:main Apr 17, 2024
29 checks passed
@sbc100 sbc100 deleted the moduleArg branch April 17, 2024 18:28
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"
Copy link
Member

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"
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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

sbc100 added a commit to sbc100/emscripten that referenced this pull request Apr 17, 2024
- Add changelog entry
- Fix typo in error message
- Improve error message
sbc100 added a commit that referenced this pull request Apr 17, 2024
- Add changelog entry
- Fix typo in error message
- Improve error message
sbc100 added a commit to sbc100/emscripten that referenced this pull request May 17, 2024
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
sbc100 added a commit to sbc100/emscripten that referenced this pull request May 17, 2024
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
sbc100 added a commit to sbc100/emscripten that referenced this pull request May 17, 2024
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
sbc100 added a commit to sbc100/emscripten that referenced this pull request May 23, 2024
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.
sbc100 added a commit to sbc100/emscripten that referenced this pull request May 23, 2024
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.
sbc100 added a commit that referenced this pull request May 29, 2024
#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.
msorvig pushed a commit to msorvig/emscripten that referenced this pull request Jun 4, 2024
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.
past-due added a commit to past-due/emscripten that referenced this pull request Jun 11, 2024
callRuntimeCallbacks passes the actual Module, so use it
sbc100 pushed a commit that referenced this pull request Jun 11, 2024
This makes it robust against #21775 in case we try to re-land it.

callRuntimeCallbacks passes the actual Module, so use it.
sbc100 added a commit to sbc100/emscripten that referenced this pull request Nov 1, 2024
…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.
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.

3 participants