-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Details of the JS API for exception handling #150
Comments
Why would it be 'WA.Exception' and not 'WA.Event', since the module deals in events, and exceptions are just one event class among others? The Event object might then have attribute() and type() accessors. |
@lars-t-hansen, when we were discussing the 2nd proposal formal spec, @rossberg and I agreed that Events should only be a bit in the binary format for future compatibility and that Events should be not mentioned at all in the formal spec (see e.g.this, this, and this comment). However, that was a very long discussion on many details of the formal spec, and I don't know what @aheejin or others think about this. |
Hm, I haven't really thought about the best way to expose these in JS land. I suppose that WA exceptions should also be JS exception, since you can catch them. But will that be true for other future forms of events? Could it be that we'll ultimately need some JS class hierarchy for this? |
Oh interesting, switching to use "Exception" terminology rather than "Event" terminology would be a big shift in my mental model of the proposal. I see the appeal and I'm sure I'd get used to it quickly, though. |
Sorry for the late reply. Yes I think we should flesh out the JS API before we proceed to Phase 3. I agree there better be a way to construct an exception from JS and throw it. It is different from wasm instructions though, with which we do creating and throwing at the same time, but wasm exception will surface as a JS exception anyway, I think having a dedicated class for wasm exception and making a way to create it make sense. The 'exception' I am talking about here is a constructed exception that contains an event tag and its arguments. Someone, I don't remember exactly, suggested to call this I'm not sure if we need to define Previous discussions, especially #109, started assuming the existence of I imagine with the JS API we can do thing like let event = new WebAssembly.Event({parameters: ["i32", "f32"]);
let exn = new WebAssembly.Exception(event, [1, 3.5]);
WebAssembly.throw(exn); I also think it makes sense for On @takikawa's original post: |
Thanks for the reply @aheejin. :) Some replies inline below:
I don't have a strong opinion here, but I think the idea was that since this proposal only introduces exception events and no other event attributes are currently planned, it could make sense to avoid the generalization and use
I agree that this likely isn't needed in the current proposal. And in particular the
I think this makes sense. I had left out a
Yes I agree with your last sentence. The BTW: I have some WIP patches that implement the API sketch above (without type reflection) for SpiderMonkey in this bug. If you click the attachment links you can also find JS/Wasm test cases that demonstrate how it might work. |
I'm not very opinionated on this. I think we can make it back to Also, if we decide to change the current
Oh, I think you are right. Maybe we don't need to add
Great that it is already in progress in FireFox! So to sum up,
|
Sorry for the lack of progress/update on my end here, in an effort to help move the discussion forward I made a PR in #154 that adds text to the overview document taking into account the discussion here and @aheejin's summary and code example. From Heejin:
Aside from the naming (BTW I used the names
(so if anyone has any thoughts for/against those, that'd be great) Also @rossberg had mentioned that maybe Wasm exceptions should also be JS exceptions. My concrete interpretation of this was: should the thrown exception class be a subclass of JS |
#154 looks good to me. I'm actually on the fence regarding making WA.RuntimeException a subclass of Error and would be fine leaving it as is. |
Apologies I missed the @-mentions in this issue! I agree with the original suggestion that there is no real reason to keep the term "event" except as a bit in the binary format in case we do add events in the future. |
Closed by #154. |
Now that the semantics for the current iteration of the proposal are fairly solid and two browser implementations are underway, I was wondering if this is a good time to figure out the details for the JS API for exceptions.
@Ms2ger has written up draft JS API spec text which provides a good baseline to expand on. This draft was made during the previous iteration of the semantics, so it needs an update to remove
exnref
. But it already describesWebAssembly.Exception
andWebAssembly.RuntimeException
that are discussed below and additional API features can be incorporated into it.Here are some of the aspects that the final JS API could/should likely provide, along with some design questions on how these aspects should work:
WebAssembly.Exception
.WA.Exception
.type()
method on exceptions.WebAssembly.RuntimeException
.WebAssembly.RuntimeException
and to keep it separate fromWebAssembly.RuntimeError
.values()
orgetArg()
method, usingToJSValue
to coerce Wasm values to JS as usual)ToWasmValue
)In terms of features, IMO it would make sense to allow accessing the values (requiring the exception type for access) and to allow constructing exception objects. Not adding this functionality won't actually prevent JS hosts from doing these operations (both limitations can be hacked around by constructing a new Wasm module) but adding it will make it more convenient.
There was some past discussion here and here on how/whether to allow constructing exception objects in JS, given the values to put in the exception. Ms2ger's draft assumes that the
WA.RuntimeException
constructor would also take aWA.Exception
argument as well. IMO this would make sense to keep in the API in order to extract the tag out of the exception type. Not having this argument would make the constructor pretty useless, as without a tag such exceptions could only be caught bycatch_all
.Are there any other aspects of the JS API that should also be discussed?
The text was updated successfully, but these errors were encountered: