-
-
Notifications
You must be signed in to change notification settings - Fork 844
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
Add experimental support for EM_JS code in side modules #3676
Conversation
libstr = "data:text/javascript," + libstr; | ||
await loadScript(libstr); | ||
let gt = globalThis as any; | ||
gt.__tmpMergeLibsFunction(Module); | ||
delete gt.__tmpMergeLibsFunction; |
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.
TODO: There should be an async lock around this code.
For EM_ASM this was fixed in emscripten-core/emscripten#18228. Here use |
It would be nice to support pages with a content security policy that does not allow Though I'm not entirely sure that this is possible. I'm not sure whether
|
Upstream, we will probably provide "out-of-the-box" support for using |
I guess another feature that is missing from the approach I'm using here is the closure. You write:
emscripten-core/emscripten#18228 (comment) Which is certainly true. It is possible to say |
Cool, it would be really interesting if we can move some JS parts into packages so we can reduce the size of the main module. |
Based on my discussion with @szabolcsdombi in #3671, I thought it would be fun to experiment with enabling
EM_JS
in side modules. TheEM_JS
is put into a file calledblah.so.js
which contains code like:we load it with
loadScript
, call__tmpMergeLibsFunction
and then delete it. We need a lock around this code to ensure that another library doesn't write over the__tmpMergeLibsFunction
global before the first is used (we need to use a global because of classic workers).I tested it manually against @szabolcsdombi's example:
https://github.com/szabolcsdombi/pyodide-custom-module-imports/commit/3d51d923cb89941024ea31cc38b8df73a2a199ad
and it seems to work.
@sbc100
Checklists