-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
webidl: Turn the [Throws]
extended attributes into Result<T, JsValue>
#457
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
webidl: Turn the [Throws]
extended attributes into Result<T, JsValue>
#457
Conversation
…ue>` This sets the `catch` flag on the emitted AST when an operation/attribute has the `[Throws]` extended attribute on it. Additionally, constructors aren't annotated with `[Throws]` but can still throw exceptions, so we must conservatively assume *every* constructor can throw an error.
// > value of a type corresponding to the interface the | ||
// > `[Constructor]` extended attribute appears on, **or throw an | ||
// > exception**. | ||
let throws = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little unfortunate :(
I wonder though if we can add configuration options to the generation to handle this? I'd expect that the majority of webidl constructors don't actually throw (or we're not interested in what they throw). We could perhaps explicitly whitelist some constructors as throwing but all others would be infallible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could certainly add our own [WbgNoThrowConstructor]
extended attribute if we get to a place where we want to explicitly whitelist some constructors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps yeah, although I was thinking moreso the build script rather than modifying the webidl files themselves, but either way's fine!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if WebIDL had a NoThrowsConstructor
or something like that.
I think for now, we should probably just leave this as is, and maybe come back to some whitelist thing -- maybe make an issue about it?
Edit: Seems I was beat to the punch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll file a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
This sets the
catch
flag on the emitted AST when an operation/attribute has the[Throws]
extended attribute on it.Additionally, constructors aren't annotated with
[Throws]
but can still throw exceptions, so we must conservatively assume every constructor can throw an error.