diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 089d3199058..49e6e770635 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1150,7 +1150,7 @@ impl ElementMethods for Element { // https://dom.spec.whatwg.org/#dom-element-getattribute fn GetAttribute(&self, name: DOMString) -> Option { - self.get_attribute_by_name(name) + self.GetAttributeNode(name) .map(|s| s.r().Value()) } @@ -1158,9 +1158,21 @@ impl ElementMethods for Element { fn GetAttributeNS(&self, namespace: Option, local_name: DOMString) -> Option { + self.GetAttributeNodeNS(namespace, local_name) + .map(|attr| attr.r().Value()) + } + + // https://dom.spec.whatwg.org/#dom-element-getattributenode + fn GetAttributeNode(&self, name: DOMString) -> Option> { + self.get_attribute_by_name(name) + } + + // https://dom.spec.whatwg.org/#dom-element-getattributenodens + fn GetAttributeNodeNS(&self, + namespace: Option, + local_name: DOMString) -> Option> { let namespace = &namespace_from_domstring(namespace); self.get_attribute(namespace, &Atom::from_slice(&local_name)) - .map(|attr| attr.r().Value()) } // https://dom.spec.whatwg.org/#dom-element-setattribute diff --git a/components/script/dom/webidls/Element.webidl b/components/script/dom/webidls/Element.webidl index dde5b978890..b5b35f8e802 100644 --- a/components/script/dom/webidls/Element.webidl +++ b/components/script/dom/webidls/Element.webidl @@ -37,6 +37,10 @@ interface Element : Node { DOMString? getAttribute(DOMString name); [Pure] DOMString? getAttributeNS(DOMString? namespace, DOMString localName); + [Pure] + Attr? getAttributeNode(DOMString name); + [Pure] + Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName); [Throws] void setAttribute(DOMString name, DOMString value); [Throws] diff --git a/tests/wpt/metadata/dom/interfaces.html.ini b/tests/wpt/metadata/dom/interfaces.html.ini index 88e87cf563d..156dc6787dd 100644 --- a/tests/wpt/metadata/dom/interfaces.html.ini +++ b/tests/wpt/metadata/dom/interfaces.html.ini @@ -150,12 +150,6 @@ [Element interface: operation hasAttributes()] expected: FAIL - [Element interface: operation getAttributeNode(DOMString)] - expected: FAIL - - [Element interface: operation getAttributeNodeNS(DOMString,DOMString)] - expected: FAIL - [Element interface: operation setAttributeNode(Attr)] expected: FAIL @@ -174,18 +168,6 @@ [Element interface: element must inherit property "hasAttributes" with the proper type (7)] expected: FAIL - [Element interface: element must inherit property "getAttributeNode" with the proper type (17)] - expected: FAIL - - [Element interface: calling getAttributeNode(DOMString) on element with too few arguments must throw TypeError] - expected: FAIL - - [Element interface: element must inherit property "getAttributeNodeNS" with the proper type (18)] - expected: FAIL - - [Element interface: calling getAttributeNodeNS(DOMString,DOMString) on element with too few arguments must throw TypeError] - expected: FAIL - [Element interface: element must inherit property "setAttributeNode" with the proper type (19)] expected: FAIL diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index ecb19827604..8308aad5885 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -2064,18 +2064,6 @@ [Element interface: document.createElement("noscript") must inherit property "hasAttributes" with the proper type (7)] expected: FAIL - [Element interface: document.createElement("noscript") must inherit property "getAttributeNode" with the proper type (17)] - expected: FAIL - - [Element interface: calling getAttributeNode(DOMString) on document.createElement("noscript") with too few arguments must throw TypeError] - expected: FAIL - - [Element interface: document.createElement("noscript") must inherit property "getAttributeNodeNS" with the proper type (18)] - expected: FAIL - - [Element interface: calling getAttributeNodeNS(DOMString,DOMString) on document.createElement("noscript") with too few arguments must throw TypeError] - expected: FAIL - [Element interface: document.createElement("noscript") must inherit property "setAttributeNode" with the proper type (19)] expected: FAIL