Pass Module to callback functions#10777
Conversation
This ensures that users can still invoke runtime elements within the preRun function that are exported on Module (for e.g. "ENV" or "FS").
|
Thank you for submitting a pull request! If this is your first PR, make sure to add yourself to AUTHORS. |
kripken
left a comment
There was a problem hiding this comment.
Good idea, thanks @kleisauke !
I wonder if this might be best to just do in all modes and not just modularize. By doing it all the time people can easily flip between the modes without problems (otherwise, modularize => non modularize could break). This does increase code size a tiny bit, but it's very very little, and seems worth it to me. What do you think?
|
Yes, that makes sense. Done with 0bd7cc9, also added some tests for this in 9ea25da. I guess that I don't have to make the same change in emscripten/src/preamble_minimal.js Line 228 in c755d1f Since it seems that with |
|
Yes, in the minimal runtime these callbacks aren't supported yet, so nothing to do there. |
kripken
left a comment
There was a problem hiding this comment.
Perfect, thanks @kleisauke !
I think it would also be good to document this on the site. Perhaps on https://emscripten.org/docs/api_reference/module.html or https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html? (both are under site/ in this repo)
But let's land this first, that can be a followup. Would be great if you can open a PR for that!
|
(Oh, also we should update the Changelog later.) |
This ensures that users can still invoke runtime elements within the
preRunfunction that are exported onModule(for e.g.ENVorFS)when compiling with
-s MODULARIZE=1.Example usage:
Note: this example requires that the code is compiled with
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['FS', 'ENV']"Resolves #9827.