editing/firstPositionInNode-crash.html in crashing in Debug
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Oct 2019 23:29:25 +0000 (23:29 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Oct 2019 23:29:25 +0000 (23:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=203520

Reviewed by Ryosuke Niwa.

If positionInParentBeforeNode / positionInParentAfterNode on a node and editingIgnoresContent()
returns true for this node's parent, keep traversing ancestors until we find one for which
editingIgnoresContent() returns false.

No new tests, covered by editing/firstPositionInNode-crash.html.

* dom/Position.cpp:
(WebCore::positionInParentBeforeNode):
(WebCore::positionInParentAfterNode):
* dom/Position.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251683 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Position.cpp
Source/WebCore/dom/Position.h

index 79914b2..e82a6f3 100644 (file)
@@ -1,3 +1,21 @@
+2019-10-28  Chris Dumez  <cdumez@apple.com>
+
+        editing/firstPositionInNode-crash.html in crashing in Debug
+        https://bugs.webkit.org/show_bug.cgi?id=203520
+
+        Reviewed by Ryosuke Niwa.
+
+        If positionInParentBeforeNode / positionInParentAfterNode on a node and editingIgnoresContent()
+        returns true for this node's parent, keep traversing ancestors until we find one for which
+        editingIgnoresContent() returns false.
+
+        No new tests, covered by editing/firstPositionInNode-crash.html.
+
+        * dom/Position.cpp:
+        (WebCore::positionInParentBeforeNode):
+        (WebCore::positionInParentAfterNode):
+        * dom/Position.h:
+
 2019-10-28  Zalan Bujtas  <zalan@apple.com>
 
         Hidden framesets should provide default edgeInfo value
index 3486957..b47a29b 100644 (file)
@@ -1569,6 +1569,28 @@ RefPtr<Node> commonShadowIncludingAncestor(const Position& a, const Position& b)
     return Range::commonAncestorContainer(nodeA, nodeB);
 }
 
+Position positionInParentBeforeNode(Node* node)
+{
+    auto* ancestor = node->parentNode();
+    while (ancestor && editingIgnoresContent(*ancestor)) {
+        node = ancestor;
+        ancestor = ancestor->parentNode();
+    }
+    ASSERT(ancestor);
+    return Position(ancestor, node->computeNodeIndex(), Position::PositionIsOffsetInAnchor);
+}
+
+Position positionInParentAfterNode(Node* node)
+{
+    auto* ancestor = node->parentNode();
+    while (ancestor && editingIgnoresContent(*ancestor)) {
+        node = ancestor;
+        ancestor = ancestor->parentNode();
+    }
+    ASSERT(ancestor);
+    return Position(ancestor, node->computeNodeIndex() + 1, Position::PositionIsOffsetInAnchor);
+}
+
 } // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)
index 77df853..909ad13 100644 (file)
@@ -263,17 +263,8 @@ inline bool operator<=(const Position& a, const Position& b)
     return !a.isNull() && !b.isNull() && (a == b || a < b);
 }
 
-inline Position positionInParentBeforeNode(const Node* node)
-{
-    ASSERT(node->parentNode());
-    return Position(node->parentNode(), node->computeNodeIndex(), Position::PositionIsOffsetInAnchor);
-}
-
-inline Position positionInParentAfterNode(const Node* node)
-{
-    ASSERT(node->parentNode());
-    return Position(node->parentNode(), node->computeNodeIndex() + 1, Position::PositionIsOffsetInAnchor);
-}
+Position positionInParentBeforeNode(Node*);
+Position positionInParentAfterNode(Node*);
 
 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1)
 inline Position positionBeforeNode(Node* anchorNode)