Simplify HTMLCollection ownership model.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jan 2012 09:35:21 +0000 (09:35 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jan 2012 09:35:21 +0000 (09:35 +0000)
commitc3cddc200fc0f62170b2312093b1ac9ea93886dc
treeac9a993346b85a8a3a46ce0f2892e991142d77e9
parent3f7533598e9f047ca690566ce6078f46557c8247
Simplify HTMLCollection ownership model.
<http://webkit.org/b/75437>

Reviewed by Sam Weinig.

Source/WebCore:

Remove HTMLCollection's inheritance from RefCounted and use OwnPtr to store it.
Added ref()/deref() methods that forward to the collection's base node, these
are only ever used by DOM wrappers.

This is a behavior change, HTMLCollection wrappers now keep the base node alive.

Test: fast/dom/htmlcollection-protects-base.html

* html/HTMLCollection.h:
(WebCore::HTMLCollection::ref):
(WebCore::HTMLCollection::deref):

    Removed inheritance from RefCounted. Added ref/deref that forward the refs
    to the collection's base Node.

* dom/Element.cpp:
(WebCore::Element::~Element):
* dom/Document.h:
* dom/Document.cpp:
(WebCore::Document::~Document):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::~HTMLFormElement):
* html/HTMLSelectElement.h:
* html/HTMLSelectElement.cpp:

    Remove HTMLCollection::detachFromNode() and call sites.

* html/HTMLAllCollection.cpp:
(WebCore::HTMLAllCollection::namedItemWithIndex):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::HTMLCollection::invalidateCacheIfNeeded):
(WebCore::HTMLCollection::itemAfter):
(WebCore::HTMLCollection::calcLength):
(WebCore::HTMLCollection::length):
(WebCore::HTMLCollection::item):
(WebCore::HTMLCollection::nextItem):
(WebCore::HTMLCollection::namedItem):
(WebCore::HTMLCollection::updateNameCache):
(WebCore::HTMLCollection::hasNamedItem):
(WebCore::HTMLCollection::namedItems):
(WebCore::HTMLCollection::tags):
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::calcLength):
(WebCore::HTMLFormCollection::item):
(WebCore::HTMLFormCollection::getNamedItem):
(WebCore::HTMLFormCollection::namedItem):
(WebCore::HTMLFormCollection::updateNameCache):
* html/HTMLNameCollection.cpp:
(WebCore::HTMLNameCollection::itemAfter):
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::add):
(WebCore::HTMLOptionsCollection::remove):
(WebCore::HTMLOptionsCollection::selectedIndex):
(WebCore::HTMLOptionsCollection::setSelectedIndex):
(WebCore::HTMLOptionsCollection::setLength):
* html/HTMLPropertiesCollection.cpp:
(WebCore::HTMLPropertiesCollection::length):
(WebCore::HTMLPropertiesCollection::item):
(WebCore::HTMLPropertiesCollection::names):

    Removed base node null-checks and assertions. Added one assertion to
    the HTMLCollection constructor (that m_base is non-null.)

