diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-04-06 12:36:09 -0500 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-04-06 12:36:09 -0500 |
commit | 8d1a6c45f656de67115e72cc927f81c2d72e03a2 (patch) | |
tree | 41562761fa72d83aac589e503efb43008b8ed578 | |
parent | 576593089227266e53ac169b04b3d223979458cc (diff) | |
parent | 561ec7e21dba9878d7621b80c2b082d370b376c1 (diff) | |
download | servo-8d1a6c45f656de67115e72cc927f81c2d72e03a2.tar.gz servo-8d1a6c45f656de67115e72cc927f81c2d72e03a2.zip |
Auto merge of #5503 - nox:cleanup-attributes, r=Manishearth
This makes all tests in attributes.html pass.
18 files changed, 138 insertions, 156 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 3c174a993c6..cdc472d6e3f 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -250,15 +250,15 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> { /// Sets the owner element. Should be called after the attribute is added /// or removed from its older parent. fn set_owner(self, owner: Option<JSRef<Element>>) { - let ns = self.namespace.clone(); + let ref ns = self.namespace; match (self.owner().root().r(), owner) { (None, Some(new)) => { // Already in the list of attributes of new owner. - assert!(new.get_attribute(ns, &self.local_name).root().r() == Some(self)) + assert!(new.get_attribute(&ns, &self.local_name).root().r() == Some(self)) } (Some(old), None) => { // Already gone from the list of attributes of old owner. - assert!(old.get_attribute(ns, &self.local_name).is_none()) + assert!(old.get_attribute(&ns, &self.local_name).is_none()) } (old, new) => assert!(old == new) } diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 64080fbdfce..7faca76b6c6 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -653,7 +653,7 @@ pub fn xml_name_type(name: &str) -> XMLName { let mut iter = name.chars(); let mut non_qname_colons = false; let mut seen_colon = false; - match iter.next() { + let mut last = match iter.next() { None => return XMLName::InvalidXMLName, Some(c) => { if !is_valid_start(c) { @@ -662,10 +662,11 @@ pub fn xml_name_type(name: &str) -> XMLName { if c == ':' { non_qname_colons = true; } + c } - } + }; - for c in name.chars() { + for c in iter { if !is_valid_continuation(c) { return XMLName::InvalidXMLName; } @@ -675,6 +676,11 @@ pub fn xml_name_type(name: &str) -> XMLName { false => seen_colon = true } } + last = c + } + + if last == ':' { + non_qname_colons = true } match non_qname_colons { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 49eaef294d5..dcf96d66399 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -369,7 +369,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { self.GetElementById(fragid.clone()).or_else(|| { let check_anchor = |&node: &JSRef<HTMLAnchorElement>| { let elem: JSRef<Element> = ElementCast::from_ref(node); - elem.get_attribute(ns!(""), &atom!("name")).root().map_or(false, |attr| { + elem.get_attribute(&ns!(""), &atom!("name")).root().map_or(false, |attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); @@ -1280,7 +1280,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { Some(element) => element, None => return false, }; - element.get_attribute(ns!(""), &atom!("name")).root().map_or(false, |attr| { + element.get_attribute(&ns!(""), &atom!("name")).root().map_or(false, |attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index 7d28c067acc..508322da0ed 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -50,7 +50,7 @@ trait PrivateDOMTokenListHelpers { impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> { fn attribute(self) -> Option<Temporary<Attr>> { let element = self.element.root(); - element.r().get_attribute(ns!(""), &self.local_name) + element.r().get_attribute(&ns!(""), &self.local_name) } fn check_token_exceptions(self, token: &str) -> Fallible<Atom> { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 14c4c81113e..f27384c8028 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -608,8 +608,11 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { pub trait AttributeHandlers { /// Returns the attribute with given namespace and case-sensitive local /// name, if any. - fn get_attribute(self, namespace: Namespace, local_name: &Atom) + fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Temporary<Attr>>; + /// Returns the first attribute with any namespace and given case-sensitive + /// name, if any. + fn get_attribute_by_name(self, name: &Atom) -> Option<Temporary<Attr>>; fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>>; fn set_attribute_from_parser(self, @@ -625,32 +628,48 @@ pub trait AttributeHandlers { fn parse_attribute(self, namespace: &Namespace, local_name: &Atom, value: DOMString) -> AttrValue; - fn remove_attribute(self, namespace: Namespace, name: &str); + /// Removes the first attribute with any given namespace and case-sensitive local + /// name, if any. + fn remove_attribute(self, namespace: &Namespace, local_name: &Atom); + /// Removes the first attribute with any namespace and given case-sensitive name. + fn remove_attribute_by_name(self, name: &Atom); + /// Removes the first attribute that satisfies `find`. + fn do_remove_attribute<F>(self, find: F) where F: Fn(JSRef<Attr>) -> bool; + fn has_class(self, name: &Atom) -> bool; - fn set_atomic_attribute(self, name: &Atom, value: DOMString); + fn set_atomic_attribute(self, local_name: &Atom, value: DOMString); // http://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes - fn has_attribute(self, name: &Atom) -> bool; - fn set_bool_attribute(self, name: &Atom, value: bool); - fn get_url_attribute(self, name: &Atom) -> DOMString; - fn set_url_attribute(self, name: &Atom, value: DOMString); - fn get_string_attribute(self, name: &Atom) -> DOMString; - fn set_string_attribute(self, name: &Atom, value: DOMString); - fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom>; - fn set_tokenlist_attribute(self, name: &Atom, value: DOMString); - fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>); - fn get_uint_attribute(self, name: &Atom) -> u32; - fn set_uint_attribute(self, name: &Atom, value: u32); + fn has_attribute(self, local_name: &Atom) -> bool; + fn set_bool_attribute(self, local_name: &Atom, value: bool); + fn get_url_attribute(self, local_name: &Atom) -> DOMString; + fn set_url_attribute(self, local_name: &Atom, value: DOMString); + fn get_string_attribute(self, local_name: &Atom) -> DOMString; + fn set_string_attribute(self, local_name: &Atom, value: DOMString); + fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec<Atom>; + fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString); + fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec<Atom>); + fn get_uint_attribute(self, local_name: &Atom) -> u32; + fn set_uint_attribute(self, local_name: &Atom, value: u32); } impl<'a> AttributeHandlers for JSRef<'a, Element> { - fn get_attribute(self, namespace: Namespace, local_name: &Atom) -> Option<Temporary<Attr>> { + fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Temporary<Attr>> { self.get_attributes(local_name).into_iter().map(|attr| attr.root()) - .find(|attr| *attr.r().namespace() == namespace) + .find(|attr| attr.r().namespace() == namespace) .map(|x| Temporary::from_rooted(x.r())) } + fn get_attribute_by_name(self, name: &Atom) -> Option<Temporary<Attr>> { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attrs = self.attrs.borrow(); + attrs.iter().map(|attr| attr.root()) + .find(|a| a.r().name() == name) + .map(|x| Temporary::from_rooted(x.r())) + } + + // https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attrs = self.attrs.borrow(); @@ -748,17 +767,24 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } } - fn remove_attribute(self, namespace: Namespace, name: &str) { - let (_, local_name) = get_attribute_parts(name); - let local_name = Atom::from_slice(local_name); - - let idx = self.attrs.borrow().iter().map(|attr| attr.root()).position(|attr| { - *attr.r().local_name() == local_name + fn remove_attribute(self, namespace: &Namespace, local_name: &Atom) { + self.do_remove_attribute(|attr| { + attr.namespace() == namespace && attr.local_name() == local_name }); + } + + fn remove_attribute_by_name(self, name: &Atom) { + self.do_remove_attribute(|attr| attr.name() == name); + } + + fn do_remove_attribute<F>(self, find: F) where F: Fn(JSRef<Attr>) -> bool { + let idx = self.attrs.borrow().iter() + .map(|attr| attr.root()) + .position(|attr| find(attr.r())); if let Some(idx) = idx { let attr = (*self.attrs.borrow())[idx].root(); - if namespace == ns!("") { + if attr.r().namespace() == &ns!("") { vtable_for(&NodeCast::from_ref(self)).before_remove_attr(attr.r()); } @@ -768,7 +794,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { let node: JSRef<Node> = NodeCast::from_ref(self); if node.is_in_doc() { let document = document_from_node(self).root(); - let damage = if local_name == atom!("style") { + let damage = if attr.r().local_name() == &atom!("style") { NodeDamage::NodeStyleDamaged } else { NodeDamage::OtherNodeDamage @@ -788,7 +814,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { NoQuirks | LimitedQuirks => lhs == rhs, Quirks => lhs.eq_ignore_ascii_case(&rhs) }; - self.get_attribute(ns!(""), &atom!("class")).root().map(|attr| { + self.get_attribute(&ns!(""), &atom!("class")).root().map(|attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); @@ -798,40 +824,38 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { }).unwrap_or(false) } - fn set_atomic_attribute(self, name: &Atom, value: DOMString) { - assert!(name.as_slice() == name.to_ascii_lowercase()); + fn set_atomic_attribute(self, local_name: &Atom, value: DOMString) { + assert!(local_name.as_slice() == local_name.to_ascii_lowercase()); let value = AttrValue::from_atomic(value); - self.set_attribute(name, value); + self.set_attribute(local_name, value); } - fn has_attribute(self, name: &Atom) -> bool { - assert!(name.bytes().all(|b| b.to_ascii_lowercase() == b)); + fn has_attribute(self, local_name: &Atom) -> bool { + assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b)); // FIXME(https://github.com/rust-lang/rust/issues/23338) let attrs = self.attrs.borrow(); attrs.iter().map(|attr| attr.root()).any(|attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); - let local_name = attr.local_name(); - let namespace = attr.namespace(); - *local_name == *name && *namespace == ns!("") + attr.local_name() == local_name && attr.namespace() == &ns!("") }) } - fn set_bool_attribute(self, name: &Atom, value: bool) { - if self.has_attribute(name) == value { return; } + fn set_bool_attribute(self, local_name: &Atom, value: bool) { + if self.has_attribute(local_name) == value { return; } if value { - self.set_string_attribute(name, String::new()); + self.set_string_attribute(local_name, String::new()); } else { - self.remove_attribute(ns!(""), &name); + self.remove_attribute(&ns!(""), local_name); } } - fn get_url_attribute(self, name: &Atom) -> DOMString { - assert!(name.as_slice() == name.to_ascii_lowercase()); - if !self.has_attribute(name) { + fn get_url_attribute(self, local_name: &Atom) -> DOMString { + assert!(local_name.as_slice() == local_name.to_ascii_lowercase()); + if !self.has_attribute(local_name) { return "".to_owned(); } - let url = self.get_string_attribute(name); + let url = self.get_string_attribute(local_name); let doc = document_from_node(self).root(); let base = doc.r().url(); // https://html.spec.whatwg.org/multipage/infrastructure.html#reflect @@ -841,23 +865,23 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { Err(_) => "".to_owned() } } - fn set_url_attribute(self, name: &Atom, value: DOMString) { - self.set_string_attribute(name, value); + fn set_url_attribute(self, local_name: &Atom, value: DOMString) { + self.set_string_attribute(local_name, value); } - fn get_string_attribute(self, name: &Atom) -> DOMString { - match self.get_attribute(ns!(""), name) { + fn get_string_attribute(self, local_name: &Atom) -> DOMString { + match self.get_attribute(&ns!(""), local_name) { Some(x) => x.root().r().Value(), None => "".to_owned() } } - fn set_string_attribute(self, name: &Atom, value: DOMString) { - assert!(name.as_slice() == name.to_ascii_lowercase()); - self.set_attribute(name, AttrValue::String(value)); + fn set_string_attribute(self, local_name: &Atom, value: DOMString) { + assert!(local_name.as_slice() == local_name.to_ascii_lowercase()); + self.set_attribute(local_name, AttrValue::String(value)); } - fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom> { - self.get_attribute(ns!(""), name).root().map(|attr| { + fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec<Atom> { + self.get_attribute(&ns!(""), local_name).root().map(|attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); @@ -867,21 +891,21 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { }).unwrap_or(vec!()) } - fn set_tokenlist_attribute(self, name: &Atom, value: DOMString) { - assert!(name.as_slice() == name.to_ascii_lowercase()); - self.set_attribute(name, AttrValue::from_serialized_tokenlist(value)); + fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString) { + assert!(local_name.as_slice() == local_name.to_ascii_lowercase()); + self.set_attribute(local_name, AttrValue::from_serialized_tokenlist(value)); } - fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>) { - assert!(name.as_slice() == name.to_ascii_lowercase()); - self.set_attribute(name, AttrValue::from_atomic_tokens(tokens)); + fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec<Atom>) { + assert!(local_name.as_slice() == local_name.to_ascii_lowercase()); + self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens)); } - fn get_uint_attribute(self, name: &Atom) -> u32 { - assert!(name.chars().all(|ch| { + fn get_uint_attribute(self, local_name: &Atom) -> u32 { + assert!(local_name.chars().all(|ch| { !ch.is_ascii() || ch.to_ascii_lowercase() == ch })); - let attribute = self.get_attribute(ns!(""), name).root(); + let attribute = self.get_attribute(&ns!(""), local_name).root(); match attribute { Some(attribute) => { match *attribute.r().value() { @@ -893,9 +917,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { None => 0, } } - fn set_uint_attribute(self, name: &Atom, value: u32) { - assert!(name.as_slice() == name.to_ascii_lowercase()); - self.set_attribute(name, AttrValue::UInt(value.to_string(), value)); + fn set_uint_attribute(self, local_name: &Atom, value: u32) { + assert!(local_name.as_slice() == local_name.to_ascii_lowercase()); + self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value)); } } @@ -974,7 +998,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-getattribute fn GetAttribute(self, name: DOMString) -> Option<DOMString> { let name = self.parsed_name(name); - self.get_attribute(ns!(""), &Atom::from_slice(&name)).root() + self.get_attribute_by_name(&Atom::from_slice(&name)).root() .map(|s| s.r().Value()) } @@ -982,7 +1006,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { fn GetAttributeNS(self, namespace: Option<DOMString>, local_name: DOMString) -> Option<DOMString> { - let namespace = namespace::from_domstring(namespace); + let namespace = &namespace::from_domstring(namespace); self.get_attribute(namespace, &Atom::from_slice(&local_name)).root() .map(|attr| attr.r().Value()) } @@ -1072,16 +1096,17 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-removeattribute fn RemoveAttribute(self, name: DOMString) { - let name = self.parsed_name(name); - self.remove_attribute(ns!(""), &name) + let name = Atom::from_slice(&self.parsed_name(name)); + self.remove_attribute_by_name(&name); } // http://dom.spec.whatwg.org/#dom-element-removeattributens fn RemoveAttributeNS(self, namespace: Option<DOMString>, - localname: DOMString) { + local_name: DOMString) { let namespace = namespace::from_domstring(namespace); - self.remove_attribute(namespace, &localname) + let local_name = Atom::from_slice(&local_name); + self.remove_attribute(&namespace, &local_name); } // http://dom.spec.whatwg.org/#dom-element-hasattribute @@ -1379,7 +1404,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { if !tree_in_doc { return; } - if let Some(attr) = self.get_attribute(ns!(""), &atom!("id")).root() { + if let Some(attr) = self.get_attribute(&ns!(""), &atom!("id")).root() { let doc = document_from_node(*self).root(); let value = attr.r().Value(); if !value.is_empty() { @@ -1396,7 +1421,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { if !tree_in_doc { return; } - if let Some(attr) = self.get_attribute(ns!(""), &atom!("id")).root() { + if let Some(attr) = self.get_attribute(&ns!(""), &atom!("id")).root() { let doc = document_from_node(*self).root(); let value = attr.r().Value(); if !value.is_empty() { @@ -1409,8 +1434,8 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { #[allow(unsafe_code)] - fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str> { - self.get_attribute(namespace.clone(), attr).root().map(|attr| { + fn get_attr(self, namespace: &Namespace, local_name: &Atom) -> Option<&'a str> { + self.get_attribute(namespace, local_name).root().map(|attr| { // This transmute is used to cheat the lifetime restriction. // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); @@ -1419,8 +1444,8 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { }) } #[allow(unsafe_code)] - fn get_attrs(self, attr: &Atom) -> Vec<&'a str> { - self.get_attributes(attr).into_iter().map(|attr| attr.root()).map(|attr| { + fn get_attrs(self, local_name: &Atom) -> Vec<&'a str> { + self.get_attributes(local_name).into_iter().map(|attr| attr.root()).map(|attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); @@ -1470,7 +1495,7 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { node.get_focus_state() } fn get_id(self) -> Option<Atom> { - self.get_attribute(ns!(""), &atom!("id")).map(|attr| { + self.get_attribute(&ns!(""), &atom!("id")).map(|attr| { let attr = attr.root(); // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); @@ -1515,7 +1540,7 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { fn each_class<F>(self, mut callback: F) where F: FnMut(&Atom) { - if let Some(ref attr) = self.get_attribute(ns!(""), &atom!("class")).root() { + if let Some(ref attr) = self.get_attribute(&ns!(""), &atom!("class")).root() { if let Some(tokens) = attr.r().value().tokens() { for token in tokens { callback(token) diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index 0856aae3c80..1219692cd9b 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -122,7 +122,7 @@ impl<'a> Activatable for JSRef<'a, HTMLAnchorElement> { //TODO: Step 3. Handle <img ismap/>. //TODO: Step 4. Download the link is `download` attribute is set. let element: JSRef<Element> = ElementCast::from_ref(*self); - let attr = element.get_attribute(ns!(""), &atom!("href")).root(); + let attr = element.get_attribute(&ns!(""), &atom!("href")).root(); match attr { Some(ref href) => { let value = href.r().Value(); diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 55c0fc6fcec..4bae413b213 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -194,9 +194,10 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> { element.set_custom_attribute(to_snake_case(name), value) } - fn get_custom_attr(self, name: DOMString) -> Option<DOMString> { + fn get_custom_attr(self, local_name: DOMString) -> Option<DOMString> { let element: JSRef<Element> = ElementCast::from_ref(self); - element.get_attribute(ns!(""), &Atom::from_slice(&to_snake_case(name))).map(|attr| { + let local_name = Atom::from_slice(&to_snake_case(local_name)); + element.get_attribute(&ns!(""), &local_name).map(|attr| { let attr = attr.root(); // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); @@ -205,9 +206,10 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> { }) } - fn delete_custom_attr(self, name: DOMString) { + fn delete_custom_attr(self, local_name: DOMString) { let element: JSRef<Element> = ElementCast::from_ref(self); - element.remove_attribute(ns!(""), &to_snake_case(name)) + let local_name = Atom::from_slice(&to_snake_case(local_name)); + element.remove_attribute(&ns!(""), &local_name); } } diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 1c5e9ec2349..cbb6ee436a3 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -83,7 +83,7 @@ impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> { fn get_url(self) -> Option<Url> { let element: JSRef<Element> = ElementCast::from_ref(self); - element.get_attribute(ns!(""), &atom!("src")).root().and_then(|src| { + element.get_attribute(&ns!(""), &atom!("src")).root().and_then(|src| { let url = src.r().value(); if url.as_slice().is_empty() { None diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index e4ebabb9e13..9223ac7ad60 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -391,7 +391,7 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { fn get_radio_group_name(self) -> Option<String> { //TODO: determine form owner let elem: JSRef<Element> = ElementCast::from_ref(self); - elem.get_attribute(ns!(""), &atom!("name")) + elem.get_attribute(&ns!(""), &atom!("name")) .root() .map(|name| name.r().Value()) } diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 8014a7af4af..82d8c33f919 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -57,8 +57,8 @@ impl HTMLLinkElement { } } -fn get_attr(element: JSRef<Element>, name: &Atom) -> Option<String> { - let elem = element.get_attribute(ns!(""), name).root(); +fn get_attr(element: JSRef<Element>, local_name: &Atom) -> Option<String> { + let elem = element.get_attribute(&ns!(""), local_name).root(); elem.map(|e| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let e = e.r(); diff --git a/components/script/dom/htmlobjectelement.rs b/components/script/dom/htmlobjectelement.rs index 88bf53a1365..ae730c102ac 100644 --- a/components/script/dom/htmlobjectelement.rs +++ b/components/script/dom/htmlobjectelement.rs @@ -62,8 +62,8 @@ impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> { let elem: JSRef<Element> = ElementCast::from_ref(*self); // TODO: support other values - match (elem.get_attribute(ns!(""), &atom!("type")).map(|x| x.root().r().Value()), - elem.get_attribute(ns!(""), &atom!("data")).map(|x| x.root().r().Value())) { + match (elem.get_attribute(&ns!(""), &atom!("type")).map(|x| x.root().r().Value()), + elem.get_attribute(&ns!(""), &atom!("data")).map(|x| x.root().r().Value())) { (None, Some(uri)) => { if is_image_data(uri.as_slice()) { let data_url = Url::parse(uri.as_slice()).unwrap(); diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 5357c146ae5..7b4f7a8aea0 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -202,8 +202,8 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { } // Step 12. - let for_attribute = element.get_attribute(ns!(""), &atom!("for")).root(); - let event_attribute = element.get_attribute(ns!(""), &Atom::from_slice("event")).root(); + let for_attribute = element.get_attribute(&ns!(""), &atom!("for")).root(); + let event_attribute = element.get_attribute(&ns!(""), &Atom::from_slice("event")).root(); match (for_attribute.r(), event_attribute.r()) { (Some(for_attribute), Some(event_attribute)) => { let for_value = for_attribute.Value() @@ -223,7 +223,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { } // Step 13. - if let Some(charset) = element.get_attribute(ns!(""), &Atom::from_slice("charset")).root() { + if let Some(charset) = element.get_attribute(&ns!(""), &Atom::from_slice("charset")).root() { if let Some(encodingRef) = encoding_from_whatwg_label(&charset.r().Value()) { *self.block_character_encoding.borrow_mut() = encodingRef; } @@ -234,7 +234,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { let window = window.r(); let base_url = window.get_url(); - let load = match element.get_attribute(ns!(""), &atom!("src")).root() { + let load = match element.get_attribute(&ns!(""), &atom!("src")).root() { // Step 14. Some(src) => { // Step 14.1 @@ -406,7 +406,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { fn is_javascript(self) -> bool { let element: JSRef<Element> = ElementCast::from_ref(self); - match element.get_attribute(ns!(""), &atom!("type")).root().map(|s| s.r().Value()) { + match element.get_attribute(&ns!(""), &atom!("type")).root().map(|s| s.r().Value()) { Some(ref s) if s.is_empty() => { // type attr exists, but empty means js debug!("script type empty, inferring js"); @@ -418,7 +418,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { }, None => { debug!("no script type"); - match element.get_attribute(ns!(""), &atom!("language")) + match element.get_attribute(&ns!(""), &atom!("language")) .root() .map(|s| s.r().Value()) { Some(ref s) if s.is_empty() => { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index f9b81cad136..6d69e4cf7e5 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2334,7 +2334,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> { fn match_attr<F>(self, attr: &AttrSelector, test: F) -> bool where F: Fn(&str) -> bool { - let name = { + let local_name = { if self.is_html_element_in_html_document() { &attr.lower_name } else { @@ -2343,7 +2343,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> { }; match attr.namespace { NamespaceConstraint::Specific(ref ns) => { - self.as_element().get_attribute(ns.clone(), name).root() + self.as_element().get_attribute(ns, local_name).root() .map_or(false, |attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); @@ -2352,7 +2352,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> { }) }, NamespaceConstraint::Any => { - self.as_element().get_attributes(name).into_iter() + self.as_element().get_attributes(local_name).into_iter() .map(|attr| attr.root()) .any(|attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) diff --git a/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocument.html.ini b/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocument.html.ini index 2c72acd4796..8d02570c391 100644 --- a/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocument.html.ini +++ b/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocument.html.ini @@ -6,27 +6,18 @@ [createDocument test 41: undefined,"xmlns",null,"NAMESPACE_ERR"] expected: FAIL - [createDocument test 52: "http://example.com/","foo:",null,"NAMESPACE_ERR"] - expected: FAIL - [createDocument test 64: "http://example.com/","xmlns",null,"NAMESPACE_ERR"] expected: FAIL [createDocument test 69: "http://example.com/","xmlns:foo",null,"NAMESPACE_ERR"] expected: FAIL - [createDocument test 106: "/","foo:",null,"NAMESPACE_ERR"] - expected: FAIL - [createDocument test 108: "/","xmlns",null,"NAMESPACE_ERR"] expected: FAIL [createDocument test 111: "/","xmlns:foo",null,"NAMESPACE_ERR"] expected: FAIL - [createDocument test 119: "http://www.w3.org/XML/1998/namespace","foo:",null,"NAMESPACE_ERR"] - expected: FAIL - [createDocument test 121: "http://www.w3.org/XML/1998/namespace","xmlns",null,"NAMESPACE_ERR"] expected: FAIL @@ -36,9 +27,6 @@ [createDocument test 141: "http://www.w3.org/2000/xmlns/","foo:xmlns",null,"NAMESPACE_ERR"] expected: FAIL - [createDocument test 148: "foo:","foo:",null,"NAMESPACE_ERR"] - expected: FAIL - [createDocument test 150: "foo:","xmlns",null,"NAMESPACE_ERR"] expected: FAIL diff --git a/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocumentType.html.ini b/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocumentType.html.ini deleted file mode 100644 index f12bf008449..00000000000 --- a/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocumentType.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[DOMImplementation-createDocumentType.html] - type: testharness - [createDocumentType("foo:", "", "") should throw NAMESPACE_ERR] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Document-createElementNS.html.ini b/tests/wpt/metadata/dom/nodes/Document-createElementNS.html.ini index b09e14e9d2b..69ab187bf8d 100644 --- a/tests/wpt/metadata/dom/nodes/Document-createElementNS.html.ini +++ b/tests/wpt/metadata/dom/nodes/Document-createElementNS.html.ini @@ -6,27 +6,18 @@ [createElementNS test 41: undefined,"xmlns","NAMESPACE_ERR"] expected: FAIL - [createElementNS test 52: "http://example.com/","foo:","NAMESPACE_ERR"] - expected: FAIL - [createElementNS test 64: "http://example.com/","xmlns","NAMESPACE_ERR"] expected: FAIL [createElementNS test 69: "http://example.com/","xmlns:foo","NAMESPACE_ERR"] expected: FAIL - [createElementNS test 106: "/","foo:","NAMESPACE_ERR"] - expected: FAIL - [createElementNS test 108: "/","xmlns","NAMESPACE_ERR"] expected: FAIL [createElementNS test 111: "/","xmlns:foo","NAMESPACE_ERR"] expected: FAIL - [createElementNS test 119: "http://www.w3.org/XML/1998/namespace","foo:","NAMESPACE_ERR"] - expected: FAIL - [createElementNS test 121: "http://www.w3.org/XML/1998/namespace","xmlns","NAMESPACE_ERR"] expected: FAIL @@ -36,9 +27,6 @@ [createElementNS test 141: "http://www.w3.org/2000/xmlns/","foo:xmlns","NAMESPACE_ERR"] expected: FAIL - [createElementNS test 148: "foo:","foo:","NAMESPACE_ERR"] - expected: FAIL - [createElementNS test 150: "foo:","xmlns","NAMESPACE_ERR"] expected: FAIL diff --git a/tests/wpt/metadata/dom/nodes/Element-removeAttributeNS.html.ini b/tests/wpt/metadata/dom/nodes/Element-removeAttributeNS.html.ini deleted file mode 100644 index ed13e73097b..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-removeAttributeNS.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-removeAttributeNS.html] - type: testharness - [removeAttributeNS should take a local name.] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/attributes.html.ini b/tests/wpt/metadata/dom/nodes/attributes.html.ini deleted file mode 100644 index f3e1c5bcdf8..00000000000 --- a/tests/wpt/metadata/dom/nodes/attributes.html.ini +++ /dev/null @@ -1,17 +0,0 @@ -[attributes.html] - type: testharness - [setAttribute should set the attribute with the given qualified name] - expected: FAIL - - [When qualifiedName does not match the QName production, an NAMESPACE_ERR exception is to be thrown.] - expected: FAIL - - [First set attribute is returned by getAttribute] - expected: FAIL - - [First set attribute is returned with mapped attribute set later] - expected: FAIL - - [Attribute with prefix in local name] - expected: FAIL - |