Hacker News new | past | comments | ask | show | jobs | submit login

Not anytime soon IMO because WASM still has to access browser APIs through the DOM, which is really built with JS in mind.



HTML DOM is described in terms of IDL interfaces, complete with types. I wouldn't say that it's optimized for JS - indeed, that's why jQuery and similar were introduced. When WHATWG took over, they improved it specifically for better JS interop, but it's still straightforward to map to most statically typed languages.

https://dom.spec.whatwg.org/#infrastructure

https://heycam.github.io/webidl/


The problem isn’t exposing the APIs, the problem is the wasm has what is essentially the C memory model, so you couldn’t trust any point/object you get from wasm land.

That’s why there so much work being put into giving wasm a more typical (for a vm) typed heap. Similar issues occur with lifetime of objects - if you get anything from the dom, you have to keep it live if wasm references it, but wasm has no idea of what memory or a handle is.

These are solvable problems, but you’re not getting dom access until after they’re solved.


Why can't wasm just use opaque handles for DOM objects? It doesn't need them to be in wasm-accessible memory, after all. It just needs to be able to invoke methods on them.


It’s not “wasm just needs to be able to invoke them”

Because the wasm memory model doesn’t have typed memory - if you call a dom api and get a handle back, you need to store it. Then you need to be able to pass it back to the host vm.

So now your wasm code needs to make sure the handle stays live - wasm by design doesn’t interact with the host GC, so you have to manually keep the handle alive (refcounting apis or whatever), and the host VM has to have someway to deal with you trying to use the handle without having kept it alive.

Similarly because wasm is designed around storing raw memory in the heap the wasm code can treat the handles as integers. Eg an attacker can just generate spoof handles and try to create type-confusion bugs, or maybe manually over release things.

So the problem isn’t “how do we let wasm make these calls” but rather “how do we do that without making it trivially exploitable”.


WASM ref handles for DOM nodes is comming.

https://github.com/WebAssembly/reference-types/blob/master/p...


But surely that is also fundamentally a solved problem? I mean, we've had distributed systems for a long time, and they had to deal with all the same issues - lifetime, security etc.


Distributed systems are designed (for better or worth) on the idea of non-malicious nodes.

Those that aren't have an extremely limited API - that would be logically not dissimilar from "untrusted wasm talks to more trusted JS".




Why not anytime soon? VBScript and Dart where given the ability to access the DOM in IE and Chrome in the past.




Consider applying for YC's first-ever Fall batch! Applications are open till Aug 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: