Fix for 3715117, crash from a bug in removeChildren. Clean up node removal and...
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Jul 2004 23:33:50 +0000 (23:33 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Jul 2004 23:33:50 +0000 (23:33 +0000)
bug.  Also clean up checks in removeChild and in the dispatch of removedFromDocument mutation events to
make node removal more efficient.

        Reviewed by kocienda

        * khtml/xml/dom_nodeimpl.cpp:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@7057 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/xml/dom_nodeimpl.cpp

index 3e00e50..d9d1a55 100644 (file)
@@ -1,3 +1,13 @@
+2004-07-19  David Hyatt  <hyatt@apple.com>
+
+       Fix for 3715117, crash from a bug in removeChildren.  Clean up node removal and fix an n-squared removal
+       bug.  Also clean up checks in removeChild and in the dispatch of removedFromDocument mutation events to
+       make node removal more efficient.
+       
+        Reviewed by kocienda
+
+        * khtml/xml/dom_nodeimpl.cpp:
+
 2004-07-19  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Trey.
index cf3bf46..1345267 100644 (file)
@@ -1668,33 +1668,37 @@ NodeImpl *NodeBaseImpl::removeChild ( NodeImpl *oldChild, int &exceptioncode )
     // Dispatch post-removal mutation events
     dispatchSubtreeModifiedEvent();
 
-    NodeImpl *p = this;
-    while (p->parentNode())
-       p = p->parentNode();
-    if (p->nodeType() == Node::DOCUMENT_NODE) {
-       for (NodeImpl *c = oldChild; c; c = c->traverseNextNode(oldChild))
-           c->removedFromDocument();
-    }
+    if (oldChild->inDocument())
+        oldChild->removedFromDocument();
 
     return oldChild;
 }
 
 void NodeBaseImpl::removeChildren()
 {
+    int exceptionCode;
     while (NodeImpl *n = _first) {
         NodeImpl *next = n->nextSibling();
+        
+        // Fire removed from document mutation events.
+        dispatchChildRemovalEvents(n, exceptionCode);
+    
         if (n->attached())
            n->detach();
-        if (n->inDocument())
-            n->removedFromDocument();
         n->setPreviousSibling(0);
         n->setNextSibling(0);
         n->setParent(0);
+        
+        if (n->inDocument())
+            n->removedFromDocument();
         if (!n->refCount())
             delete n;
         _first = next;
     }
     _last = 0;
+    
+    // Dispatch a single post-removal mutation event denoting a modified subtree.
+    dispatchSubtreeModifiedEvent();
 }
 
 
@@ -2117,10 +2121,7 @@ void NodeBaseImpl::dispatchChildRemovalEvents( NodeImpl *child, int &exceptionco
     bool hasRemovalListeners = getDocument()->hasListenerType(DocumentImpl::DOMNODEREMOVEDFROMDOCUMENT_LISTENER);
 
     // dispatch the DOMNOdeRemovedFromDocument event to all descendants
-    NodeImpl *p = this;
-    while (p->parentNode())
-       p = p->parentNode();
-    if (p->nodeType() == Node::DOCUMENT_NODE) {
+    if (inDocument()) {
        for (NodeImpl *c = child; c; c = c->traverseNextNode(child)) {
            if (hasRemovalListeners) {
                c->dispatchEvent(new MutationEventImpl(EventImpl::DOMNODEREMOVEDFROMDOCUMENT_EVENT,