diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 14c4c81113e..1a9c87542d8 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -610,6 +610,9 @@ pub trait AttributeHandlers { /// name, if any. fn get_attribute(self, namespace: Namespace, local_name: &Atom) -> Option>; + /// Returns the first attribute with any namespace and given case-sensitive + /// name, if any. + fn get_attribute_by_name(self, name: &Atom) -> Option>; fn get_attributes(self, local_name: &Atom) -> Vec>; fn set_attribute_from_parser(self, @@ -651,6 +654,15 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { .map(|x| Temporary::from_rooted(x.r())) } + fn get_attribute_by_name(self, name: &Atom) -> Option> { + // 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> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attrs = self.attrs.borrow(); @@ -974,7 +986,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-getattribute fn GetAttribute(self, name: DOMString) -> Option { 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()) } diff --git a/tests/wpt/metadata/dom/nodes/attributes.html.ini b/tests/wpt/metadata/dom/nodes/attributes.html.ini index f3e1c5bcdf8..27d1981425b 100644 --- a/tests/wpt/metadata/dom/nodes/attributes.html.ini +++ b/tests/wpt/metadata/dom/nodes/attributes.html.ini @@ -1,17 +1,8 @@ [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