From 8cf9da4981936cdaee98f899d8a77aa2003188ff Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 17 Sep 2018 14:10:23 -0700 Subject: [PATCH] Translate the `Global` attribute to "structural" All APIs on `Windows` are tagged where `Window` has `[Global]`, and they all need to be structurally accessed rather than through a prototype. --- crates/webidl/src/util.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/webidl/src/util.rs b/crates/webidl/src/util.rs index 0c453be6..7ed04a2d 100644 --- a/crates/webidl/src/util.rs +++ b/crates/webidl/src/util.rs @@ -630,6 +630,18 @@ fn has_named_attribute(list: Option<&ExtendedAttributeList>, attribute: &str) -> }) } +fn has_ident_attribute(list: Option<&ExtendedAttributeList>, ident: &str) -> bool { + let list = match list { + Some(list) => list, + None => return false, + }; + list.body.list.iter().any(|attr| match attr { + ExtendedAttribute::Ident(id) => id.lhs_identifier.0 == ident, + ExtendedAttribute::IdentList(id) => id.identifier.0 == ident, + _ => false, + }) +} + /// ChromeOnly is for things that are only exposed to privileged code in Firefox. pub fn is_chrome_only(ext_attrs: &Option) -> bool { has_named_attribute(ext_attrs.as_ref(), "ChromeOnly") @@ -646,7 +658,8 @@ pub fn is_structural( container_attrs: Option<&ExtendedAttributeList>, ) -> bool { has_named_attribute(item_attrs, "Unforgeable") || - has_named_attribute(container_attrs, "Unforgeable") + has_named_attribute(container_attrs, "Unforgeable") || + has_ident_attribute(container_attrs, "Global") } /// Whether a webidl object is marked as throwing.