Repository navigation
Conversation
…LE_EXPORTS=0 Since emscripten-core#25530, mutable Wasm globals are exported to JS as WebAssembly.Global objects rather than plain numbers. This was only done in the static create_receiving path in emscripten.py; the dynamic $assignWasmExports used with DECLARE_ASM_MODULE_EXPORTS=0 still unwrapped every global into a number. Rather than embedding the names of all exported mutable globals in the JS, probe each exported global by writing back its current value: this throws for immutable WebAssembly.Global objects, which are then unwrapped to plain numbers as before. The probe is only emitted when the module exports at least one mutable global (new internal setting HAS_MUTABLE_GLOBAL_EXPORTS), so code size is unchanged in the common case. Under wasm2js, immutable globals are also exported with a setter, so when any mutable global is exported, all exported globals stay as objects. Fixes the omitexports0 part of emscripten-core#25550. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Can I ask, are you using DECLARE_ASM_MODULE_EXPORT=0 in production?
It seems like a pretty limited settings since it depends on using globalThis to store all the exported symbols meaning that only one emscripten-generated program can live in a given context. This seems like a pretty big limitation.
This is 99% of Unity generated pages. If multiple apps are needed, they are almost always wrapped in iframes, because browsers have bugs in garbage collecting full pages away. (this is what itch, poki, crazygames, youtube and all those other Unity content serving gaming portals do) Tiny Unity used to ship with this flag. Current Unity doesn't though (which has been a TODO to investigate if it can help) |
I get that there is likely only one unity app on a given page.. but what about other wasm content that might live on the same page. Folks use wasm content for all kinds of things right? I guess you right that a lot of wasm content might be in iframes. I will be curious to see if/when you revisit this. I'd love to remove this strange hacky path if possible! |
Hmm.. we haven't gotten reports that users would have had other wasm compiled content on the same page/iframe context. They could theoretically have other wasm compiled content on the site, but the globalThis would point to the local iframe still for the unity content part. |
Since #25530, mutable Wasm globals are exported to JS as WebAssembly.Global objects rather than plain numbers. This regressed DECLARE_ASM_MODULE_EXPORTS=0 path.
Rather than embedding the names of all exported mutable globals in the JS, probe each exported global by writing back its current value: this throws for immutable WebAssembly.Global objects, which are then unwrapped to plain numbers as before. The probe is only emitted when the module exports at least one mutable global (new internal setting HAS_MUTABLE_GLOBAL_EXPORTS), so code size is unchanged in the common case.
Under wasm2js, immutable globals are also exported with a setter, so when any mutable global is exported, all exported globals stay as objects.
Fixes the omitexports0 part of #25550.