Index: Source/core/dom/Range.cpp |
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp |
index 85906a831541882178e89be7e9c85b864e07bc3a..53a081d175f13e58a51dee60b31a953d1ef101cc 100644 |
--- a/Source/core/dom/Range.cpp |
+++ b/Source/core/dom/Range.cpp |
@@ -901,7 +901,10 @@ PassRefPtr<Node> Range::processAncestorsAndTheirSiblings(ActionType action, Node |
Node* child = it->get(); |
switch (action) { |
case DELETE_CONTENTS: |
- ancestor->removeChild(child, exceptionState); |
+ // Prior call of ancestor->removeChild() may cause a tree change due to DOMSubtreeModified event. |
+ // Therefore, we need to make sure |ancestor| is still |child|'s parent. |
+ if (ancestor == child->parentNode()) |
+ ancestor->removeChild(child, exceptionState); |
break; |
case EXTRACT_CONTENTS: // will remove child from ancestor |
if (direction == ProcessContentsForward) |