From d28c9a1588e88db3c38da4b2866ea4a4a6363972 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Sat, 28 Nov 2015 16:27:51 -0800 Subject: [PATCH] Implement removeAttributeNode This commit implement removeAttributeNode, as described here: https://dom.spec.whatwg.org/#dom-element-removeattributenode See also #8724 and #8068. --- components/script/dom/element.rs | 6 ++++++ components/script/dom/webidls/Element.webidl | 2 ++ tests/wpt/metadata/dom/interfaces.html.ini | 9 --------- tests/wpt/metadata/dom/nodes/attributes.html.ini | 3 --- tests/wpt/metadata/html/dom/interfaces.html.ini | 6 ------ 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 3ddf6b4f769e..2949c1d2cca6 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1358,6 +1358,12 @@ impl ElementMethods for Element { self.remove_attribute(&namespace, &local_name); } + // https://dom.spec.whatwg.org/#dom-element-removeattributenode + fn RemoveAttributeNode(&self, attr: &Attr) -> Fallible> { + self.remove_first_matching_attribute(|a| a == attr) + .ok_or(Error::NotFound) + } + // https://dom.spec.whatwg.org/#dom-element-hasattribute fn HasAttribute(&self, name: DOMString) -> bool { self.GetAttribute(name).is_some() diff --git a/components/script/dom/webidls/Element.webidl b/components/script/dom/webidls/Element.webidl index 21c9f8234f0c..009fb9998565 100644 --- a/components/script/dom/webidls/Element.webidl +++ b/components/script/dom/webidls/Element.webidl @@ -49,6 +49,8 @@ interface Element : Node { void setAttributeNS(DOMString? namespace, DOMString name, DOMString value); void removeAttribute(DOMString name); void removeAttributeNS(DOMString? namespace, DOMString localName); + [Throws] + Attr removeAttributeNode(Attr oldAttr); boolean hasAttribute(DOMString name); boolean hasAttributeNS(DOMString? namespace, DOMString localName); diff --git a/tests/wpt/metadata/dom/interfaces.html.ini b/tests/wpt/metadata/dom/interfaces.html.ini index 65c1d82f2cfe..2d0458f453a4 100644 --- a/tests/wpt/metadata/dom/interfaces.html.ini +++ b/tests/wpt/metadata/dom/interfaces.html.ini @@ -108,9 +108,6 @@ [Element interface: operation hasAttributes()] expected: FAIL - [Element interface: operation removeAttributeNode(Attr)] - expected: FAIL - [Element interface: operation query(DOMString)] expected: FAIL @@ -120,12 +117,6 @@ [Element interface: element must inherit property "hasAttributes" with the proper type (7)] expected: FAIL - [Element interface: element must inherit property "removeAttributeNode" with the proper type (22)] - expected: FAIL - - [Element interface: calling removeAttributeNode(Attr) on element with too few arguments must throw TypeError] - expected: FAIL - [Element interface: element must inherit property "query" with the proper type (34)] expected: FAIL diff --git a/tests/wpt/metadata/dom/nodes/attributes.html.ini b/tests/wpt/metadata/dom/nodes/attributes.html.ini index 1531de6e1a8d..1f0e7d4973e7 100644 --- a/tests/wpt/metadata/dom/nodes/attributes.html.ini +++ b/tests/wpt/metadata/dom/nodes/attributes.html.ini @@ -1,8 +1,5 @@ [attributes.html] type: testharness - [Basic functionality of removeAttributeNode] - expected: FAIL - [Own property names should only include all-lowercase qualified names for an HTML element in an HTML document] expected: FAIL diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 7e7c9590db65..d4cd891b4d30 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -1986,12 +1986,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 "removeAttributeNode" with the proper type (22)] - expected: FAIL - - [Element interface: calling removeAttributeNode(Attr) on document.createElement("noscript") with too few arguments must throw TypeError] - expected: FAIL - [Element interface: document.createElement("noscript") must inherit property "query" with the proper type (34)] expected: FAIL