2011-05-11 Dimitri Glazkov <dglazkov@chromium.org>
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 May 2011 18:35:15 +0000 (18:35 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 May 2011 18:35:15 +0000 (18:35 +0000)
        Unreviewed, rolling out r85650.
        http://trac.webkit.org/changeset/85650
        https://bugs.webkit.org/show_bug.cgi?id=59983

        Triggers m_numNodeListCaches > 0 assert in gc-heavy sites.

        * dom/ContainerNode.cpp:
        (WebCore::ContainerNode::childrenChanged):
        * dom/Node.cpp:
        (WebCore::Node::~Node):
        (WebCore::Node::setDocument):
        (WebCore::Node::setTreeScopeRecursively):
        (WebCore::Node::childNodes):
        (WebCore::Node::registerDynamicNodeList):
        (WebCore::Node::unregisterDynamicNodeList):
        (WebCore::Node::notifyLocalNodeListsAttributeChanged):
        (WebCore::Node::notifyLocalNodeListsChildrenChanged):
        (WebCore::Node::getElementsByTagName):
        (WebCore::Node::getElementsByTagNameNS):
        (WebCore::Node::getElementsByName):
        (WebCore::Node::getElementsByClassName):
        * dom/Node.h:
        * html/HTMLFormControlElement.cpp:
        (WebCore::HTMLFormControlElement::labels):

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

Source/WebCore/ChangeLog
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/html/HTMLFormControlElement.cpp

index ef9293c..b4a587a 100644 (file)
@@ -1,3 +1,30 @@
+2011-05-11  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Unreviewed, rolling out r85650.
+        http://trac.webkit.org/changeset/85650
+        https://bugs.webkit.org/show_bug.cgi?id=59983
+
+        Triggers m_numNodeListCaches > 0 assert in gc-heavy sites.
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::childrenChanged):
+        * dom/Node.cpp:
+        (WebCore::Node::~Node):
+        (WebCore::Node::setDocument):
+        (WebCore::Node::setTreeScopeRecursively):
+        (WebCore::Node::childNodes):
+        (WebCore::Node::registerDynamicNodeList):
+        (WebCore::Node::unregisterDynamicNodeList):
+        (WebCore::Node::notifyLocalNodeListsAttributeChanged):
+        (WebCore::Node::notifyLocalNodeListsChildrenChanged):
+        (WebCore::Node::getElementsByTagName):
+        (WebCore::Node::getElementsByTagNameNS):
+        (WebCore::Node::getElementsByName):
+        (WebCore::Node::getElementsByClassName):
+        * dom/Node.h:
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::labels):
+
 2011-05-11  Eric Carlson  <eric.carlson@apple.com>
 
         Reviewed by Darin Adler.
index d89c23a..a1ca23d 100644 (file)
@@ -802,7 +802,7 @@ void ContainerNode::childrenChanged(bool changedByParser, Node* beforeChange, No
     Node::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
     if (!changedByParser && childCountDelta)
         document()->nodeChildrenChanged(this);
-    if (treeScope()->hasNodeListCaches())
+    if (document()->hasNodeListCaches())
         notifyNodeListsChildrenChanged();
 }
 
index 4428ffa..c9597fb 100644 (file)
@@ -388,8 +388,8 @@ Node::~Node()
     if (!hasRareData())
         ASSERT(!NodeRareData::rareDataMap().contains(this));
     else {
-        if (treeScope() && rareData()->nodeLists())
-            treeScope()->removeNodeListCache();
+        if (m_document && rareData()->nodeLists())
+            m_document->removeNodeListCache();
         
         NodeRareData::NodeRareDataMap& dataMap = NodeRareData::rareDataMap();
         NodeRareData::NodeRareDataMap::iterator it = dataMap.find(this);
@@ -452,6 +452,12 @@ void Node::setDocument(Document* document)
     willMoveToNewOwnerDocument();
     ASSERT(willMoveToNewOwnerDocumentWasCalled);
 
+    if (hasRareData() && rareData()->nodeLists()) {
+        if (m_document)
+            m_document->removeNodeListCache();
+        document->addNodeListCache();
+    }
+
     if (m_document) {
         m_document->moveNodeIteratorsToNewDocument(this, document);
         m_document->guardDeref();
@@ -502,12 +508,6 @@ void Node::setTreeScopeRecursively(TreeScope* newTreeScope, bool includeRoot)
         } else
             node->ensureRareData()->setTreeScope(newTreeScope);
 
-        if (hasRareData() && rareData()->nodeLists()) {
-            if (currentTreeScope)
-                currentTreeScope->removeNodeListCache();
-            newTreeScope->addNodeListCache();
-        }
-
         node->setDocument(newDocument);
 
         if (!node->isElementNode())
@@ -604,8 +604,8 @@ PassRefPtr<NodeList> Node::childNodes()
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        if (treeScope())
-            treeScope()->addNodeListCache();
+        if (document())
+            document()->addNodeListCache();
     }
 
     return ChildNodeList::create(this, data->nodeLists()->m_childNodeListCaches.get());
