Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Unified Diff: Source/core/editing/CompositeEditCommand.cpp

Issue 251723003: Check the traversal state in CompositeEditCommand::cloneParagraphUnderNewElement (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/CompositeEditCommand.cpp
diff --git a/Source/core/editing/CompositeEditCommand.cpp b/Source/core/editing/CompositeEditCommand.cpp
index c9defa511a558e6d31e88827229257ed8b1aa509..9148d180d81f6fbe6fd10694be13d2c44d365ce1 100644
--- a/Source/core/editing/CompositeEditCommand.cpp
+++ b/Source/core/editing/CompositeEditCommand.cpp
@@ -964,6 +964,8 @@ void CompositeEditCommand::pushAnchorElementDown(Node* anchorNode)
void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start, const Position& end, Node* passedOuterNode, Element* blockElement)
{
ASSERT(comparePositions(start, end) <= 0);
+ ASSERT(passedOuterNode);
+ ASSERT(blockElement);
// First we clone the outerNode
RefPtr<Node> lastNode;
@@ -1005,20 +1007,26 @@ void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
// If end is not a descendant of outerNode we need to
// find the first common ancestor to increase the scope
// of our nextSibling traversal.
- while (!end.deprecatedNode()->isDescendantOf(outerNode.get())) {
+ while (outerNode && !end.deprecatedNode()->isDescendantOf(outerNode.get())) {
outerNode = outerNode->parentNode();
}
+ if (!outerNode)
Yuta Kitamura 2014/04/28 02:56:42 In what situation this could happen? (I really cou
yoichio 2014/04/30 07:45:17 It takes place when |passedOuterNode| and |end| ar
+ return;
+
RefPtr<Node> startNode = start.deprecatedNode();
for (RefPtr<Node> node = NodeTraversal::nextSkippingChildren(*startNode, outerNode.get()); node; node = NodeTraversal::nextSkippingChildren(*node, outerNode.get())) {
// Move lastNode up in the tree as much as node was moved up in the
// tree by NodeTraversal::nextSkippingChildren, so that the relative depth between
// node and the original start node is maintained in the clone.
- while (startNode->parentNode() != node->parentNode()) {
+ while (startNode && lastNode && startNode->parentNode() != node->parentNode()) {
startNode = startNode->parentNode();
lastNode = lastNode->parentNode();
}
+ if (!lastNode || !lastNode->parentNode())
Yuta Kitamura 2014/04/28 02:56:42 What's the point of checking the non-nullness of l
yoichio 2014/04/30 07:45:17 It is for L1031:insertNodeAfter(clonedNode, lastNo
+ return;
+
RefPtr<Node> clonedNode = node->cloneNode(true);
insertNodeAfter(clonedNode, lastNode);
lastNode = clonedNode.release();

Powered by Google App Engine
This is Rietveld 408576698