WebAssembly / exception-handling

Proposal to add exception handling to WebAssembly
https://webassembly.github.io/exception-handling/
Other
160 stars 35 forks source link

wast doesn't seem to have a way to test uncaught exception in start function #322

Open yamt opened 2 months ago

yamt commented 2 months ago

maybe we need to add assert_exception for a module?

rossberg commented 2 months ago

Usually one can encode such checks in Wasm itself with some wrapper function, but the start function is an interesting exception.

An assert_exception might make sense, the only problem is that there is no obvious way to refer to a specific exception, i.e., a tag, outside of a module. We could have an assertion that cannot check the exception, but that seems a bit half-arsed. Perhaps the tag would have to be identified by a module + export name?

Strawman:

(assert_exception (tag moduleid? "name") value*)

where the values are the exception's expected payload.

But can such an assertion always be translated to JS easily, e.g., if the exception carries a v128? In the case of call results, the interpreter's JS translation synthesises a Wasm wrapper performing the check in such cases, but for exceptions that's a bit more more work and won't directly extend to the implicit invocation of the start function. It would at least require some extra indirection bouncing back between Wasm and JS to wrap a Wasm handler around module instantiation.