From ed42cc72a4ff5534a35198c0458ab3857879d078 Mon Sep 17 00:00:00 2001 From: Arnaud Marant Date: Wed, 20 Apr 2016 22:23:27 +0200 Subject: [PATCH] Implements Node::isSameNode Fixes #10746 Adapted the tests from dom/nodes/Node-isEqualNode.html --- components/script/dom/node.rs | 8 ++ components/script/dom/webidls/Node.webidl | 2 + tests/wpt/metadata/MANIFEST.json | 6 ++ tests/wpt/metadata/dom/interfaces.html.ini | 52 --------- .../dom/nodes/Node-isSameNode.html | 100 ++++++++++++++++++ 5 files changed, 116 insertions(+), 52 deletions(-) create mode 100644 tests/wpt/web-platform-tests/dom/nodes/Node-isSameNode.html diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 3cbe8024b9e..0f2209c00ea 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2230,6 +2230,14 @@ impl NodeMethods for Node { } } + // https://dom.spec.whatwg.org/#dom-node-issamenode + fn IsSameNode(&self, otherNode: Option<&Node>) -> bool { + match otherNode { + Some(node) => self == node, + None => false, + } + } + // https://dom.spec.whatwg.org/#dom-node-comparedocumentposition fn CompareDocumentPosition(&self, other: &Node) -> u16 { if self == other { diff --git a/components/script/dom/webidls/Node.webidl b/components/script/dom/webidls/Node.webidl index 0c3311cb647..f727fa98660 100644 --- a/components/script/dom/webidls/Node.webidl +++ b/components/script/dom/webidls/Node.webidl @@ -58,6 +58,8 @@ interface Node : EventTarget { Node cloneNode(optional boolean deep = false); [Pure] boolean isEqualNode(Node? node); + [Pure] + boolean isSameNode(Node? otherNode); // historical alias of === const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01; const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02; diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index bfb83729c78..533d663e71a 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -35235,6 +35235,12 @@ "path": "dom/nodes/Element-hasAttributes.html", "url": "/dom/nodes/Element-hasAttributes.html" } + ], + "dom/nodes/Node-isSameNode.html": [ + { + "path": "dom/nodes/Node-isSameNode.html", + "url": "/dom/nodes/Node-isSameNode.html" + } ] } }, diff --git a/tests/wpt/metadata/dom/interfaces.html.ini b/tests/wpt/metadata/dom/interfaces.html.ini index 68196d519d3..2569ebac143 100644 --- a/tests/wpt/metadata/dom/interfaces.html.ini +++ b/tests/wpt/metadata/dom/interfaces.html.ini @@ -186,45 +186,18 @@ [Node interface: attribute isConnected] expected: FAIL - [Node interface: operation isSameNode(Node)] - expected: FAIL - [Node interface: new Document() must inherit property "isConnected" with the proper type (15)] expected: FAIL - [Node interface: new Document() must inherit property "isSameNode" with the proper type (31)] - expected: FAIL - - [Node interface: calling isSameNode(Node) on new Document() with too few arguments must throw TypeError] - expected: FAIL - [Node interface: xmlDoc must inherit property "isConnected" with the proper type (15)] expected: FAIL - [Node interface: xmlDoc must inherit property "isSameNode" with the proper type (31)] - expected: FAIL - - [Node interface: calling isSameNode(Node) on xmlDoc with too few arguments must throw TypeError] - expected: FAIL - [Node interface: document.doctype must inherit property "isConnected" with the proper type (15)] expected: FAIL - [Node interface: document.doctype must inherit property "isSameNode" with the proper type (31)] - expected: FAIL - - [Node interface: calling isSameNode(Node) on document.doctype with too few arguments must throw TypeError] - expected: FAIL - [Node interface: document.createDocumentFragment() must inherit property "isConnected" with the proper type (15)] expected: FAIL - [Node interface: document.createDocumentFragment() must inherit property "isSameNode" with the proper type (31)] - expected: FAIL - - [Node interface: calling isSameNode(Node) on document.createDocumentFragment() with too few arguments must throw TypeError] - expected: FAIL - [ShadowRoot interface: existence and properties of interface object] expected: FAIL @@ -276,12 +249,6 @@ [Node interface: element must inherit property "isConnected" with the proper type (15)] expected: FAIL - [Node interface: element must inherit property "isSameNode" with the proper type (31)] - expected: FAIL - - [Node interface: calling isSameNode(Node) on element with too few arguments must throw TypeError] - expected: FAIL - [Text interface: attribute assignedSlot] expected: FAIL @@ -291,27 +258,8 @@ [Node interface: document.createTextNode("abc") must inherit property "isConnected" with the proper type (15)] expected: FAIL - [Node interface: document.createTextNode("abc") must inherit property "isSameNode" with the proper type (31)] - expected: FAIL - - [Node interface: calling isSameNode(Node) on document.createTextNode("abc") with too few arguments must throw TypeError] - expected: FAIL - [Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "isConnected" with the proper type (15)] expected: FAIL - [Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "isSameNode" with the proper type (31)] - expected: FAIL - - [Node interface: calling isSameNode(Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError] - expected: FAIL - [Node interface: document.createComment("abc") must inherit property "isConnected" with the proper type (15)] expected: FAIL - - [Node interface: document.createComment("abc") must inherit property "isSameNode" with the proper type (31)] - expected: FAIL - - [Node interface: calling isSameNode(Node) on document.createComment("abc") with too few arguments must throw TypeError] - expected: FAIL - diff --git a/tests/wpt/web-platform-tests/dom/nodes/Node-isSameNode.html b/tests/wpt/web-platform-tests/dom/nodes/Node-isSameNode.html new file mode 100644 index 00000000000..884fdd50490 --- /dev/null +++ b/tests/wpt/web-platform-tests/dom/nodes/Node-isSameNode.html @@ -0,0 +1,100 @@ + + +Node.prototype.isSameNode + + + +