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

None yet

3 participants