webidl: Turn the [Throws] extended attributes into Result<T, JsValue>

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.
This commit is contained in:
Nick Fitzgerald
2018-07-11 11:07:03 -07:00
parent eabbe0e56e
commit 3cdb6ef03a
6 changed files with 251 additions and 29 deletions

View File

@ -35,6 +35,23 @@ pub fn raw_ident(name: &str) -> Ident {
/// Create a path type from the given segments. For example an iterator yielding
/// the idents `[foo, bar, baz]` will result in the path type `foo::bar::baz`.
pub fn simple_path_ty<I>(segments: I) -> syn::Type
where
I: IntoIterator<Item = Ident>,
{
path_ty(false, segments)
}
/// Create a global path type from the given segments. For example an iterator
/// yielding the idents `[foo, bar, baz]` will result in the path type
/// `::foo::bar::baz`.
pub fn leading_colon_path_ty<I>(segments: I) -> syn::Type
where
I: IntoIterator<Item = Ident>,
{
path_ty(true, segments)
}
fn path_ty<I>(leading_colon: bool, segments: I) -> syn::Type
where
I: IntoIterator<Item = Ident>,
{
@ -49,7 +66,11 @@ where
syn::TypePath {
qself: None,
path: syn::Path {
leading_colon: None,
leading_colon: if leading_colon {
Some(Default::default())
} else {
None
},
segments: syn::punctuated::Punctuated::from_iter(segments),
},
}.into()