HTMLCollection's caches should be owned by either ElementRareData or Document
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jun 2012 23:56:42 +0000 (23:56 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jun 2012 23:56:42 +0000 (23:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90322

Reviewed by Anders Carlsson.

Removed all instances of OwnPtr<HTMLCollection> except ones on ElementRareData and Document.
ElementRareData::ensureCachedHTMLCollection then polymorphically creates HTMLCollection or
its subclass as deemed necessary.

This refactoring allows us to move HTMLCollection to use the same invalidation model as
DynamicNodeList (invalidated during DOM mutations) in a follow up.

* dom/Document.cpp:
(WebCore::Document::all):
* dom/Document.h:
(Document):
* dom/Element.cpp:
(WebCore::ElementRareData::ensureCachedHTMLCollection):
(WebCore):
(WebCore::Element::cachedHTMLCollection):
* dom/Element.h:
(Element):
* dom/ElementRareData.h:
(WebCore):
(ElementRareData):
(WebCore::ElementRareData::cachedHTMLCollection):
* dom/Node.cpp:
(WebCore):
* dom/Node.h:
(Node):
* dom/NodeRareData.h:
(WebCore::NodeRareData::setItemType):
(NodeRareData):
* html/CollectionType.h:
* html/HTMLCollection.cpp:
(WebCore::shouldIncludeChildren):
(WebCore::HTMLCollection::isAcceptableElement):
* html/HTMLElement.cpp:
(WebCore):
(WebCore::HTMLElement::properties):
* html/HTMLElement.h:
(HTMLElement):
* html/HTMLFieldSetElement.cpp:
(WebCore::HTMLFieldSetElement::elements):
* html/HTMLFieldSetElement.h:
(HTMLFieldSetElement):
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::HTMLFormCollection):
(WebCore::HTMLFormCollection::create):
* html/HTMLFormCollection.h:
(HTMLFormCollection):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::elements):
* html/HTMLFormElement.h:
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
(WebCore::HTMLOptionsCollection::create):
* html/HTMLOptionsCollection.h:
(HTMLOptionsCollection):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::selectedOptions):
(WebCore::HTMLSelectElement::options):
(WebCore::HTMLSelectElement::invalidateSelectedItems):
(WebCore::HTMLSelectElement::setRecalcListItems):
* html/HTMLSelectElement.h:
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::rows):
* html/HTMLTableElement.h:
* html/HTMLTableRowsCollection.cpp:
(WebCore::HTMLTableRowsCollection::HTMLTableRowsCollection):
(WebCore::HTMLTableRowsCollection::create):
* html/HTMLTableRowsCollection.h:
(HTMLTableRowsCollection):

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

27 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/ElementRareData.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/NodeRareData.h
Source/WebCore/html/CollectionType.h
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLElement.h
Source/WebCore/html/HTMLFieldSetElement.cpp
Source/WebCore/html/HTMLFieldSetElement.h
Source/WebCore/html/HTMLFormCollection.cpp
Source/WebCore/html/HTMLFormCollection.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h
Source/WebCore/html/HTMLOptionsCollection.cpp
Source/WebCore/html/HTMLOptionsCollection.h
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLSelectElement.h
Source/WebCore/html/HTMLTableElement.cpp
Source/WebCore/html/HTMLTableElement.h
Source/WebCore/html/HTMLTableRowsCollection.cpp
Source/WebCore/html/HTMLTableRowsCollection.h

