Bug 1258576 - Part 1: nsContentIterator should give up to find next/previous node if it reached the root node unexpectedly. r=smaug, a=ritu

nsContentIterator isn't designed as working fine with a tree whose some nodes are being removed.  In such case, NextNode() and PrevNode() meets orphan node (i.e., a node whose parent is nullptr).  Then, nsContentIterator should mark it as "done".

However, it should keep crashing if it's debug build for detecting bugs explicitly.

MozReview-Commit-ID: 81ZQgoHD67T
This commit is contained in:
Masayuki Nakano 2016-03-31 15:00:50 +09:00
parent 30a855d534
commit 4ae12c423b

View File

@ -774,7 +774,11 @@ nsContentIterator::NextNode(nsINode* aNode, nsTArray<int32_t>* aIndexes)
// post-order
nsINode* parent = node->GetParentNode();
NS_WARN_IF(!parent);
if (NS_WARN_IF(!parent)) {
MOZ_ASSERT(parent, "The node is the root node but not the last node");
mIsDone = true;
return node;
}
nsIContent* sibling = nullptr;
int32_t indx = 0;
@ -839,7 +843,11 @@ nsContentIterator::PrevNode(nsINode* aNode, nsTArray<int32_t>* aIndexes)
// if we are a Pre-order iterator, use pre-order
if (mPre) {
nsINode* parent = node->GetParentNode();
NS_WARN_IF(!parent);
if (NS_WARN_IF(!parent)) {
MOZ_ASSERT(parent, "The node is the root node but not the first node");
mIsDone = true;
return aNode;
}
nsIContent* sibling = nullptr;
int32_t indx = 0;