5 ms·
after reading many tutorials about WASM I still figured out one of the most important questions for me: Would I be able to call JS functions from WASM? or pass
by tamat 9y ago
after reading many tutorials about WASM I still figured out one of the most important questions for me:
Would I be able to call JS functions from WASM? or pass callbacks to WASM. Because WASM sounds like it goes agains the async nature of JS and I have the feeling that is going to be very annoying to merge both worlds.
Also if I cannot call any JS func from WASM it means I cannot call WebGL or Audio so I dont know what would I need the performance if I cannot access the most performance demanding APIs.
- westoncb 9y agoIt seems like it would be a little backward to go from WASM to javascript in order to invoke native code (in e.g. an OpenGL driver). More likely WASM will have some way of its own to interface with such things. Right?
- Rusky 9y agoYes, JS and wasm can call each other. In the long run wasm should also be able to call web APIs directly.
- infogulch 9y agoIs wasm also restricted to running on one thread like js?
- Rusky 9y agoNo, though neither is Javascript. (I am not sure how far along non-WebWorker-based wasm threads are, but here's the proposal: https://github.com/WebAssembly/threads https://github.com/WebAssembly/threads)
- moosingin3space 9y agoShared-memory threads are something I hope lands in WASM, since they're part of the reason you'd want to drop down to WASM in an application in the first place.
- white-flame 9y agoWasm has explicitly declared imports & exports, so that it can be called from, and call into, both JS and other wasm modules. I haven't seen anything regarding dynamic linking, but just linking these declarations at wasm module start time. The interface should take care of all type conversion between wasm and JS primitive types (notably varying integer sizes and JS floats). wasm's 64-bit integers will likely not be allowed across a JS<->wasm interface.