Title: [243621] trunk
Revision
243621
Author
[email protected]
Date
2019-03-28 14:23:49 -0700 (Thu, 28 Mar 2019)

Log Message

Debug assert in DOMSelection::containsNode when node belongs to a different tree
https://bugs.webkit.org/show_bug.cgi?id=196342

Reviewed by Antti Koivisto.

Source/WebCore:

The assertion was wrong. It's possible for Range::compareBoundaryPoints to return WRONG_DOCUMENT_ERR
when the node and the start container belong to two different trees.

Return false in such a case for now since it's unclear (unspecified) what these methods on Selection
should do with respect to shadow trees, preserving the current behavior of release builds.

Test: editing/selection/containsNode-with-no-common-ancestor.html

* page/DOMSelection.cpp:
(WebCore::DOMSelection::containsNode const):

LayoutTests:

Added a regression test to catch the debug assertion failure. The test always passed in release builds.

* editing/selection/containsNode-with-no-common-ancestor-expected.txt: Added.
* editing/selection/containsNode-with-no-common-ancestor.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (243620 => 243621)


--- trunk/LayoutTests/ChangeLog	2019-03-28 21:23:05 UTC (rev 243620)
+++ trunk/LayoutTests/ChangeLog	2019-03-28 21:23:49 UTC (rev 243621)
@@ -1,3 +1,15 @@
+2019-03-28  Ryosuke Niwa  <[email protected]>
+
+        Debug assert in DOMSelection::containsNode when node belongs to a different tree
+        https://bugs.webkit.org/show_bug.cgi?id=196342
+
+        Reviewed by Antti Koivisto.
+
+        Added a regression test to catch the debug assertion failure. The test always passed in release builds.
+
+        * editing/selection/containsNode-with-no-common-ancestor-expected.txt: Added.
+        * editing/selection/containsNode-with-no-common-ancestor.html: Added.
+
 2019-03-28  Shawn Roberts  <[email protected]>
 
         http/wpt/cache-storage/quota-third-party.https.html is a flaky failure

Added: trunk/LayoutTests/editing/selection/containsNode-with-no-common-ancestor-expected.txt (0 => 243621)


--- trunk/LayoutTests/editing/selection/containsNode-with-no-common-ancestor-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/containsNode-with-no-common-ancestor-expected.txt	2019-03-28 21:23:49 UTC (rev 243621)
@@ -0,0 +1,11 @@
+This tests calling containsNode when the selection is set inside a shadow tree.
+WebKit should not hit a debug assertion
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.querySelector('input').select(); getSelection().containsNode(document.body) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/editing/selection/containsNode-with-no-common-ancestor.html (0 => 243621)


--- trunk/LayoutTests/editing/selection/containsNode-with-no-common-ancestor.html	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/containsNode-with-no-common-ancestor.html	2019-03-28 21:23:49 UTC (rev 243621)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<body>
+<input type="text" value="hello">
+<script src=""
+<script>
+
+description(`This tests calling containsNode when the selection is set inside a shadow tree.<br>
+WebKit should not hit a debug assertion`);
+
+shouldBeFalse(`document.querySelector('input').select(); getSelection().containsNode(document.body)`);
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (243620 => 243621)


--- trunk/Source/WebCore/ChangeLog	2019-03-28 21:23:05 UTC (rev 243620)
+++ trunk/Source/WebCore/ChangeLog	2019-03-28 21:23:49 UTC (rev 243621)
@@ -1,3 +1,21 @@
+2019-03-28  Ryosuke Niwa  <[email protected]>
+
+        Debug assert in DOMSelection::containsNode when node belongs to a different tree
+        https://bugs.webkit.org/show_bug.cgi?id=196342
+
+        Reviewed by Antti Koivisto.
+
+        The assertion was wrong. It's possible for Range::compareBoundaryPoints to return WRONG_DOCUMENT_ERR
+        when the node and the start container belong to two different trees.
+
+        Return false in such a case for now since it's unclear (unspecified) what these methods on Selection
+        should do with respect to shadow trees, preserving the current behavior of release builds.
+
+        Test: editing/selection/containsNode-with-no-common-ancestor.html
+
+        * page/DOMSelection.cpp:
+        (WebCore::DOMSelection::containsNode const):
+
 2019-03-28  Tim Horton  <[email protected]>
 
         Fix the !ENABLE(APPLE_PAY) build

Modified: trunk/Source/WebCore/page/DOMSelection.cpp (243620 => 243621)


--- trunk/Source/WebCore/page/DOMSelection.cpp	2019-03-28 21:23:05 UTC (rev 243620)
+++ trunk/Source/WebCore/page/DOMSelection.cpp	2019-03-28 21:23:49 UTC (rev 243621)
@@ -415,7 +415,9 @@
     unsigned nodeIndex = node.computeNodeIndex();
 
     auto startsResult = Range::compareBoundaryPoints(parentNode, nodeIndex, &selectedRange->startContainer(), selectedRange->startOffset());
-    ASSERT(!startsResult.hasException());
+    if (startsResult.hasException())
+        return false;
+
     auto endsResult = Range::compareBoundaryPoints(parentNode, nodeIndex + 1, &selectedRange->endContainer(), selectedRange->endOffset());
     ASSERT(!endsResult.hasException());
     bool isNodeFullySelected = !startsResult.hasException() && startsResult.releaseReturnValue() >= 0
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to