index 88741a2..e6173cc 100644 (file)
@@ -1,3 +1,79 @@
+2012-06-29  Ryosuke Niwa  <rniwa@webkit.org>
+
+        HTMLCollection's caches should be owned by either ElementRareData or Document
+        https://bugs.webkit.org/show_bug.cgi?id=90322
+
+        Reviewed by Anders Carlsson.
+
+        Removed all instances of OwnPtr<HTMLCollection> except ones on ElementRareData and Document.
+        ElementRareData::ensureCachedHTMLCollection then polymorphically creates HTMLCollection or
+        its subclass as deemed necessary.
+
+        This refactoring allows us to move HTMLCollection to use the same invalidation model as
+        DynamicNodeList (invalidated during DOM mutations) in a follow up.
+
+        * dom/Document.cpp:
+        (WebCore::Document::all):
+        * dom/Document.h:
+        (Document):
+        * dom/Element.cpp:
+        (WebCore::ElementRareData::ensureCachedHTMLCollection):
+        (WebCore):
+        (WebCore::Element::cachedHTMLCollection):
+        * dom/Element.h:
+        (Element):
+        * dom/ElementRareData.h:
+        (WebCore):
+        (ElementRareData):
+        (WebCore::ElementRareData::cachedHTMLCollection):
+        * dom/Node.cpp:
+        (WebCore):
+        * dom/Node.h:
+        (Node):
+        * dom/NodeRareData.h:
+        (WebCore::NodeRareData::setItemType):
+        (NodeRareData):
+        * html/CollectionType.h:
+        * html/HTMLCollection.cpp:
+        (WebCore::shouldIncludeChildren):
+        (WebCore::HTMLCollection::isAcceptableElement):
+        * html/HTMLElement.cpp:
+        (WebCore):
+        (WebCore::HTMLElement::properties):
+        * html/HTMLElement.h:
+        (HTMLElement):
+        * html/HTMLFieldSetElement.cpp:
+        (WebCore::HTMLFieldSetElement::elements):
+        * html/HTMLFieldSetElement.h:
+        (HTMLFieldSetElement):
+        * html/HTMLFormCollection.cpp:
+        (WebCore::HTMLFormCollection::HTMLFormCollection):
+        (WebCore::HTMLFormCollection::create):
+        * html/HTMLFormCollection.h:
+        (HTMLFormCollection):
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::elements):
+        * html/HTMLFormElement.h:
+        * html/HTMLOptionsCollection.cpp:
+        (WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
+        (WebCore::HTMLOptionsCollection::create):
+        * html/HTMLOptionsCollection.h:
+        (HTMLOptionsCollection):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::selectedOptions):
+        (WebCore::HTMLSelectElement::options):
+        (WebCore::HTMLSelectElement::invalidateSelectedItems):
+        (WebCore::HTMLSelectElement::setRecalcListItems):
+        * html/HTMLSelectElement.h:
+        * html/HTMLTableElement.cpp:
+        (WebCore::HTMLTableElement::rows):
+        * html/HTMLTableElement.h:
+        * html/HTMLTableRowsCollection.cpp:
+        (WebCore::HTMLTableRowsCollection::HTMLTableRowsCollection):
+        (WebCore::HTMLTableRowsCollection::create):
+        * html/HTMLTableRowsCollection.h:
+        (HTMLTableRowsCollection):
+
 2012-06-29  Ojan Vafai  <ojan@chromium.org>
 
         Add FIXMEs for vertical writing mode and override sizes.
index 188fcac..12ae63f 100644 (file)
@@ -4745,9 +4745,9 @@ HTMLCollection* Document::anchors()
 
 HTMLAllCollection* Document::all()
 {
-    if (!m_allCollection)
-        m_allCollection = HTMLAllCollection::create(this);
-    return m_allCollection.get();
+    if (!m_collections[DocAll])
+        m_collections[DocAll] = HTMLAllCollection::create(this);
+    return static_cast<HTMLAllCollection*>(m_collections[DocAll].get());
 }
 
 HTMLCollection* Document::windowNamedItems(const AtomicString& name)
index eccf8a7..2e1ac13 100644 (file)
@@ -1396,7 +1396,6 @@ private:
     InheritedBool m_designMode;
     
     OwnPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];
-    OwnPtr<HTMLAllCollection> m_allCollection;
     HashSet<DynamicSubtreeNodeList*> m_listsInvalidatedAtDocument;
 
     typedef HashMap<AtomicStringImpl*, OwnPtr<HTMLNameCollection> > NamedCollectionMap;
index ebc0c9b..91477f6 100644 (file)
 #include "HTMLCollection.h"
 #include "HTMLDocument.h"
 #include "HTMLElement.h"
+#include "HTMLFormCollection.h"
 #include "HTMLFrameOwnerElement.h"
 #include "HTMLNames.h"
+#include "HTMLOptionsCollection.h"
 #include "HTMLParserIdioms.h"
+#include "HTMLTableRowsCollection.h"
 #include "InspectorInstrumentation.h"
 #include "MutationObserverInterestGroup.h"
 #include "MutationRecord.h"