* dom/Document.h:
* dom/Document.cpp:
(WebCore::Document::openSearchDescriptionURL):
(WebCore::Document::cachedCollection):
(WebCore::Document::images):
(WebCore::Document::applets):
(WebCore::Document::embeds):
(WebCore::Document::plugins):
(WebCore::Document::objects):
(WebCore::Document::scripts):
(WebCore::Document::links):
(WebCore::Document::forms):
(WebCore::Document::anchors):
(WebCore::Document::all):
(WebCore::Document::windowNamedItems):
(WebCore::Document::documentNamedItems):
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::namedItemGetter):
* bindings/js/JSHTMLDocumentCustom.cpp:
(WebCore::JSHTMLDocument::nameGetter):
(WebCore::JSHTMLDocument::all):
* bindings/v8/custom/V8DOMWindowCustom.cpp:
(WebCore::V8DOMWindow::namedPropertyGetter):
* bindings/v8/custom/V8HTMLDocumentCustom.cpp:
(WebCore::V8HTMLDocument::GetNamedProperty):
* dom/ElementRareData.h:
(WebCore::ElementRareData::ensureCachedHTMLCollection):
* dom/NodeRareData.h:
(WebCore::NodeRareData::properties):
* html/HTMLAllCollection.h:
* html/HTMLAllCollection.cpp:
(WebCore::HTMLAllCollection::create):
* html/HTMLCollection.h:
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::create):
(WebCore::HTMLCollection::HTMLCollection):
* html/HTMLDataListElement.cpp:
(WebCore::HTMLDataListElement::options):
* html/HTMLDataListElement.h:
* html/HTMLElement.cpp:
(WebCore::HTMLElement::children):
* html/HTMLElement.h:
* html/HTMLSelectElement.h:
(WebCore::HTMLSelectElement::options):
* html/HTMLFormCollection.h:
* html/HTMLFormElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::elements):
* html/HTMLNameCollection.h:
(WebCore::HTMLNameCollection::create):
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::create):
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::imageElement):
(WebCore::HTMLMapElement::areas):
* html/HTMLMapElement.h:
* html/HTMLPropertiesCollection.h:
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::rows):
(WebCore::HTMLTableElement::tBodies):
* html/HTMLTableElement.h:
* html/HTMLTableRowElement.cpp:
(WebCore::HTMLTableRowElement::insertCell):
(WebCore::HTMLTableRowElement::deleteCell):
(WebCore::HTMLTableRowElement::cells):
* html/HTMLTableRowElement.h:
* html/HTMLTableRowsCollection.cpp:
(WebCore::HTMLTableRowsCollection::create):
(WebCore::HTMLTableRowsCollection::itemAfter):
* html/HTMLTableRowsCollection.h:
* html/HTMLTableSectionElement.h:
* html/HTMLTableSectionElement.cpp:
(WebCore::HTMLTableSectionElement::insertRow):
(WebCore::HTMLTableSectionElement::deleteRow):
(WebCore::HTMLTableSectionElement::rows):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::selectedOption):
* html/HTMLOptionsCollection.h:
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::create):
* html/HTMLPropertiesCollection.cpp:
(WebCore::HTMLPropertiesCollection::create):
* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::getDocumentLinks):

    Store cached HTMLCollections in OwnPtrs. Methods that used to return
    PassRefPtr<HTMLCollection> now simply return HTMLCollection*.
    Updated call sites as appropriate.

LayoutTests:

- Removed fast/dom/htmlcollection-zombies.html since it was testing bogus behavior.
- Added a test to verify that HTMLCollection protects its base node from GC.

* fast/dom/htmlcollection-protects-base-expected.txt: Added.
* fast/dom/htmlcollection-protects-base.html: Added.
* fast/dom/htmlcollection-zombies-expected.txt: Removed.
* fast/dom/htmlcollection-zombies.html: Removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@104383 268f45cc-cd09-0410-ab3c-d52691b4dbfc
47 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/htmlcollection-protects-base-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/htmlcollection-protects-base.html [new file with mode: 0644]
LayoutTests/fast/dom/htmlcollection-zombies-expected.txt [deleted file]
LayoutTests/fast/dom/htmlcollection-zombies.html [deleted file]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp
Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/ElementRareData.h
Source/WebCore/dom/NodeRareData.h
Source/WebCore/html/HTMLAllCollection.cpp
Source/WebCore/html/HTMLAllCollection.h
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLCollection.h
Source/WebCore/html/HTMLDataListElement.cpp
Source/WebCore/html/HTMLDataListElement.h
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLElement.h
Source/WebCore/html/HTMLFormCollection.cpp
Source/WebCore/html/HTMLFormCollection.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLMapElement.cpp
Source/WebCore/html/HTMLMapElement.h
Source/WebCore/html/HTMLNameCollection.cpp
Source/WebCore/html/HTMLNameCollection.h
Source/WebCore/html/HTMLOptionsCollection.cpp
Source/WebCore/html/HTMLOptionsCollection.h
Source/WebCore/html/HTMLPropertiesCollection.cpp
Source/WebCore/html/HTMLPropertiesCollection.h
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLSelectElement.h
Source/WebCore/html/HTMLTableElement.cpp
Source/WebCore/html/HTMLTableElement.h
Source/WebCore/html/HTMLTableRowElement.cpp
Source/WebCore/html/HTMLTableRowElement.h
Source/WebCore/html/HTMLTableRowsCollection.cpp
Source/WebCore/html/HTMLTableRowsCollection.h
Source/WebCore/html/HTMLTableSectionElement.cpp
Source/WebCore/html/HTMLTableSectionElement.h