Skip to content
Permalink
Browse files
Range.insersectsNode(node) is supposed to return true if node.parent …
…is null

https://bugs.webkit.org/show_bug.cgi?id=148687

Reviewed by Ryosuke Niwa.

Source/WebCore:

Range.insersectsNode(node) is supposed to return true if node.parent is
null:
https://dom.spec.whatwg.org/#dom-range-intersectsnode (step 3)

Previously, WebKit would throw a NotFoundError, apparently to match
Firefox's behavior. However, these days, Firefox complies with the
specification and returns true here.

No new tests, already covered by:
http/tests/w3c/dom/ranges/Range-intersectsNode.html (rebaselined)

* dom/Range.cpp:
(WebCore::Range::intersectsNode):

LayoutTests:

Rebaseline / update existing tests.

* fast/dom/Range/range-intersectsNode-expected.txt:
* fast/dom/Range/resources/intersectsNode.js:
* http/tests/w3c/dom/nodes/Element-matches-expected.txt:
* http/tests/w3c/dom/ranges/Range-intersectsNode-expected.txt:

Canonical link: https://commits.webkit.org/166803@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189225 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Sep 1, 2015
1 parent d06f4ba commit d913d62c79998d0f968c22dac7a2139a2d57dd9d
Showing 7 changed files with 101 additions and 70 deletions.
@@ -1,3 +1,17 @@
2015-09-01 Chris Dumez <cdumez@apple.com>

Range.insersectsNode(node) is supposed to return true if node.parent is null
https://bugs.webkit.org/show_bug.cgi?id=148687

Reviewed by Ryosuke Niwa.

Rebaseline / update existing tests.

* fast/dom/Range/range-intersectsNode-expected.txt:
* fast/dom/Range/resources/intersectsNode.js:
* http/tests/w3c/dom/nodes/Element-matches-expected.txt:
* http/tests/w3c/dom/ranges/Range-intersectsNode-expected.txt:

2015-09-01 Zalan Bujtas <zalan@apple.com>

Repaint cleanup:
@@ -50,7 +50,7 @@ PASS detachedRange.intersectsNode(document.getElementById('a1')) is false
PASS intersects is false

2.3 Node has no parent
PASS range.intersectsNode(document) threw exception Error: NotFoundError: DOM Exception 8.
PASS range.intersectsNode(document) is true

2.4 Range has no parent
PASS range.selectNode(document) threw exception Error: InvalidNodeTypeError: DOM Exception 24.
@@ -109,7 +109,7 @@ debug("");

debug("2.3 Node has no parent");
range.selectNode(document.getElementById("a2"));
shouldThrow("range.intersectsNode(document)");
shouldBeTrue("range.intersectsNode(document)");
debug("");

