Make reentering nsRange::DeleteContents safe, and make RemoveChildAt deal with

the mutation event removing the child.  Bug 293388, r=sicking, sr=peterv,
a=bsmedberg
This commit is contained in:
bzbarsky%mit.edu 2005-07-26 15:45:49 +00:00
Родитель 9d273059dd
Коммит aa4232c78f
2 изменённых файлов: 18 добавлений и 9 удалений

Просмотреть файл

@ -2764,7 +2764,10 @@ nsGenericElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
nsIDocument *document = GetCurrentDoc();
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEREMOVED)) {
PRBool hasListeners =
HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEREMOVED);
if (hasListeners) {
nsMutationEvent mutation(PR_TRUE, NS_MUTATION_NODEREMOVED, oldKid);
mutation.mRelatedNode = do_QueryInterface(this);
@ -2773,15 +2776,19 @@ nsGenericElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
NS_EVENT_FLAG_INIT, &status);
}
nsRange::OwnerChildRemoved(this, aIndex, oldKid);
// Someone may have removed the kid while that event was processing...
if (!hasListeners ||
(oldKid->GetParent() == this && oldKid == GetChildAt(aIndex))) {
nsRange::OwnerChildRemoved(this, aIndex, oldKid);
mAttrsAndChildren.RemoveChildAt(aIndex);
mAttrsAndChildren.RemoveChildAt(aIndex);
if (aNotify && document) {
document->ContentRemoved(this, oldKid, aIndex);
}
if (aNotify && document) {
document->ContentRemoved(this, oldKid, aIndex);
}
oldKid->UnbindFromTree();
oldKid->UnbindFromTree();
}
}
return NS_OK;

Просмотреть файл

@ -1588,8 +1588,10 @@ nsresult nsRange::DeleteContents()
node->GetParentNode(getter_AddRefs(parent));
res = parent->RemoveChild(node, getter_AddRefs(tmpNode));
if (NS_FAILED(res)) return res;
if (parent) {
res = parent->RemoveChild(node, getter_AddRefs(tmpNode));
if (NS_FAILED(res)) return res;
}
}
}