Bug 1759217 Comment 11 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

(In reply to Hamish Willee from comment #10)

> A few notes/questions
> 1. The fact that tags have identity makes a lot of things more clear. Thanks.
> 2. You only need the tag to throw an exception and to decode it. So if you create a tag in JS and then that JS is called from WASM and throws, you only need to also import the tag into the module IFF you want the module to be able to interpret the exception. You don't have to if you're happy for the exception to propagate up to JS to handle, or for it to be caught in a catch_all. That's what the examples do now in the linked docs anyway.


> 
> 4. How do you run that `wasmTextToBinary` sample? Is there a shell or something where this method is defined?
>    I'm running wat2wsm locally because https://webassembly.github.io/wabt/demo/wat2wasm/is not working for exceptions, but that is a bit slow.

The SpiderMonkey engine has a JS shell CLI program which contains a `wasmTextToBinary` function. I think you can use jsvu [1] to download a SpiderMonkey shell, but I haven't done that in a while. The other way would be to compile SM from source [2].

There's also wasm-tools [3] which should be runnable in CLI and contains the text to binary converter that we use in SpiderMonkey.

[1] https://github.com/GoogleChromeLabs/jsvu
[2] https://firefox-source-docs.mozilla.org/js/build.html
[3] https://github.com/bytecodealliance/wasm-tools/

> 
> 5. I can see how this works for me as a test code writer. What if I want to port a C++ app, that happens to throw a particular exception. Would it be that a tool author for C++ (say) would define some standard exceptions and map the standard libraries etc such that there would be a whole lot of exported "standard exceptions"? I guess I'm trying to understand if this is just a fundamental precondition that people writing code use, or is it something that will be an intermediate step for emscripten and others? Hope that makes sense.
Sorry for the delay, I was on leave last week.

(In reply to Hamish Willee from comment #10)
> 2. You only need the tag to throw an exception and to decode it. So if you create a tag in JS and then that JS is called from WASM and throws, you only need to also import the tag into the module IFF you want the module to be able to interpret the exception. You don't have to if you're happy for the exception to propagate up to JS to handle, or for it to be caught in a catch_all. That's what the examples do now in the linked docs anyway.

Yes, that's correct.

> 
> 4. How do you run that `wasmTextToBinary` sample? Is there a shell or something where this method is defined?
>    I'm running wat2wsm locally because https://webassembly.github.io/wabt/demo/wat2wasm/is not working for exceptions, but that is a bit slow.

The SpiderMonkey engine has a JS shell CLI program which contains a `wasmTextToBinary` function. I think you can use jsvu [1] to download a SpiderMonkey shell, but I haven't done that in a while. The other way would be to compile SM from source [2].

There's also wasm-tools [3] which should be runnable in CLI and contains the text to binary converter that we use in SpiderMonkey.

[1] https://github.com/GoogleChromeLabs/jsvu
[2] https://firefox-source-docs.mozilla.org/js/build.html
[3] https://github.com/bytecodealliance/wasm-tools/

> 
> 5. I can see how this works for me as a test code writer. What if I want to port a C++ app, that happens to throw a particular exception. Would it be that a tool author for C++ (say) would define some standard exceptions and map the standard libraries etc such that there would be a whole lot of exported "standard exceptions"? I guess I'm trying to understand if this is just a fundamental precondition that people writing code use, or is it something that will be an intermediate step for emscripten and others? Hope that makes sense.

This depends a bit on how the C++ toolchain wants to use the wasm feature, so it depends.

My understanding is that C++ compiled with LLVM will generate a single tag to represent 'any exception'. A C++ source level throw of any exception object will use this tag in the wasm throw instruction. The wasm tag/exception will contain a single i32 value which is a pointer into wasm memory referencing the thrown C++ exception object. So a C++ app would only have a single wasm tag for all C++ exceptions. This tag could be exported so that JS could decode C++ exceptions. This description of how C++ uses wasm exceptions may not be entirely correct, it's from viewing some disassembly and conversations - not thorough investigation.

I have also heard that LLVM may use the wasm exception-handling proposal to implement the setjmp/longjmp feature [1]. In this case they would define another tag for use in all setjmp/longjmp code to distinguish that from exceptions.

[1] https://en.cppreference.com/w/cpp/utility/program/setjmp

Back to Bug 1759217 Comment 11