In the end, calling from WASM into JS isn't all that different than calling from native machine code into a virtual machine like .NET or the JVM.
In the end, calling from WASM into JS isn't all that different than calling from native machine code into a virtual machine like .NET or the JVM.
For an assembly language designed to run in the browser, I wouldn't characterize DOM access as "just one of many APIs". DOM access is the most universal need in front end programs.
I guess one can run WASM on servers, too, but aren't there plenty of ways there to do it already?
Depends on how you look at it. WASM itself doesn't have any browser specific features (and on purpose), it's a universal bytecode VM designed with strict sandboxing in mind.
You can manipulate the DOM from WASM by calling through a Javascript shim with very little overhead, same as it works for calling into other browser APIs like WebGL, WebGPU or WebAudio.
It just doesn't make all that much sense since WASM doesn't bring any benefit compared to manipulating the DOM via Javascript. Any theoretical performance advantage is pointless because the entire architecture of the DOM is slow by design.
But if you still want to do it, there are helpers like the Rust web_sys crate:
https://rustwasm.github.io/wasm-bindgen/api/web_sys/
Here's a simple DOM hello world:
I know, but other than being able to run it in the browser, does WASM have any other benefits over compiling into C, LLVM, etc?
https://hacks.mozilla.org/2020/02/securing-firefox-with-weba...