Is it specified somewhere how non-numeric values are treated if returned from a host function back to WASM? I saw that if I e.g. return an object {} or some other value that doesn't match one of WASM's types it converts that to 0. Is that in the spec somewhere or is it up to the host runtime to decide how to convert the values when returned?
I looked here https://webassembly.github.io/spec/js-api/index.html#instances but didn't find anything. Maybe I missed it.
I think you're looking for ToWebAssemblyValue and ToJSValue
https://webassembly.github.io/spec/js-api/index.html#towebassemblyvalue
https://webassembly.github.io/spec/js-api/index.html#tojsvalue
used in the spec here: https://webassembly.github.io/spec/js-api/index.html#call-an-exported-function
Thanks so much @fitzgen (he/him) :pray:
Last updated: Dec 06 2025 at 05:03 UTC