debug("2.4 Range has no parent");
@@ -171,7 +171,7 @@ PASS In-document Element.matches: :empty pseudo-class selector, matching empty p
PASS In-document Element.matches: :empty pseudo-class selector, matching all empty elements (with no refNodes): #pseudo-empty :empty
PASS In-document Element.matches: :link and :visited pseudo-class selectors, matching a and area elements with href attributes (with no refNodes): #pseudo-link :link, #pseudo-link :visited
PASS In-document Element.matches: :link and :visited pseudo-class selectors, matching link elements with href attributes (with no refNodes): #head :link, #head :visited
FAIL In-document Element.matches: :target pseudo-class selector, matching the element referenced by the URL fragment identifier (with no refNodes): :target assert_true: The element #target should match the selector. expected true got false
PASS In-document Element.matches: :target pseudo-class selector, matching the element referenced by the URL fragment identifier (with no refNodes): :target
PASS In-document Element.matches: :lang pseudo-class selector, matching inherited language (with no refNodes): #pseudo-lang-div1:lang(en)
PASS In-document Element.matches: :lang pseudo-class selector, matching specified language with exact value (with no refNodes): #pseudo-lang-div2:lang(fr)
PASS In-document Element.matches: :lang pseudo-class selector, matching specified language with partial value (with no refNodes): #pseudo-lang-div3:lang(en)
@@ -426,67 +426,67 @@ PASS Node 6 detachedPara1.firstChild, range 56 [detachedComment, 5, detachedComm
PASS Node 6 detachedPara1.firstChild, range 57 [detachedForeignComment, 4, detachedForeignComment, 4]
PASS Node 6 detachedPara1.firstChild, range 58 [foreignDocfrag, 0, foreignDocfrag, 0]
PASS Node 6 detachedPara1.firstChild, range 59 [xmlDocfrag, 0, xmlDocfrag, 0]
FAIL Node 7 document, detached range NotFoundError: DOM Exception 8
FAIL Node 7 document, range 0 [paras[0].firstChild, 0, paras[0].firstChild, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 1 [paras[0].firstChild, 0, paras[0].firstChild, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 2 [paras[0].firstChild, 2, paras[0].firstChild, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 3 [paras[0].firstChild, 2, paras[0].firstChild, 9] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 4 [paras[1].firstChild, 0, paras[1].firstChild, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 5 [paras[1].firstChild, 2, paras[1].firstChild, 9] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 6 [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 7 [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 8 [foreignPara1.firstChild, 0, foreignPara1.firstChild, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 9 [foreignPara1.firstChild, 2, foreignPara1.firstChild, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 10 [document.documentElement, 0, document.documentElement, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 11 [document.documentElement, 0, document.documentElement, 2] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 12 [document.documentElement, 1, document.documentElement, 2] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 13 [document.head, 1, document.head, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 14 [document.body, 4, document.body, 5] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 15 [foreignDoc.documentElement, 0, foreignDoc.documentElement, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 16 [paras[0], 0, paras[0], 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 17 [detachedPara1, 0, detachedPara1, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 18 [paras[0].firstChild, 0, paras[1].firstChild, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 19 [paras[0].firstChild, 0, paras[1].firstChild, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 20 [paras[0].firstChild, 3, paras[3], 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 21 [paras[0], 0, paras[0].firstChild, 7] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 22 [testDiv, 2, paras[4], 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 23 [document, 0, document, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 24 [document, 0, document, 2] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 25 [comment, 2, comment, 3] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 26 [testDiv, 0, comment, 5] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 27 [foreignDoc, 1, foreignComment, 2] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 28 [foreignDoc.body, 0, foreignTextNode, 36] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 29 [xmlDoc, 1, xmlComment, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 30 [detachedTextNode, 0, detachedTextNode, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 31 [detachedForeignTextNode, 0, detachedForeignTextNode, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 32 [detachedXmlTextNode, 0, detachedXmlTextNode, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 33 [detachedComment, 3, detachedComment, 4] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 34 [detachedForeignComment, 0, detachedForeignComment, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 35 [detachedXmlComment, 2, detachedXmlComment, 6] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 36 [docfrag, 0, docfrag, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 37 [processingInstruction, 0, processingInstruction, 4] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 38 [paras[1].firstChild, 0, paras[1].firstChild, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 39 [paras[1].firstChild, 2, paras[1].firstChild, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 40 [detachedPara1.firstChild, 0, detachedPara1.firstChild, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 41 [foreignPara1.firstChild, 0, foreignPara1.firstChild, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 42 [foreignDoc.head, 1, foreignDoc.head, 1] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 43 [foreignDoc.body, 0, foreignDoc.body, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 44 [paras[0], 0, paras[0], 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 45 [detachedPara1, 0, detachedPara1, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 46 [testDiv, 1, paras[2].firstChild, 5] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 47 [document.documentElement, 1, document.body, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 48 [foreignDoc.documentElement, 1, foreignDoc.body, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 49 [document, 1, document, 2] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 50 [paras[2].firstChild, 4, comment, 2] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 51 [paras[3], 1, comment, 8] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 52 [foreignDoc, 0, foreignDoc, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 53 [xmlDoc, 0, xmlDoc, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 54 [detachedForeignTextNode, 7, detachedForeignTextNode, 7] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 55 [detachedXmlTextNode, 7, detachedXmlTextNode, 7] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 56 [detachedComment, 5, detachedComment, 5] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 57 [detachedForeignComment, 4, detachedForeignComment, 4] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 58 [foreignDocfrag, 0, foreignDocfrag, 0] NotFoundError: DOM Exception 8
FAIL Node 7 document, range 59 [xmlDocfrag, 0, xmlDocfrag, 0] NotFoundError: DOM Exception 8
PASS Node 7 document, detached range
PASS Node 7 document, range 0 [paras[0].firstChild, 0, paras[0].firstChild, 0]
PASS Node 7 document, range 1 [paras[0].firstChild, 0, paras[0].firstChild, 1]
PASS Node 7 document, range 2 [paras[0].firstChild, 2, paras[0].firstChild, 8]
PASS Node 7 document, range 3 [paras[0].firstChild, 2, paras[0].firstChild, 9]
PASS Node 7 document, range 4 [paras[1].firstChild, 0, paras[1].firstChild, 0]
PASS Node 7 document, range 5 [paras[1].firstChild, 2, paras[1].firstChild, 9]
PASS Node 7 document, range 6 [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0]
PASS Node 7 document, range 7 [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8]
PASS Node 7 document, range 8 [foreignPara1.firstChild, 0, foreignPara1.firstChild, 0]
PASS Node 7 document, range 9 [foreignPara1.firstChild, 2, foreignPara1.firstChild, 8]
PASS Node 7 document, range 10 [document.documentElement, 0, document.documentElement, 1]
PASS Node 7 document, range 11 [document.documentElement, 0, document.documentElement, 2]
PASS Node 7 document, range 12 [document.documentElement, 1, document.documentElement, 2]
PASS Node 7 document, range 13 [document.head, 1, document.head, 1]
PASS Node 7 document, range 14 [document.body, 4, document.body, 5]
PASS Node 7 document, range 15 [foreignDoc.documentElement, 0, foreignDoc.documentElement, 1]
PASS Node 7 document, range 16 [paras[0], 0, paras[0], 1]
PASS Node 7 document, range 17 [detachedPara1, 0, detachedPara1, 1]
PASS Node 7 document, range 18 [paras[0].firstChild, 0, paras[1].firstChild, 0]
PASS Node 7 document, range 19 [paras[0].firstChild, 0, paras[1].firstChild, 8]
PASS Node 7 document, range 20 [paras[0].firstChild, 3, paras[3], 1]
PASS Node 7 document, range 21 [paras[0], 0, paras[0].firstChild, 7]
PASS Node 7 document, range 22 [testDiv, 2, paras[4], 1]
PASS Node 7 document, range 23 [document, 0, document, 1]
PASS Node 7 document, range 24 [document, 0, document, 2]
PASS Node 7 document, range 25 [comment, 2, comment, 3]
PASS Node 7 document, range 26 [testDiv, 0, comment, 5]
PASS Node 7 document, range 27 [foreignDoc, 1, foreignComment, 2]
PASS Node 7 document, range 28 [foreignDoc.body, 0, foreignTextNode, 36]
PASS Node 7 document, range 29 [xmlDoc, 1, xmlComment, 0]
PASS Node 7 document, range 30 [detachedTextNode, 0, detachedTextNode, 8]
PASS Node 7 document, range 31 [detachedForeignTextNode, 0, detachedForeignTextNode, 8]
PASS Node 7 document, range 32 [detachedXmlTextNode, 0, detachedXmlTextNode, 8]
PASS Node 7 document, range 33 [detachedComment, 3, detachedComment, 4]
PASS Node 7 document, range 34 [detachedForeignComment, 0, detachedForeignComment, 1]
PASS Node 7 document, range 35 [detachedXmlComment, 2, detachedXmlComment, 6]
PASS Node 7 document, range 36 [docfrag, 0, docfrag, 0]
PASS Node 7 document, range 37 [processingInstruction, 0, processingInstruction, 4]
PASS Node 7 document, range 38 [paras[1].firstChild, 0, paras[1].firstChild, 1]
PASS Node 7 document, range 39 [paras[1].firstChild, 2, paras[1].firstChild, 8]
PASS Node 7 document, range 40 [detachedPara1.firstChild, 0, detachedPara1.firstChild, 1]
PASS Node 7 document, range 41 [foreignPara1.firstChild, 0, foreignPara1.firstChild, 1]
PASS Node 7 document, range 42 [foreignDoc.head, 1, foreignDoc.head, 1]
PASS Node 7 document, range 43 [foreignDoc.body, 0, foreignDoc.body, 0]
PASS Node 7 document, range 44 [paras[0], 0, paras[0], 0]
PASS Node 7 document, range 45 [detachedPara1, 0, detachedPara1, 0]
PASS Node 7 document, range 46 [testDiv, 1, paras[2].firstChild, 5]
PASS Node 7 document, range 47 [document.documentElement, 1, document.body, 0]
PASS Node 7 document, range 48 [foreignDoc.documentElement, 1, foreignDoc.body, 0]
PASS Node 7 document, range 49 [document, 1, document, 2]
PASS Node 7 document, range 50 [paras[2].firstChild, 4, comment, 2]
PASS Node 7 document, range 51 [paras[3], 1, comment, 8]
PASS Node 7 document, range 52 [foreignDoc, 0, foreignDoc, 0]
PASS Node 7 document, range 53 [xmlDoc, 0, xmlDoc, 0]
PASS Node 7 document, range 54 [detachedForeignTextNode, 7, detachedForeignTextNode, 7]
PASS Node 7 document, range 55 [detachedXmlTextNode, 7, detachedXmlTextNode, 7]
PASS Node 7 document, range 56 [detachedComment, 5, detachedComment, 5]
PASS Node 7 document, range 57 [detachedForeignComment, 4, detachedForeignComment, 4]
PASS Node 7 document, range 58 [foreignDocfrag, 0, foreignDocfrag, 0]
PASS Node 7 document, range 59 [xmlDocfrag, 0, xmlDocfrag, 0]
PASS Node 8 detachedDiv, detached range
PASS Node 8 detachedDiv, range 0 [paras[0].firstChild, 0, paras[0].firstChild, 0]
PASS Node 8 detachedDiv, range 1 [paras[0].firstChild, 0, paras[0].firstChild, 1]
@@ -1,3 +1,24 @@
2015-09-01 Chris Dumez <cdumez@apple.com>

Range.insersectsNode(node) is supposed to return true if node.parent is null
https://bugs.webkit.org/show_bug.cgi?id=148687

Reviewed by Ryosuke Niwa.

Range.insersectsNode(node) is supposed to return true if node.parent is
null:
https://dom.spec.whatwg.org/#dom-range-intersectsnode (step 3)

Previously, WebKit would throw a NotFoundError, apparently to match
Firefox's behavior. However, these days, Firefox complies with the
specification and returns true here.

No new tests, already covered by:
http/tests/w3c/dom/ranges/Range-intersectsNode.html (rebaselined)

* dom/Range.cpp:
(WebCore::Range::intersectsNode):

2015-09-01 Brian Burg <bburg@apple.com>

Web Inspector: tighten up lifetimes for InspectorController-owned objects; add brace initializers to agents
@@ -501,12 +501,8 @@ bool Range::intersectsNode(Node* refNode, ExceptionCode& ec) const
ContainerNode* parentNode = refNode->parentNode();
unsigned nodeIndex = refNode->computeNodeIndex();

if (!parentNode) {
// if the node is the top document we should return NODE_BEFORE_AND_AFTER
// but we throw to match firefox behavior
ec = NOT_FOUND_ERR;
return false;
}
if (!parentNode)
return true;

if (comparePoint(parentNode, nodeIndex, ec) < 0 && // starts before start
comparePoint(parentNode, nodeIndex + 1, ec) < 0) { // ends before start

0 comments on commit d913d62

Please sign in to comment.