@@ -2044,6 +2047,37 @@ HTMLCollection* Element::ensureCachedHTMLCollection(CollectionType type)
     return ensureElementRareData()->ensureCachedHTMLCollection(this, type);
 }
 
+HTMLCollection* ElementRareData::ensureCachedHTMLCollection(Element* element, CollectionType type)
+{
+    if (!m_cachedCollections)
+        m_cachedCollections = adoptPtr(new CachedHTMLCollectionArray);
+    
+    OwnPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
+    if (!collection) {
+        if (type == TableRows) {
+            ASSERT(element->hasTagName(tableTag));
+            collection = HTMLTableRowsCollection::create(element);
+        } else if (type == SelectOptions) {
+            ASSERT(element->hasTagName(selectTag));
+            collection = HTMLOptionsCollection::create(element);
+        } else if (type == FormControls) {
+            ASSERT(element->hasTagName(formTag) || element->hasTagName(fieldsetTag));
+            collection = HTMLFormCollection::create(element);
+#if ENABLE(MICRODATA)
+        } else if (type == ItemProperties) {
+            collection = HTMLPropertiesCollection::create(element);
+#endif
+        } else
+            collection = HTMLCollection::create(element, type);
+    }
+    return collection.get();
+}
+
+HTMLCollection* Element::cachedHTMLCollection(CollectionType type)
+{
+    return hasRareData() ? elementRareData()->cachedHTMLCollection(type) : 0;
+}
+
 IntSize Element::savedLayerScrollOffset() const
 {
     return hasRareData() ? elementRareData()->m_savedLayerScrollOffset : IntSize();
index e4f70cf..67cad52 100644 (file)
@@ -448,6 +448,7 @@ protected:
     virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
 
     HTMLCollection* ensureCachedHTMLCollection(CollectionType);
+    HTMLCollection* cachedHTMLCollection(CollectionType);
 
 private:
     void updateInvalidAttributes() const;
index 8e7bcbc..68c8cc6 100644 (file)
 #include "DatasetDOMStringMap.h"
 #include "Element.h"
 #include "ElementShadow.h"
-#include "HTMLCollection.h"
 #include "NamedNodeMap.h"
 #include "NodeRareData.h"
 #include <wtf/OwnPtr.h>
 
 namespace WebCore {
 
+class HTMLCollection;
+
 class ElementRareData : public NodeRareData {
 public:
     ElementRareData();
@@ -50,15 +51,13 @@ public:
         return m_cachedCollections;
     }
 
-    HTMLCollection* ensureCachedHTMLCollection(Element* element, CollectionType type)
+    HTMLCollection* ensureCachedHTMLCollection(Element*, CollectionType);
+    HTMLCollection* cachedHTMLCollection(CollectionType type)
     {
         if (!m_cachedCollections)
-            m_cachedCollections = adoptPtr(new CachedHTMLCollectionArray);
+            return 0;
 
-        OwnPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
-        if (!collection)
-            collection = HTMLCollection::create(element, type);
-        return collection.get();
+        return (*m_cachedCollections)[type - FirstNodeCollectionType].get();
     }
 
     OwnPtr<CachedHTMLCollectionArray> m_cachedCollections;
index 79ef6b8..42dd215 100644 (file)
@@ -2778,10 +2778,6 @@ void Node::setItemType(const String& value)
     ensureRareData()->setItemType(value);
 }
 
-HTMLPropertiesCollection* Node::properties()
-{
-    return ensureRareData()->properties(this);
-}
 #endif
 
 void NodeRareData::createNodeLists(Node* node)
index 8c477c0..7fb0b8d 100644 (file)
@@ -630,7 +630,6 @@ public:
     DOMSettableTokenList* itemProp();
     DOMSettableTokenList* itemRef();
     DOMSettableTokenList* itemType();
-    HTMLPropertiesCollection* properties();
 #endif
 
 #if ENABLE(MUTATION_OBSERVERS)
index b7f359e..edb2d69 100644 (file)
@@ -305,14 +305,6 @@ public:
 
         m_itemType->setValue(value);
     }
