-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Rename wasmImpots
to envImports
and move actual wasmImports
to top level scope
#20130
base: main
Are you sure you want to change the base?
Rename wasmImpots
to envImports
and move actual wasmImports
to top level scope
#20130
Conversation
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.
While I kind of like the simplicity of this solution (as proposed in #20035 (comment)).. I'm also wondering if there is a better way to can officially support the two level namespace.
Adding a new global called imports
and making part of the ABI seems a little risky, since it would be hard to then change in the future.
I also wonder if we can come up with a better name than just imports
here. Its a shame wasmImports
is already taken. Perhaps we should rename the existing wasmImports
to envImports
so we can use wasmImports
for this new global?
src/preamble.js
Outdated
@@ -1129,16 +1130,16 @@ function createWasm() { | |||
#endif | |||
#if MODULARIZE | |||
// If instantiation fails, reject the module ready promise. | |||
instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject); | |||
instantiateAsync(wasmBinary, wasmBinaryFile, imports, receiveInstantiationResult).catch(readyPromiseReject); |
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.
If we are making the imports
object global, then perhaps we just remove the third argument from this function completely?
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.
found it used elsewhere
emscripten/src/library_async.js
Lines 541 to 550 in 0a6f54b
_load_secondary_module: async function() { | |
// Mark the module as loading for the wasm module (so it doesn't try to load it again). | |
wasmExports['load_secondary_module_status'].value = 1; | |
var imports = {'primary': wasmExports}; | |
// Replace '.wasm' suffix with '.deferred.wasm'. | |
var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm'; | |
await new Promise((resolve) => { | |
instantiateAsync(null, deferred, imports, resolve); | |
}); | |
}, |
Indeed, I personally think that the The name "imports" was chosen because I see that |
createWasm
wasmImpots
to envImports
and move actual wasmImports
to top level scope
Can such changes be merged? |
I believe this was fixed in a separate PR: #20231. Sorry I forgot we had two different PRs for the same thing |
It’s been a month since #20035 was opened and you may have forgotten the details. Initially, I hoped to add the |
Ah yes, sorry I see that #20231 was related to same variable but not trying to solve the same issue. |
7ec9a5a
to
6fda833
Compare
Branch updated. Please take a look if you have time. If there is a better way to solve #20035 in a short time, I don't mind closing this PR and waiting for official support. |
I would love to find a way to fix #20035 in a nicer way. I did take a stab at it a few days ago but I ran into some roadblock. In the long term I do think its something we do want to support, I'm just not clear what the best path forward is at this moment. This change is looks little invasive, which is making me think twice about it. |
Thank you for your nice work. I'm looking forward to good news. Once this feature is supported, then I can advance the header change landing on Node.js side. |
any progress/update on this? |
As #20035 (comment) proposed, move imports definition outside the
createWasm
function for allowing user specify custom namespace in JS library.I'm not very familiar with emscripten codebase and can only make such a simple change, not sure what will be affected. it looks like all the variables used in the
imports
are in the same scope so maybe it's not a problem? Feel free to close this if it really breaks something.