News for hackers. Stuff that matters.
Re:WASM 3.0 Completed by gspr on Wednesday September 17, 2025 @03:57PM (#45280662)
> 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.

From the point of view of someone who doesn't do web development at all, and to whom JS seems entirely cryptic: This argument is weird. Why is this specific (seemingly extremely useful!) "web thing" guarded by a specific language? Why would something with the generality and wide scope of WASM relegate that specific useful thing to a particular language? A language that, in the context of what WASM wants to do in making the web "just another platform", is pretty niche (for any non-web-person)?

For me, as a non-web-person, the big allure of WASM is the browser as "just another platform". The one web-specific thing that seems sensible to keep is the DOM. But if manipulating that requires learning web-specific languages, then so be it, I'll just grab a canvas and paint everything myself. I think we give up something if we start going that route.

Re:WASM 3.0 Completed by flohofwoe on Wednesday September 17, 2025 @04:19PM (#45280903)
Think of it as traditional FFI (foreign function interface) situation.

Many important libraries have been written in C and only come with a C API. To use those libraries in non-C languages (such as Java) you need a mechanism to call from Java into C APIs, and most non-C language have that feature (e.g. for Java this was called JNI but has now been replaced by this: https://docs.oracle.com/en/java/javase/21/core/foreign-funct...), e.g. C APIs are a sort of lingua franca of the computing world.

The DOM is the same thing as those C libraries, an important library that's only available with an API for a single language, but this language is Javascript instead of C.

To use such a JS library API from a non-JS language you need an FFI mechanism quite similar to the C FFI that's been implemented in most native programming languages. Being able to call efficiently back and forth between WASM and JS is this FFI feature, but you need some minimal JS glue code for marshalling complex arguments between the WASM and JS side (but you also need to do that in native scenarios, for instance you can't directly pass a Java string into a C API).

Re:WASM 3.0 Completed by jcul on Wednesday September 17, 2025 @05:44PM (#45281756)
Wow, I've used JNI many times, but many years ago. It is a bit painful. Cool to see it's been replaced by FFM, didn't know that existed.
Re:WASM 3.0 Completed by gspr on Wednesday September 17, 2025 @04:35PM (#45281072)
Sure, but if someone came at the C-centric ecosystem today and said "let's do the work to make it so that any language can play in this world", then surely "just FFI through C" would be considered rather underwhelming?
Re:WASM 3.0 Completed by flohofwoe on Wednesday September 17, 2025 @04:49PM (#45281254)
Well that's what the WASM Component Model set out to solve, some sort of next-gen FFI standard that goes beyond C APIs:

https://component-model.bytecodealliance.org/

In my opinion it's an overengineered boondoggle, since "C APIs ought to be good enough for anything", but maybe something useful will eventually come out of it, so far it looks like it mostly replaces the idea of C-APIs as lingua-franca with "a random collection of Rust stdlib types" as lingua-france, which at least to me sounds utterly uninteresting.

Re:WASM 3.0 Completed by afiori on Wednesday September 17, 2025 @05:47PM (#45281781)
While it can function as an FFI (it is indeed the basis of WASI) the component model is more about composability and interfaces
Re:WASM 3.0 Completed by dontlaugh on Thursday September 18, 2025 @04:23AM (#45287008)
DOM API interactions with JS are already described with a DDL, they're not exactly native JS APIs.
Re:WASM 3.0 Completed by afiori on Wednesday September 17, 2025 @05:43PM (#45281747)
The practical argument is that while initially the DOM API was developed to be language agnostic with more of an eye to Java/C++ than JavaScript since a while ago this is no longer the case and many web APIs use JavaScript data types and interfaces (eg async iterators) that do not map well to wasm

The good news is that you can use very minimal glue code with just a few functions to do most JavaScript operations