-
-    HTMLPropertiesCollection* properties(Node* node)
-    {
-        if (!m_properties)
-            m_properties = HTMLPropertiesCollection::create(node);
-
-        return m_properties.get();
-    }
 #endif
 
 #if ENABLE(STYLE_SCOPED)
@@ -368,7 +360,6 @@ private:
     mutable RefPtr<DOMSettableTokenList> m_itemProp;
     mutable RefPtr<DOMSettableTokenList> m_itemRef;
     mutable RefPtr<DOMSettableTokenList> m_itemType;
-    mutable OwnPtr<HTMLPropertiesCollection> m_properties;
 #endif
 
 #if ENABLE(STYLE_SCOPED)
index 5bed4d8..7b2b32b 100644 (file)
@@ -49,6 +49,7 @@ enum CollectionType {
     NodeChildren, // first-level children (IE)
     TableTBodies, // all <tbody> elements in this table
     TSectionRows, // all row elements in this table section
+    TableRows,
     TRCells,      // all cells in this row
     SelectOptions,
     SelectedOptions,
@@ -59,15 +60,14 @@ enum CollectionType {
     ItemProperties, // Microdata item properties in the document
 #endif
 
-    FormControls,
-    OtherCollection
+    FormControls
 };
 
 static const CollectionType FirstUnnamedDocumentCachedType = DocImages;
 static const unsigned NumUnnamedDocumentCachedTypes = WindowNamedItems - DocImages + 1;
 
 static const CollectionType FirstNodeCollectionType = NodeChildren;
-static const unsigned NumNodeCollectionTypes = OtherCollection - NodeChildren + 1;
+static const unsigned NumNodeCollectionTypes = FormControls - NodeChildren + 1;
 
 } // namespace
 
index 19604e1..ecf623a 100644 (file)
@@ -50,7 +50,7 @@ static bool shouldIncludeChildren(CollectionType type)
     case DocScripts:
     case DocumentNamedItems:
     case MapAreas:
-    case OtherCollection:
+    case TableRows:
     case SelectOptions:
     case SelectedOptions:
     case DataListOptions:
@@ -151,7 +151,7 @@ inline bool HTMLCollection::isAcceptableElement(Element* element) const
 #endif
     case FormControls:
     case DocumentNamedItems:
-    case OtherCollection:
+    case TableRows:
     case WindowNamedItems:
         ASSERT_NOT_REACHED();
     }
index 50152ca..e92e956 100644 (file)
@@ -987,6 +987,11 @@ void HTMLElement::setItemValueText(const String& value, ExceptionCode& ec)
 {
     setTextContent(value, ec);
 }
+
+HTMLPropertiesCollection* HTMLElement::properties()
+{
+    return ensureCachedHTMLCollection(ItemProperties);
+}
 #endif
 
 void HTMLElement::addHTMLLengthToStyle(StylePropertySet* style, CSSPropertyID propertyID, const String& value)
index 4eeab8c..6858dfc 100644 (file)
@@ -96,6 +96,7 @@ public:
 #if ENABLE(MICRODATA)
     void setItemValue(const String&, ExceptionCode&);
     PassRefPtr<MicroDataItemValue> itemValue() const;
+    HTMLPropertiesCollection* properties();
 #endif
 
 #ifndef NDEBUG
index 9033d2a..1eed9e4 100644 (file)
@@ -99,9 +99,7 @@ HTMLLegendElement* HTMLFieldSetElement::legend() const
 
 HTMLCollection* HTMLFieldSetElement::elements()
 {
-    if (!m_elementsCollection)
-        m_elementsCollection = HTMLFormCollection::create(this);
-    return m_elementsCollection.get();
+    return ensureCachedHTMLCollection(FormControls);
 }
 
 void HTMLFieldSetElement::refreshElementsIfNeeded() const
index ea56a1c..875abea 100644 (file)
@@ -59,7 +59,6 @@ private:
     static void invalidateDisabledStateUnder(Element*);
     void refreshElementsIfNeeded() const;
 
-    OwnPtr<HTMLFormCollection> m_elementsCollection;
     mutable Vector<FormAssociatedElement*> m_associatedElements;
     // When dom tree is modified, we have to refresh the m_associatedElements array.
     mutable uint64_t m_documentVersion;
