WebAssembly and DOM Support: The Future of Glue Code
The question of whether WebAssembly (Wasm) is truly production-ready for web applications, given its need to integrate with web pages and APIs like the DOM, is addressed. The article argues that direct DOM access in Wasm isn't necessary; existing JavaScript APIs and compiler-generated glue code provide seamless integration. While a mechanism for directly calling web APIs might be added in the future, it would require significant effort. Currently, Wasm leverages JavaScript function imports (e.g., `console.log`) and cleverly uses JavaScript object array indices to manage object references, enabling flexible interaction with JavaScript. This approach, while not purely Wasm, effectively boosts performance. Ongoing improvements in exception handling, blocking I/O, and garbage collection are further optimizing Wasm-JavaScript integration efficiency. The author concludes that Wasm's focus should be on improving program performance, not eliminating JavaScript entirely. The future of WebAssembly involves refining the component model and toolchains to enhance interoperability with JavaScript without sacrificing performance or code size.