Auto merge of #10761 - amarant:Node-isSameNode, r=Ms2ger

Implements Node::isSameNode

Fixes #10746

I adapted the tests from dom/nodes/Node-isEqualNode.html
should I also add ones for xhtml too like here : dom/nodes/Node-isEqualNode-xhtml.xhtml ?

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10761)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-25 01:04:47 -07:00
commit 4f05ea73fe
5 changed files with 116 additions and 52 deletions

View file

@ -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 {

View file

@ -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;

View file

@ -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"
}
]
}
},

View file

@ -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

View file

@ -0,0 +1,100 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Node.prototype.isSameNode</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-issamenode">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
test(function() {
var doctype1 = document.implementation.createDocumentType("qualifiedName", "publicId", "systemId");
var doctype2 = document.implementation.createDocumentType("qualifiedName", "publicId", "systemId");
assert_true(doctype1.isSameNode(doctype1), "self-comparison");
assert_false(doctype1.isSameNode(doctype2), "same properties");
assert_false(doctype1.isSameNode(null), "with null other node");
}, "doctypes should be comapred on reference");
test(function() {
var element1 = document.createElementNS("namespace", "prefix:localName");
var element2 = document.createElementNS("namespace", "prefix:localName");
assert_true(element1.isSameNode(element1), "self-comparison");
assert_false(element1.isSameNode(element2), "same properties");
assert_false(element1.isSameNode(null), "with null other node");
}, "elements should be compared on reference");
test(function() {
var element1 = document.createElement("element");
element1.setAttributeNS("namespace", "prefix:localName", "value");
var element2 = document.createElement("element");
element2.setAttributeNS("namespace", "prefix:localName", "value");
assert_true(element1.isSameNode(element1), "self-comparison");
assert_false(element1.isSameNode(element2), "same properties");
assert_false(element1.isSameNode(null), "with null other node");
}, "elements should be compared on reference");
test(function() {
var pi1 = document.createProcessingInstruction("target", "data");
var pi2 = document.createProcessingInstruction("target", "data");
assert_true(pi1.isSameNode(pi1), "self-comparison");
assert_false(pi1.isSameNode(pi2), "different target");
assert_false(pi1.isSameNode(null), "with null other node");
}, "processing instructions should be compared on reference");
test(function() {
var text1 = document.createTextNode("data");
var text2 = document.createTextNode("data");
assert_true(text1.isSameNode(text1), "self-comparison");
assert_false(text1.isSameNode(text2), "same properties");
assert_false(text1.isSameNode(null), "with null other node");
}, "text nodes should be compared on reference");
test(function() {
var comment1 = document.createComment("data");
var comment2 = document.createComment("data");
assert_true(comment1.isSameNode(comment1), "self-comparison");
assert_false(comment1.isSameNode(comment2), "same properties");
assert_false(comment1.isSameNode(null), "with null other node");
}, "comments should be compared on reference");
test(function() {
var documentFragment1 = document.createDocumentFragment();
var documentFragment2 = document.createDocumentFragment();
assert_true(documentFragment1.isSameNode(documentFragment1), "self-comparison");
assert_false(documentFragment1.isSameNode(documentFragment2), "same properties");
assert_false(documentFragment1.isSameNode(null), "with null other node");
}, "document fragments should be compared on reference");
test(function() {
var document1 = document.implementation.createDocument("", "");
var document2 = document.implementation.createDocument("", "");
assert_true(document1.isSameNode(document1), "self-comparison");
assert_false(document1.isSameNode(document2), "another empty XML document");
assert_false(document1.isSameNode(null), "with null other node");
}, "documents should not be compared on reference");
</script>