index ad0aa16..b6796f9 100644 (file)
@@ -36,12 +36,13 @@ using namespace HTMLNames;
 // Since the collections are to be "live", we have to do the
 // calculation every time if anything has changed.
 
-HTMLFormCollection::HTMLFormCollection(HTMLElement* base)
+HTMLFormCollection::HTMLFormCollection(Element* base)
     : HTMLCollection(base, FormControls)
 {
+    ASSERT(base->hasTagName(formTag) || base->hasTagName(fieldsetTag));
 }
 
-PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLElement* base)
+PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(Element* base)
 {
     return adoptPtr(new HTMLFormCollection(base));
 }
index 0697946..99329a3 100644 (file)
@@ -36,7 +36,7 @@ class QualifiedName;
 
 class HTMLFormCollection : public HTMLCollection {
 public:
-    static PassOwnPtr<HTMLFormCollection> create(HTMLElement*);
+    static PassOwnPtr<HTMLFormCollection> create(Element*);
 
     virtual ~HTMLFormCollection();
 
@@ -44,7 +44,7 @@ public:
     virtual Node* namedItem(const AtomicString& name) const;
 
 private:
-    HTMLFormCollection(HTMLElement*);
+    HTMLFormCollection(Element*);
 
     virtual void updateNameCache() const;
     virtual unsigned calcLength() const;
index 41d1d2d..b267456 100644 (file)
@@ -537,9 +537,7 @@ void HTMLFormElement::removeImgElement(HTMLImageElement* e)
 
 HTMLCollection* HTMLFormElement::elements()
 {
-    if (!m_elementsCollection)
-        m_elementsCollection = HTMLFormCollection::create(this);
-    return m_elementsCollection.get();
+    return ensureCachedHTMLCollection(FormControls);
 }
 
 String HTMLFormElement::name() const
index c12c9aa..b193b57 100644 (file)
@@ -150,7 +150,6 @@ private:
 
     FormSubmission::Attributes m_attributes;
     OwnPtr<AliasMap> m_elementAliases;
-    OwnPtr<HTMLFormCollection> m_elementsCollection;
 
     CheckedRadioButtons m_checkedRadioButtons;
 
index ca8a1b0..805fe9a 100644 (file)
 
 namespace WebCore {
 
-HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement* select)
+HTMLOptionsCollection::HTMLOptionsCollection(Element* select)
     : HTMLCollection(select, SelectOptions)
 {
+    ASSERT(select->hasTagName(HTMLNames::selectTag));
 }
 
-PassOwnPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(HTMLSelectElement* select)
+PassOwnPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(Element* select)
 {
     return adoptPtr(new HTMLOptionsCollection(select));
 }
index bc9bdfa..987532c 100644 (file)
@@ -35,7 +35,7 @@ typedef int ExceptionCode;
 
 class HTMLOptionsCollection : public HTMLCollection {
 public:
-    static PassOwnPtr<HTMLOptionsCollection> create(HTMLSelectElement*);
+    static PassOwnPtr<HTMLOptionsCollection> create(Element*);
 
     void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&);
     void add(PassRefPtr<HTMLOptionElement>, int index, ExceptionCode&);
@@ -49,7 +49,7 @@ public:
     using HTMLCollection::invalidateCacheIfNeeded;
 
 private:
-    HTMLOptionsCollection(HTMLSelectElement*);
+    HTMLOptionsCollection(Element*);
 };
 
 } //namespace
