To do some follow-up on #76, specifically about the case of Wasm exception objects and how they behave wrt. debuggers.
In Munich, we discussed this issue IIRC with @lukewagner and @aheejin (if I made the right GitHub handle connections). One possible solution came up that would build on Custom Descriptors: a standardized well-known symbol that redirects to a "real" JS Error instance.
Currently, exception objects like java.lang.Throwable are Wasm objects, so they cannot extend the JS Error class, and do not get stack trace information. However, we make them contain, in a field, a reference to a freshly allocated Error instance. This allows to implement things like Throwable.getStackTrace() by inspecting the underlyingJSError.stack property. So we're not completely clueless: internal language tools, testing frameworks, etc., understand the stack traces.
What we're missing is for debuggers to understand our exception objects. A possible solution would be to use Custom Descriptors to expose the underlying Error instance in a standardized way, which debuggers could access:
- Define a well-known symbol
WebAssembly.underlyingError
- Register a
get [WebAssembly.underlyingError]() on the JS prototype associated to java.lang.Throwable
- Have its body return the
Error instance that we are storing inside our exception objects.
Now, debuggers can use that information. If they hold a thing e that's not an "error object", they can try to look into e[WebAssembly.underlyingError] to get a second chance. They could then offer all the nice debugging infrastructure for Wasm objects, based on that underlying Error instance.
Arguably, such a proposal could go all the way up to TC39 as Symbol.underlyingError rather than WebAssembly.underlyingError.
To do some follow-up on #76, specifically about the case of Wasm exception objects and how they behave wrt. debuggers.
In Munich, we discussed this issue IIRC with @lukewagner and @aheejin (if I made the right GitHub handle connections). One possible solution came up that would build on Custom Descriptors: a standardized well-known symbol that redirects to a "real" JS
Errorinstance.Currently, exception objects like
java.lang.Throwableare Wasm objects, so they cannot extend the JSErrorclass, and do not get stack trace information. However, we make them contain, in a field, a reference to a freshly allocatedErrorinstance. This allows to implement things likeThrowable.getStackTrace()by inspecting theunderlyingJSError.stackproperty. So we're not completely clueless: internal language tools, testing frameworks, etc., understand the stack traces.What we're missing is for debuggers to understand our exception objects. A possible solution would be to use Custom Descriptors to expose the underlying
Errorinstance in a standardized way, which debuggers could access:WebAssembly.underlyingErrorget [WebAssembly.underlyingError]()on the JS prototype associated tojava.lang.ThrowableErrorinstance that we are storing inside our exception objects.Now, debuggers can use that information. If they hold a thing
ethat's not an "error object", they can try to look intoe[WebAssembly.underlyingError]to get a second chance. They could then offer all the nice debugging infrastructure for Wasm objects, based on that underlyingErrorinstance.Arguably, such a proposal could go all the way up to TC39 as
Symbol.underlyingErrorrather thanWebAssembly.underlyingError.