Skip to content

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

Merged

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Jul 11, 2018

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.

…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.
@fitzgen fitzgen requested review from ohanar and alexcrichton July 11, 2018 18:09
// > value of a type corresponding to the interface the
// > `[Constructor]` extended attribute appears on, **or throw an
// > exception**.
let throws = true;
Copy link
Contributor

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?

Copy link
Member Author

@fitzgen fitzgen Jul 11, 2018

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.

Copy link
Contributor

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!

Copy link
Member

@ohanar ohanar Jul 11, 2018

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@ohanar ohanar left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants