-
I'm using chrome 119 and I want to know if there is a way on the js side to read the data in the ref element returned in wasm: I use Here are my test codes: WebAssembly.instantiateStreaming(fetch('./example.wasm'), {})
.then(out => {
let data = out.instance.exports._start();
console.log(data)
}) (module $structure-example
(type $Point (;0;) (struct (field $field0 f64) (field $field1 f64)))
(func $_start (;1;) (export "_start") (result (ref $Point))
struct.new_default $Point
)
) (module $array-example
(type $UTF32Text (;0;) (array (field i32)))
(func $_start (;1;) (export "_start") (result (ref $UTF32Text))
i32.const 72 (;H;)
i32.const 101 (;e;)
i32.const 108 (;l;)
i32.const 108 (;l;)
i32.const 111 (;o;)
array.new_fixed $UTF32Text 5
)
) Is there a standard that requires browsers to return |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
WasmGC structs and arrays are completely opaque to JS, which is why you're seeing an empty object |
Beta Was this translation helpful? Give feedback.
WasmGC structs and arrays are completely opaque to JS, which is why you're seeing an empty object
{ }
. That also means that the only way to access their contents from JS is by calling exported Wasm functions that can do the accesses. There is broad interest in making this easier, but all the obvious solutions would be technically very challenging to implement in JS engines, so I wouldn't expect this to change soon.