-
Notifications
You must be signed in to change notification settings - Fork 830
Fixes for #5998 #1341
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
Fixes for #5998 #1341
Conversation
|
The filesystem was "needed" because of iostream usage. |
|
Ok, this should fix everything now. Added a wasm.js fix for recent emscripten and testing fixes and improvements (run binaryen.js tests in all engines). One change here is to move binaryen.js to use standard emscripten MODULARIZE (like wasm.js). I needed that because things had broken in non-node.js for some reason. @dcodeIO , I think you wrote that code, is that ok? Note that it means we emit Binaryen as a function, so the test suite and users now do One odd thing is that this modified some of the test outputs - what I think are pointer values changed. We should probably remove those from the output, as they will change over time. It might even fail now on the bot given it's using an older emsdk version, we'll see... |
|
As long as the exported interface is the same (that is, Regarding pointer values:; Yeah, these tend to change every time something is changed and binaryen.js is recompiled. There are a few occasions where something seems wrong, like for the names in the tests (probably missing a Pointer_stringify), but there are others like |
|
About changing the interface, I'm not sure what's best. In MODULARIZE the exported About the pointer numbers, I guess we can leave them as-is for now, as the tests pass here. But I'm not sure exactly why it's not complaining already, something seems odd. |
|
Ah, I see what's been going wrong... we build |
|
Good, and now it fails as expected on the bot. |
|
And with the last commit it should work, without printing the pointer values that the tests now clean out. This PR should be finished now, assuming tests pass. |
|
Just noticed that the module loader code is gone entirely. Does MODULARIZE add similar checks for require/define and the global object on its own? |
|
I'm not sure how - I've never really understood how require and module loading etc. work, to be honest. But we have tests check for require, for example https://github.com/kripken/emscripten/blob/incoming/tests/test_other.py#L5420 |
|
It's relatively simple, actually: CommonJS is synchronous: Check if a global if (typeof require === "function" && typeof module !== "undefined" && module && module.exports)
module.exports = the_interface;// other file would do
var Binaryen = require("./path/to/binaryen");
// Binaryen is `module.exports` from aboveAMD is asynchronous: Check if a global if (typeof define === "function" && define.amd)
define(function() { return the_interface });// other file would do
define(["./path/to/binaryen"], function(Binaryen) {
// Binaryen is what is returned from the factory function above
});Additionally it's always a good idea to expose the module on the global object ( var globalObject = typeof window !== "undefined" && window || typeof global !== "undefined" && global || self;
globalObject.the_module_name = the_interface;Unordered seems to be ideal, that is export unconditionally in every way possible so it "just works" no matter what. If you want I'll take a look after this is merged. Could also be an enhancement to |
|
Thanks, I understand better now. Is it standard though to add it to the global object, don't most people use the proper In any case, yeah, let's look into this as a general improvement of MODULARIZE. People on the emscripten repo will know more about this than me there. Otherwise this looks ok to merge? |
There is something called universal module definition (UMD) that doesn't go as far as my suggestions above, e.g., doesn't unconditionally export on the global object. That's somewhat how it was before this PR. In my experience, though, additional issues originate from mixing these things, which is sometimes inevitable when different modules from different authors with different loaders combined with different bundlers are used in a single application. Not sure what's best. UMD as above forces everyone to create compatible modules while doing more avoids more issues.
Might fail with AMD loaders at first. I am not using AMD myself, but I can take a look and send a PR as a follow-up, probably simply consisting of adding the following two lines to if (typeof define === "function" && define.amd)
define(function() { return Module; });That should do for now if |
|
Ok, let's merge this in. For followups, let's discuss those two lines in emscripten since it seems like a general thing for modularize? |
|
I think I made a mistake by suggesting to call the Binaryen() function implicitly because exports aren't consistent now. AMD and CommonJS export the factory function while the |
|
Hmm, so should we assign the output of |
|
Alternatively, maybe there is a use for exporting the constructor, people may want multiple Binaryen instances for some reason? In which case, users should do the instantiation? |
|
Hmm. From a JS/node module perspective I'd say that a user expects a ready-to-use API on In this context It pretty much boils down to the question whether exporting a default instance of a module makes sense for a specific emscripten-compiled module or not. A static Let's say, when |
|
If there ever be |
|
Yeah, that was my thought. Like providing a similar API like WebAssembly in the browser, while still providing a way to export something like a synchronously instantiated node module. |
|
In a hypothetical |
|
I don't know the full picture, but if the instantiation code runs once anyway, there's not much a tree-shaking/dead-code-eliminating compiler could optimize away - unless singleton instantiation is simpler and can exclude a heap of code. Can it? |
|
Yeah, singleton instantiation is simpler for a VM. It can see that the code will never be used again and throw it away immediately after it runs, also it can avoid adding type profiling code as it compiles it (except for loops) etc. But, as I said I'm not sure it would matter much here. We should probably err on the side of the nicest API for users. |
This should help with emscripten-core/emscripten#5998 , but I don't have time right now to test it completely.