Index: Source/core/dom/Range.cpp |
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp |
index 44343a12b27f31859079e55d66724d76628d2c01..0b87825708b4dbcb40361fdc0e8c4fc0b6beb687 100644 |
--- a/Source/core/dom/Range.cpp |
+++ b/Source/core/dom/Range.cpp |
@@ -894,8 +894,16 @@ void Range::insertNode(PassRefPtrWillBeRawPtr<Node> prpNewNode, ExceptionState& |
if (exceptionState.hadException()) |
return; |
- if (collapsed) |
+ if (collapsed) { |
+ // The load event would be fired regardless of EventQueueScope; |
+ // e.g. by ContainerNode::updateTreeAfterInsertion |
+ // Given circumstance may mutate the tree so newText->parentNode() may become null |
+ if (!newText->parentNode()) { |
+ exceptionState.throwDOMException(HierarchyRequestError, "This operation would set range's end to parent with new offset, but there's no parent into which to continue."); |
+ return; |
+ } |
m_end.setToBeforeChild(*newText); |
+ } |
} else { |
RefPtrWillBeRawPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? toDocumentFragment(newNode)->lastChild() : newNode.get(); |
if (lastChild && lastChild == m_start.childBefore()) { |