index 9936719..e27616e 100644 (file)
@@ -352,16 +352,12 @@ bool HTMLSelectElement::childShouldCreateRenderer(const NodeRenderingContext& ch
 
 HTMLCollection* HTMLSelectElement::selectedOptions()
 {
-    if (!m_selectedOptionsCollection)
-        m_selectedOptionsCollection = HTMLCollection::create(this, SelectedOptions);
-    return m_selectedOptionsCollection.get();
+    return ensureCachedHTMLCollection(SelectedOptions);
 }
 
 HTMLOptionsCollection* HTMLSelectElement::options()
 {
-    if (!m_optionsCollection)
-        m_optionsCollection = HTMLOptionsCollection::create(this);
-    return m_optionsCollection.get();
+    return static_cast<HTMLOptionsCollection*>(ensureCachedHTMLCollection(SelectOptions));
 }
 
 void HTMLSelectElement::updateListItemSelectedStates()
@@ -709,8 +705,8 @@ const Vector<HTMLElement*>& HTMLSelectElement::listItems() const
 
 void HTMLSelectElement::invalidateSelectedItems()
 {
-    if (m_selectedOptionsCollection)
-        m_selectedOptionsCollection->invalidateCache();
+    if (HTMLCollection* collection = cachedHTMLCollection(SelectedOptions))
+        collection->invalidateCache();
 }
 
 void HTMLSelectElement::setRecalcListItems()
@@ -720,10 +716,12 @@ void HTMLSelectElement::setRecalcListItems()
     m_activeSelectionAnchorIndex = -1;
     setOptionsChangedOnRenderer();
     setNeedsStyleRecalc();
-    if (!inDocument() && m_optionsCollection)
-        m_optionsCollection->invalidateCacheIfNeeded();
-    if (!inDocument() && m_selectedOptionsCollection)
-        m_selectedOptionsCollection->invalidateCacheIfNeeded();
+    if (!inDocument()) {
+        if (HTMLCollection* collection = cachedHTMLCollection(SelectOptions))
+            collection->invalidateCache();
+    }
+    if (!inDocument())
+        invalidateSelectedItems();
 }
 
 void HTMLSelectElement::recalcListItems(bool updateSelectedStates) const
index 3ea24c1..d4b355a 100644 (file)
@@ -180,9 +180,6 @@ private:
 
     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
 
-    OwnPtr<HTMLOptionsCollection> m_optionsCollection;
-    OwnPtr<HTMLCollection> m_selectedOptionsCollection;
-
     // m_listItems contains HTMLOptionElement, HTMLOptGroupElement, and HTMLHRElement objects.
     mutable Vector<HTMLElement*> m_listItems;
     Vector<bool> m_lastOnChangeSelection;
index a6fa17d..bf53055 100644 (file)
@@ -562,9 +562,7 @@ bool HTMLTableElement::isURLAttribute(const Attribute& attribute) const
 
 HTMLCollection* HTMLTableElement::rows()
 {
-    if (!m_rowsCollection)
-        m_rowsCollection = HTMLTableRowsCollection::create(this);
-    return m_rowsCollection.get();
+    return ensureCachedHTMLCollection(TableRows);
 }
 
 HTMLCollection* HTMLTableElement::tBodies()
index d492b54..7da4e41 100644 (file)
@@ -97,7 +97,6 @@ private:
                                 // are present, to none otherwise).
 
     unsigned short m_padding;
-    OwnPtr<HTMLTableRowsCollection> m_rowsCollection;
     RefPtr<StylePropertySet> m_sharedCellStyle;
 };
 
index 8041034..15019ca 100644 (file)
@@ -151,12 +151,13 @@ HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table)
 // Must call get() on the table in case that argument is compiled before dereferencing the
 // table to get at the collection cache. Order of argument evaluation is undefined and can
 // differ between compilers.
-HTMLTableRowsCollection::HTMLTableRowsCollection(HTMLTableElement* table)
-    : HTMLCollection(table, OtherCollection)
+HTMLTableRowsCollection::HTMLTableRowsCollection(Element* table)
+    : HTMLCollection(table, TableRows)
 {
+    ASSERT(table->hasTagName(tableTag));
 }
 
-PassOwnPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(HTMLTableElement* table)
+PassOwnPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(Element* table)
 {
     return adoptPtr(new HTMLTableRowsCollection(table));
 }
index dfe53e5..a082a0b 100644 (file)
@@ -38,13 +38,13 @@ class HTMLTableRowElement;
 
 class HTMLTableRowsCollection : public HTMLCollection {
 public:
-    static PassOwnPtr<HTMLTableRowsCollection> create(HTMLTableElement*);
+    static PassOwnPtr<HTMLTableRowsCollection> create(Element*);
 
     static HTMLTableRowElement* rowAfter(HTMLTableElement*, HTMLTableRowElement*);
     static HTMLTableRowElement* lastRow(HTMLTableElement*);
 
 private:
-    HTMLTableRowsCollection(HTMLTableElement*);
+    HTMLTableRowsCollection(Element*);
 
     virtual Element* itemAfter(Node*) const OVERRIDE;
 };