WASM loader does not expose importObject
See original GitHub issueWebAssembly modules are able to import foreign Javascript functions and memory objects that are passed in the second parameter of WebAssembly.instantiate(...)
. Unfortunately the current WASM loader is hard-coded to call instantiate
with no import object.
https://github.com/parcel-bundler/parcel/blob/master/src/builtins/loaders/wasm-loader.js https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate
The simplest solution would be to have the WASM loader instead run WebAssembly.compile(...)
and return the compiled WebAssembly.Module
, so the user can call WebAssembly.instantiate(...)
with whatever parameters they need. I think that’s how Webpacks wasm loader works.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:21
- Comments:11 (3 by maintainers)
Top Results From Across the Web
failed to load wasm application - Stack Overflow
ImportObjects is just an object you create with functions etc you want to expose to the wasm module. If you don't expose any...
Read more >Using the WebAssembly JavaScript API - MDN Web Docs
This article has taken you through the basics of using the WebAssembly JavaScript API to include a WebAssembly module in a JavaScript ...
Read more >Load wasm module using manifest V3 - Google Groups
The problem is that after enabling wasm loading in webpack, I get the following error ... Above code can still work in some...
Read more >Understanding the JS API - WebAssembly
For basic loading, there are three steps: ... Instance objects are like function closures, pairing code with environment and are not structured cloneable....
Read more >The `wasm-bindgen` Guide - Rust and WebAssembly
It does not generate an ES module. With that in mind the main difference is how the wasm/JS code is loaded, and here's...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
You’re correct, this is the right approach. WASM modules will eventually be ES modules, so imports/exports should work the same as they do in JS. I will likely be championing this over the next few months. Work will be tracked in https://github.com/WebAssembly/design/issues/1087
The webpack folks also brought this up. If no one responds with a plan to address this, I’ll bring it up in our biweekly WASM toolchain meeting (which is next Tuesday) and see if I can figure out what the plan is.
It would be really nice to have support for
importObject
– a killer feature of WASM is the ability to call JS functions from WASM modules (as well as the other way round of course)!I feel that you shouldn’t have to compile WASM modules already knowing the paths of JS files they use. It would be nice to simply have them as standalone binary modules to which you can pass in imports they need to run (in keeping with the JS
WebAssembly.instantiateStreaming()
API).Besides, this would also open up support for wasm_bindgen as well as other existing WASM compilers. @hitecherik and I thought perhaps a syntax like this would be preferable (and compatible with the current import syntax)…