4 ms·
How about making WASM actually work for its target use-case (the browser) rather than needing to be chaperoned around by Javascript stubs?
by jujube3 2y ago
How about making WASM actually work for its target use-case (the browser) rather than needing to be chaperoned around by Javascript stubs?
- andrewfromx 2y agohttps://andrewarrow.dev/frame/wasm https://andrewarrow.dev/frame/wasm everything I do now for the web is backend go, AND frontend go wasm
- danielvaughn 2y agoI think what the original comment means is that WASM is heavily sandboxed in the browser environment, and cannot interact with the DOM APIs directly. You still need JS for that.
- andrewfromx 2y agonot all all. I just have: <script>document.addEventListener("DOMContentLoaded", function() { const go = new Go(); WebAssembly.instantiateStreaming(fetch("/assets/other/json.wasm.gz"), go.importObject).then((result) => { go.run(result.instance); WasmReady('welcome.html'); }); });</script> and <script src="/assets/javascript/wasm_exec.js" class=""> and that's it! Then from go there's nothing I can't do in the DOM.
- pfraze 2y agoDoes wasm provide synchronous access through the perimeter?
- andrewfromx 2y agoWebAssembly itself does not provide synchronous access directly; the interactions with WebAssembly modules in browsers are asynchronous. This is because WebAssembly operations, like module instantiation and function calls, are designed to fit into JavaScript's event-driven, non-blocking model.
- JasonSage 2y agoThe `new Go();` is doing all the JS that you claim to not be doing.
- andrewfromx 2y agobut all my logic that changes the DOM is in go. What am I missing?
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- Rohansi 2y agoYour logic still needs to run JS code to change the DOM. You are indirectly relying on JS despite using WASM.
- andrewfromx 2y agook but I have all the advantages of go. I can code my go in a modern way and escape JS traps despite the end result is still using js.
- vrighter 2y ago
- zbentley 2y agoI think GP was referring to running wasm directly rather than using (as your website does with WebAssembly.instantiateStreaming) JS APIs to bootstrap it and JS APIs every time it needs to do something with the browser's built-in functionality (like manipulate the DOM).
- andrewfromx 2y agocan you link me to example that does wasm in browser without calling instantiateStreaming?
- mvdtnz 2y agoHis entire point is that it can't be done currently.
- andrewfromx 2y agoso what's the big problem with calling instantiateStreaming? Explain it to me like i'm 5
- zbentley 2y agoinstantiateStreaming is not the problem; the problem is that JS code is necessary (via that function or another) to execute WASM, and JS is necessary to call back from WASM into browser APIs. Because of that, WASM in the browser is, at present, effectively a JavaScript extension language, and it cannot meet the goals discussed by Crockford in TFA. This hybrid approach that requires JS both at bootstrap and browser-API-interaction time significantly undercuts the benefits of WASM as a javascript replacement for several reasons. Some of those reasons are: this likely means JS will remain supported/enabled/required-for-many-sites in browsers, warts and all, in perpetuity; the advantages of WASM's sandboxability will be mitigated by the presence of a much more permissive runtime that must be present in order to load and run WASM artifacts; more performant/parallel access to browser APIs will remain difficult or impossible; multi-language/multi-build system competence will be needed due to large parts of the ecosystem remaining in browser JS.