|
|
|
|
|
by klibertp
1539 days ago
|
|
I think you actually can't pass any non-trivial object to WASM. The only thing you can pass to and get out of WASM (IIRC) is a chunk of linear memory, a buffer. I don't think it's possible to obtain a raw pointer to an object on a JS side - passing that would be very unsafe, but also pretty much useless, unless you knew precisely the memory layout of said object. If you need to expose operations on a more complex objects to WASM, you need to encode the object identity somehow (as a number, or a buffer) and expose an API that will decode the object reference and call the needed function/method on it. |
|
Doing a network request from C++:
https://emscripten.org/docs/api_reference/val.h.html#val-hOf course this can be thrown out of the JavaScript binding side so that it isn't there anymore, but the marshalling makes the API nice and so many emscripten users will use it, thus it's present, thus you have to trust the wasm library.
How complicated this is without emscripten i don't know, but even then I guess many people will need some marshalling for real life scenarios.