@@ -976,8 +976,8 @@ void Node::registerDynamicNodeList(DynamicNodeList* list)
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        treeScope()->addNodeListCache();
-    } else if (!treeScope() || !treeScope()->hasNodeListCaches()) {
+        document()->addNodeListCache();
+    } else if (!m_document || !m_document->hasNodeListCaches()) {
         // We haven't been receiving notifications while there were no registered lists, so the cache is invalid now.
         data->nodeLists()->invalidateCaches();
     }
@@ -995,8 +995,8 @@ void Node::unregisterDynamicNodeList(DynamicNodeList* list)
         data->nodeLists()->m_listsWithCaches.remove(list);
         if (data->nodeLists()->isEmpty()) {
             data->clearNodeLists();
-            if (treeScope())
-                treeScope()->removeNodeListCache();
+            if (document())
+                document()->removeNodeListCache();
         }
     }
 }
@@ -1016,7 +1016,7 @@ void Node::notifyLocalNodeListsAttributeChanged()
 
     if (data->nodeLists()->isEmpty()) {
         data->clearNodeLists();
-        treeScope()->removeNodeListCache();
+        document()->removeNodeListCache();
     }
 }
 
@@ -1042,7 +1042,7 @@ void Node::notifyLocalNodeListsChildrenChanged()
 
     if (data->nodeLists()->isEmpty()) {
         data->clearNodeLists();
-        treeScope()->removeNodeListCache();
+        document()->removeNodeListCache();
     }
 }
 
@@ -1772,7 +1772,7 @@ PassRefPtr<NodeList> Node::getElementsByTagName(const AtomicString& localName)
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        treeScope()->addNodeListCache();
+        document()->addNodeListCache();
     }
 
     String name = localName;
@@ -1801,7 +1801,7 @@ PassRefPtr<NodeList> Node::getElementsByTagNameNS(const AtomicString& namespaceU
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        treeScope()->addNodeListCache();
+        document()->addNodeListCache();
     }
 
     String name = localName;
@@ -1824,7 +1824,7 @@ PassRefPtr<NodeList> Node::getElementsByName(const String& elementName)
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        treeScope()->addNodeListCache();
+        document()->addNodeListCache();
     }
 
     pair<NodeListsNodeData::NameNodeListCache::iterator, bool> result = data->nodeLists()->m_nameNodeListCache.add(elementName, 0);
@@ -1841,7 +1841,7 @@ PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames)
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        treeScope()->addNodeListCache();
+        document()->addNodeListCache();
     }
 
     pair<NodeListsNodeData::ClassNodeListCache::iterator, bool> result = data->nodeLists()->m_classNodeListCache.add(classNames, 0);
index daf1c00..5ffb4cc 100644 (file)
@@ -627,6 +627,11 @@ protected:
     };
     Node(Document*, ConstructionType);
 
+    // Do not use this method to change the document of a node until after the node has been
+    // removed from its previous document.
+    void setDocument(Document*);
+    void setDocumentRecursively(Document*);
+
     virtual void willMoveToNewOwnerDocument();
     virtual void didMoveToNewOwnerDocument();
     
@@ -640,11 +645,6 @@ protected:
     NodeRareData* ensureRareData();
 
 private:
-    // Do not use this method to change the document of a node until after the node has been
-    // removed from its previous document.
-    void setDocumentRecursively(Document*);
-    void setDocument(Document*);
-
     enum EditableLevel { Editable, RichlyEditable };
     bool rendererIsEditable(EditableLevel) const;
 
index 8be7609..b125060 100644 (file)
@@ -468,7 +468,7 @@ PassRefPtr<NodeList> HTMLFormControlElement::labels()
     NodeRareData* data = Node::ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        treeScope()->addNodeListCache();
+        document()->addNodeListCache();
     }
 
     if (data->nodeLists()->m_labelsNodeListCache)