logoalt Hacker News

hinkleyyesterday at 7:09 PM10 repliesview on HN

Still no mention of DOM.

<sets alarm for three years from now>

See you all for WASM 4.0.


Replies

flohofwoeyesterday at 7:25 PM

That old thing again ;)

Direct DOM access doesn't make any sense as a WASM feature.

It would be at best a web-browser feature which browser vendors need to implement outside of WASM (by defining a standardized C-API which maps to the DOM JS API and exposing that C API directly to WASM via the function import table - but that idea is exactly as horrible in practice as it sounds in theory).

If you need to manipulate the DOM - just do that in JS, calling from WASM into JS is cheap, and JS is surprisingly fast too. Just make sure that the JS code has enough 'meat', e.g. don't call accross the WASM/JS boundary for every single DOM method call or property change. While the call itself is fast, the string conversion from the source language specific string representation on the WASM heap into JS strings and back is not free (getting rid of this string marshalling would be the only theoretical advantage of a 'native' WASM DOM API).

show 5 replies
davexunityesterday at 8:10 PM

Wasm doesn't specify any I/O facilities at all. DOM is no different. There's a strict host/guest boundary and anything interacting with the outside world enters Wasm through an import granted by the host. On the web, the host is the JS runtime.

sjrdyesterday at 9:01 PM

Wasm 3.0, with its GC and exception support, contains everything you need. The rest is up to the source language to deal with. For example, in Scala.js [1], which is mentioned in the article, you can use the full extent of JavaScript interop to call DOM methods right from inside your Scala code. The compiler does the rest, transparently bridging what needs to be.

[1] https://www.scala-js.org/doc/project/webassembly.html

cdatayesterday at 7:23 PM

Don't sleep on the Rust toolchain for this! You can have DOM-via-Wasm today, the tools generate all the glue for you and the overhead isn't that bad, either.

show 2 replies
spankaleeyesterday at 7:28 PM

DOM wouldn't be part of WASM, it'd be part of the host.

If there ever is a WASM-native DOM API, WASM GC should help a lot with that.

someuser345today at 4:20 AM

End-users DON'T want developers' apps running in the browser to have freedom to access everything on the end-users' machines. Not having direct dom access is a security feature, as much as an MMU is. Please don't ask for this.

show 1 reply
whizzteryesterday at 7:41 PM

It's explicitly negated from the Wasm-GC spec, too damn much security issue surface that keeps all of the browser makers solidly in the "do not want to touch" camp.

Imustaskforhelpyesterday at 7:16 PM

I wish the same mate, Please wasm team, I am more than happy waiting 3 years if you can guarantee that you are looking into the best way possible into integrating this feature of dom manipulation.

I sometimes feel like js is too magic-y, I want plain boring golang and want to write some dom functions without using htmx preferably.

Please give us more freedom! This might be the most requested feature and this was how I came across knowing wasm in the first place (leptos video from some youtuber I think, sorry if i forgot)

show 1 reply
mikewarotyesterday at 8:19 PM

If you give WASM access to everything, you've defeated the main reason it exists. Ambient authority is the reason we need WASM in the first place.

show 1 reply