Skip to content

Commit 7355acf

Browse files
committed
Mark some set_* fns as potentially throwing.
Make attributes marked `[SetterThrows]` use a `set_*` function that returns a `Result`. Currently webidl only looks for a `[Throws]` attribute.
1 parent 1ceec1a commit 7355acf

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

crates/webidl/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use crate::generator::{
2525
use crate::idl_type::ToIdlType;
2626
use crate::traverse::TraverseType;
2727
use crate::util::{
28-
camel_case_ident, is_structural, is_type_unstable, read_dir, shouty_snake_case_ident,
29-
snake_case_ident, throws, webidl_const_v_to_backend_const_v, TypePosition,
28+
camel_case_ident, is_structural, is_type_unstable, read_dir, setter_throws,
29+
shouty_snake_case_ident, snake_case_ident, throws, webidl_const_v_to_backend_const_v,
30+
TypePosition,
3031
};
3132
use anyhow::Context;
3233
use anyhow::Result;
@@ -625,6 +626,7 @@ impl<'src> FirstPassRecord<'src> {
625626
let structural = is_structural(attrs.as_ref(), container_attrs);
626627

627628
let catch = throws(attrs);
629+
let setter_catch = setter_throws(attrs);
628630

629631
let ty = type_
630632
.type_
@@ -659,7 +661,7 @@ impl<'src> FirstPassRecord<'src> {
659661
attributes.push(InterfaceAttribute {
660662
is_static,
661663
structural,
662-
catch,
664+
catch: catch || setter_catch,
663665
ty,
664666
js_name,
665667
kind,

crates/webidl/src/util.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ pub fn throws(attrs: &Option<ExtendedAttributeList>) -> bool {
611611
has_named_attribute(attrs.as_ref(), "Throws")
612612
}
613613

614+
/// Whether a webidl attribute is marked as throwing when setting.
615+
pub fn setter_throws(attrs: &Option<ExtendedAttributeList>) -> bool {
616+
has_named_attribute(attrs.as_ref(), "SetterThrows")
617+
}
618+
614619
fn flag_slices_immutable(ty: &mut IdlType) {
615620
match ty {
616621
IdlType::Int8Array { immutable }

0 commit comments

Comments
 (0)