Unreviewed, rolling out r104373 and r104374.

http://trac.webkit.org/changeset/104373
http://trac.webkit.org/changeset/104374
https://bugs.webkit.org/show_bug.cgi?id=75769

Too many assertion failures. (Requested by kling on #webkit).

Patch by Sheriff Bot <webkit.review.bot@gmail.com> on 2012-01-06

Source/WebCore:

* 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/Document.cpp:
(WebCore::Document::~Document):
(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):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::~Element):
* dom/ElementRareData.h:
(WebCore::ElementRareData::cachedHTMLCollection):
(WebCore::ElementRareData::ensureCachedHTMLCollection):
* dom/NodeRareData.h:
(WebCore::NodeRareData::properties):
* html/HTMLAllCollection.cpp:
(WebCore::HTMLAllCollection::create):
(WebCore::HTMLAllCollection::namedItemWithIndex):
* html/HTMLAllCollection.h:
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::HTMLCollection::create):
(WebCore::HTMLCollection::detachFromNode):
(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/HTMLCollection.h:
* html/HTMLDataListElement.cpp:
(WebCore::HTMLDataListElement::options):
* html/HTMLDataListElement.h:
* html/HTMLElement.cpp:
(WebCore::HTMLElement::children):
* html/HTMLElement.h:
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::create):
(WebCore::HTMLFormCollection::calcLength):
(WebCore::HTMLFormCollection::item):
(WebCore::HTMLFormCollection::getNamedItem):
(WebCore::HTMLFormCollection::namedItem):
(WebCore::HTMLFormCollection::updateNameCache):
* html/HTMLFormCollection.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::~HTMLFormElement):
(WebCore::HTMLFormElement::elements):
* html/HTMLFormElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::selectedOption):
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::imageElement):
(WebCore::HTMLMapElement::areas):
* html/HTMLMapElement.h:
* html/HTMLNameCollection.cpp:
(WebCore::HTMLNameCollection::itemAfter):
* html/HTMLNameCollection.h:
(WebCore::HTMLNameCollection::create):
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::create):
(WebCore::HTMLOptionsCollection::add):
(WebCore::HTMLOptionsCollection::remove):
(WebCore::HTMLOptionsCollection::selectedIndex):
(WebCore::HTMLOptionsCollection::setSelectedIndex):
(WebCore::HTMLOptionsCollection::setLength):
* html/HTMLOptionsCollection.h:
* html/HTMLPropertiesCollection.cpp:
(WebCore::HTMLPropertiesCollection::create):
(WebCore::HTMLPropertiesCollection::length):
(WebCore::HTMLPropertiesCollection::item):
(WebCore::HTMLPropertiesCollection::names):
* html/HTMLPropertiesCollection.h:
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::~HTMLSelectElement):
(WebCore::HTMLSelectElement::options):
* html/HTMLSelectElement.h:
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::~HTMLTableElement):

LayoutTests:

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

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104376 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2cd8d015
2012-01-06 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r104373 and r104374.
http://trac.webkit.org/changeset/104373
http://trac.webkit.org/changeset/104374
https://bugs.webkit.org/show_bug.cgi?id=75769
Too many assertion failures. (Requested by kling on #webkit).
* fast/dom/htmlcollection-protects-base-expected.txt: Removed.
* fast/dom/htmlcollection-protects-base.html: Removed.
* fast/dom/htmlcollection-zombies-expected.txt: Added.
* fast/dom/htmlcollection-zombies.html: Added.
2012-01-06 Andreas Kling <awesomekling@apple.com>
Simplify HTMLCollection ownership model.
This test verifies that a HTMLCollection protects its base node from being GC'd.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS options[0].parentNode.getAttribute('foo') is 'bar'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<select foo="bar">
<option name="A">A</option>
</select>
<script>
description("This test verifies that a HTMLCollection protects its base node from being GC'd.");
options = document.getElementsByTagName("select")[0].options;
document.body.removeChild(document.getElementsByTagName("select")[0]);
gc();
options[0] = new Option("bik", "bok");
shouldBe("options[0].parentNode.getAttribute('foo')", "'bar'");
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
This test tests the behavior of collections after their base node has been destroyed.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Testing selectElement's options collection.
PASS collection.length is 2
PASS collection[0].getAttribute('name') is 'foo'
PASS collection[1].getAttribute('name') is 'bar'
Destroying selectElement
PASS collection.length is 0
PASS collection[0] is undefined
Testing formElement's elements collection.
PASS collection.length is 2
PASS collection[0].getAttribute('name') is 'foo'
PASS collection[1].getAttribute('name') is 'bar'
Destroying formElement
PASS collection.length is 0
PASS collection[0] is undefined
Testing tableElement's rows collection.
PASS collection.length is 2
PASS collection[0].getAttribute('name') is 'foo'
PASS collection[1].getAttribute('name') is 'bar'
Destroying tableElement
PASS collection.length is 0
PASS collection[0] is undefined
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<select id="selectElement">
<option name="foo"/>
<option name="bar"/>
</select>
<form id="formElement">
<input name="foo"/>
<input name="bar"/>
</form>
<table id="tableElement">
<tr name="foo"></tr>
<tr name="bar"></tr>
</table>
<script>
description("This test tests the behavior of collections after their base node has been destroyed.");
var element;
var collection;
function testZombieBehavior(id, collectionGetterName)
{
debug("Testing " + id + "'s " + collectionGetterName + " collection.");
element = document.getElementById(id);
collection = eval("element." + collectionGetterName);
shouldBe("collection.length", "2");
shouldBe("collection[0].getAttribute('name')", "'foo'");
shouldBe("collection[1].getAttribute('name')", "'bar'");
debug("Destroying " + id);
document.body.removeChild(element);
element = null;
gc();
shouldBe("collection.length", "0");
shouldBe("collection[0]", "undefined");
}
testZombieBehavior("selectElement", "options");
testZombieBehavior("formElement", "elements");
testZombieBehavior("tableElement", "rows");
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
2012-01-06 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r104373 and r104374.
http://trac.webkit.org/changeset/104373
http://trac.webkit.org/changeset/104374
https://bugs.webkit.org/show_bug.cgi?id=75769
Too many assertion failures. (Requested by kling on #webkit).
* 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/Document.cpp:
(WebCore::Document::~Document):
(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):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::~Element):
* dom/ElementRareData.h:
(WebCore::ElementRareData::cachedHTMLCollection):
(WebCore::ElementRareData::ensureCachedHTMLCollection):
* dom/NodeRareData.h:
(WebCore::NodeRareData::properties):
* html/HTMLAllCollection.cpp:
(WebCore::HTMLAllCollection::create):
(WebCore::HTMLAllCollection::namedItemWithIndex):
* html/HTMLAllCollection.h:
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::HTMLCollection::create):
(WebCore::HTMLCollection::detachFromNode):
(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/HTMLCollection.h:
* html/HTMLDataListElement.cpp:
(WebCore::HTMLDataListElement::options):
* html/HTMLDataListElement.h:
* html/HTMLElement.cpp:
(WebCore::HTMLElement::children):
* html/HTMLElement.h:
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::create):
(WebCore::HTMLFormCollection::calcLength):
(WebCore::HTMLFormCollection::item):
(WebCore::HTMLFormCollection::getNamedItem):
(WebCore::HTMLFormCollection::namedItem):
(WebCore::HTMLFormCollection::updateNameCache):
* html/HTMLFormCollection.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::~HTMLFormElement):
(WebCore::HTMLFormElement::elements):
* html/HTMLFormElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::selectedOption):
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::imageElement):
(WebCore::HTMLMapElement::areas):
* html/HTMLMapElement.h:
* html/HTMLNameCollection.cpp:
(WebCore::HTMLNameCollection::itemAfter):
* html/HTMLNameCollection.h:
(WebCore::HTMLNameCollection::create):
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::create):
(WebCore::HTMLOptionsCollection::add):
(WebCore::HTMLOptionsCollection::remove):
(WebCore::HTMLOptionsCollection::selectedIndex):
(WebCore::HTMLOptionsCollection::setSelectedIndex):
(WebCore::HTMLOptionsCollection::setLength):
* html/HTMLOptionsCollection.h:
* html/HTMLPropertiesCollection.cpp:
(WebCore::HTMLPropertiesCollection::create):
(WebCore::HTMLPropertiesCollection::length):
(WebCore::HTMLPropertiesCollection::item):
(WebCore::HTMLPropertiesCollection::names):
* html/HTMLPropertiesCollection.h:
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::~HTMLSelectElement):
(WebCore::HTMLSelectElement::options):
* html/HTMLSelectElement.h:
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::~HTMLTableElement):
2012-01-06 Andreas Kling <awesomekling@apple.com>
Unreviewed build fix after r104373.
......@@ -115,10 +115,10 @@ static JSValue namedItemGetter(ExecState* exec, JSValue slotBase, const Identifi
ASSERT(document);
ASSERT(document->isHTMLDocument());
HTMLCollection* collection = document->windowNamedItems(identifierToAtomicString(propertyName));
RefPtr<HTMLCollection> collection = document->windowNamedItems(identifierToAtomicString(propertyName));
if (collection->length() == 1)
return toJS(exec, thisObj, collection->firstItem());
return toJS(exec, thisObj, collection);
return toJS(exec, thisObj, collection.get());
}
bool JSDOMWindow::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
......
......@@ -61,7 +61,7 @@ JSValue JSHTMLDocument::nameGetter(ExecState* exec, JSValue slotBase, const Iden
JSHTMLDocument* thisObj = static_cast<JSHTMLDocument*>(asObject(slotBase));
HTMLDocument* document = static_cast<HTMLDocument*>(thisObj->impl());
HTMLCollection* collection = document->documentNamedItems(identifierToAtomicString(propertyName));
RefPtr<HTMLCollection> collection = document->documentNamedItems(identifierToAtomicString(propertyName));
unsigned length = collection->length();
if (!length)
......@@ -77,7 +77,7 @@ JSValue JSHTMLDocument::nameGetter(ExecState* exec, JSValue slotBase, const Iden
return toJS(exec, thisObj->globalObject(), node);
}
return toJS(exec, thisObj->globalObject(), collection);
return toJS(exec, thisObj->globalObject(), collection.get());
}
// Custom attributes
......@@ -89,7 +89,7 @@ JSValue JSHTMLDocument::all(ExecState* exec) const
if (v)
return v;
return toJS(exec, globalObject(), static_cast<HTMLDocument*>(impl())->all());
return toJS(exec, globalObject(), static_cast<HTMLDocument*>(impl())->all().get());
}
void JSHTMLDocument::setAll(ExecState* exec, JSValue value)
......
......@@ -512,11 +512,11 @@ v8::Handle<v8::Value> V8DOMWindow::namedPropertyGetter(v8::Local<v8::String> nam
if (doc && doc->isHTMLDocument()) {
if (static_cast<HTMLDocument*>(doc)->hasNamedItem(propName.impl()) || doc->hasElementWithId(propName.impl())) {
HTMLCollection* items = doc->windowNamedItems(propName);
RefPtr<HTMLCollection> items = doc->windowNamedItems(propName);
if (items->length() >= 1) {
if (items->length() == 1)
return toV8(items->firstItem());
return toV8(items);
return toV8(items.release());
}
}
}
......
......@@ -79,7 +79,7 @@ v8::Handle<v8::Value> V8HTMLDocument::GetNamedProperty(HTMLDocument* htmlDocumen
if (!htmlDocument->hasNamedItem(key.impl()) && !htmlDocument->hasExtraNamedItem(key.impl()))
return v8::Handle<v8::Value>();
HTMLCollection* items = htmlDocument->documentNamedItems(key);
RefPtr<HTMLCollection> items = htmlDocument->documentNamedItems(key);
if (!items->length())
return v8::Handle<v8::Value>();
......@@ -92,7 +92,7 @@ v8::Handle<v8::Value> V8HTMLDocument::GetNamedProperty(HTMLDocument* htmlDocumen
return toV8(node);
}
return toV8(items);
return toV8(items.release());
}
// HTMLDocument ----------------------------------------------------------------
......
......@@ -567,6 +567,14 @@ Document::~Document()
if (m_mediaQueryMatcher)
m_mediaQueryMatcher->documentDestroyed();
for (unsigned i = 0; i < NumUnnamedDocumentCachedTypes; ++i) {
if (m_collections[i])
m_collections[i]->detachFromNode();
}
if (m_allCollection)
m_allCollection->detachFromNode();
}
void Document::removedLastRef()
......@@ -4168,7 +4176,7 @@ KURL Document::openSearchDescriptionURL()
if (!head())
return KURL();
HTMLCollection* children = head()->children();
RefPtr<HTMLCollection> children = head()->children();
for (Node* child = children->firstItem(); child; child = children->nextItem()) {
if (!child->hasTagName(linkTag))
continue;
......@@ -4293,81 +4301,81 @@ bool Document::hasSVGRootNode() const
}
#endif
HTMLCollection* Document::cachedCollection(CollectionType type)
const RefPtr<HTMLCollection>& Document::cachedCollection(CollectionType type)
{
ASSERT(static_cast<unsigned>(type) < NumUnnamedDocumentCachedTypes);
if (!m_collections[type])
m_collections[type] = HTMLCollection::create(this, type);
return m_collections[type].get();
return m_collections[type];
}
HTMLCollection* Document::images()
PassRefPtr<HTMLCollection> Document::images()
{
return cachedCollection(DocImages);
}
HTMLCollection* Document::applets()
PassRefPtr<HTMLCollection> Document::applets()
{
return cachedCollection(DocApplets);
}
HTMLCollection* Document::embeds()
PassRefPtr<HTMLCollection> Document::embeds()
{
return cachedCollection(DocEmbeds);
}
HTMLCollection* Document::plugins()
PassRefPtr<HTMLCollection> Document::plugins()
{
// This is an alias for embeds() required for the JS DOM bindings.
return cachedCollection(DocEmbeds);
}
HTMLCollection* Document::objects()
PassRefPtr<HTMLCollection> Document::objects()
{
return cachedCollection(DocObjects);
}
HTMLCollection* Document::scripts()
PassRefPtr<HTMLCollection> Document::scripts()
{
return cachedCollection(DocScripts);
}
HTMLCollection* Document::links()
PassRefPtr<HTMLCollection> Document::links()
{
return cachedCollection(DocLinks);
}
HTMLCollection* Document::forms()
PassRefPtr<HTMLCollection> Document::forms()
{
return cachedCollection(DocForms);
}
HTMLCollection* Document::anchors()
PassRefPtr<HTMLCollection> Document::anchors()
{
return cachedCollection(DocAnchors);
}
HTMLAllCollection* Document::all()
PassRefPtr<HTMLAllCollection> Document::all()
{
if (!m_allCollection)
m_allCollection = HTMLAllCollection::create(this);
return m_allCollection.get();
return m_allCollection;
}
HTMLCollection* Document::windowNamedItems(const AtomicString& name)
PassRefPtr<HTMLCollection> Document::windowNamedItems(const AtomicString& name)
{
OwnPtr<HTMLNameCollection>& collection = m_windowNamedItemCollections.add(name.impl(), nullptr).first->second;
RefPtr<HTMLNameCollection>& collection = m_windowNamedItemCollections.add(name.impl(), 0).first->second;
if (!collection)
collection = HTMLNameCollection::create(this, WindowNamedItems, name);
return collection.get();
return collection;
}
HTMLCollection* Document::documentNamedItems(const AtomicString& name)
PassRefPtr<HTMLCollection> Document::documentNamedItems(const AtomicString& name)
{
OwnPtr<HTMLNameCollection>& collection = m_documentNamedItemCollections.add(name.impl(), nullptr).first->second;
RefPtr<HTMLNameCollection>& collection = m_documentNamedItemCollections.add(name.impl(), 0).first->second;
if (!collection)
collection = HTMLNameCollection::create(this, DocumentNamedItems, name);
return collection.get();
return collection;
}
void Document::finishedParsing()
......
......@@ -410,19 +410,19 @@ public:
PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
HTMLCollection* images();
HTMLCollection* embeds();
HTMLCollection* plugins(); // an alias for embeds() required for the JS DOM bindings.
HTMLCollection* applets();
HTMLCollection* links();
HTMLCollection* forms();
HTMLCollection* anchors();
HTMLCollection* objects();
HTMLCollection* scripts();
HTMLCollection* windowNamedItems(const AtomicString& name);
HTMLCollection* documentNamedItems(const AtomicString& name);
HTMLAllCollection* all();
PassRefPtr<HTMLCollection> images();
PassRefPtr<HTMLCollection> embeds();
PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
PassRefPtr<HTMLCollection> applets();
PassRefPtr<HTMLCollection> links();
PassRefPtr<HTMLCollection> forms();
PassRefPtr<HTMLCollection> anchors();
PassRefPtr<HTMLCollection> objects();
PassRefPtr<HTMLCollection> scripts();
PassRefPtr<HTMLCollection> windowNamedItems(const AtomicString& name);
PassRefPtr<HTMLCollection> documentNamedItems(const AtomicString& name);
PassRefPtr<HTMLAllCollection> all();
// Other methods (not part of DOM)
bool isHTMLDocument() const { return m_isHTML; }
......@@ -1182,7 +1182,7 @@ private:
PageVisibilityState visibilityState() const;
#endif
HTMLCollection* cachedCollection(CollectionType);
const RefPtr<HTMLCollection>& cachedCollection(CollectionType);
int m_guardRefCount;
......@@ -1365,10 +1365,10 @@ private:
CheckedRadioButtons m_checkedRadioButtons;
OwnPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];
OwnPtr<HTMLAllCollection> m_allCollection;
RefPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];
RefPtr<HTMLAllCollection> m_allCollection;
typedef HashMap<AtomicStringImpl*, OwnPtr<HTMLNameCollection> > NamedCollectionMap;
typedef HashMap<AtomicStringImpl*, RefPtr<HTMLNameCollection> > NamedCollectionMap;
NamedCollectionMap m_documentNamedItemCollections;
NamedCollectionMap m_windowNamedItemCollections;
......
......@@ -123,6 +123,16 @@ Element::~Element()
removeShadowRoot();
if (m_attributeMap)
m_attributeMap->detachFromElement();
if (hasRareData()) {
ElementRareData* elementRareData = rareData();
if (elementRareData->hasCachedHTMLCollections()) {
for (unsigned type = 0; type < NumNodeCollectionTypes; ++type) {
if (HTMLCollection* collection = elementRareData->cachedHTMLCollection(static_cast<CollectionType>(FirstNodeCollectionType + type)))
collection->detachFromNode();
}
}
}
}
inline ElementRareData* Element::rareData() const
......
......@@ -43,19 +43,25 @@ public:
using NodeRareData::needsFocusAppearanceUpdateSoonAfterAttach;
using NodeRareData::setNeedsFocusAppearanceUpdateSoonAfterAttach;
typedef FixedArray<OwnPtr<HTMLCollection>, NumNodeCollectionTypes> CachedHTMLCollectionArray;
typedef FixedArray<RefPtr<HTMLCollection>, NumNodeCollectionTypes> CachedHTMLCollectionArray;
bool hasCachedHTMLCollections() const
{
return m_cachedCollections;
}
HTMLCollection* cachedHTMLCollection(CollectionType type) const
{
ASSERT(m_cachedCollections);
return (*m_cachedCollections)[type - FirstNodeCollectionType].get();
}
HTMLCollection* ensureCachedHTMLCollection(Element* element, CollectionType type)
{
if (!m_cachedCollections)
m_cachedCollections = adoptPtr(new CachedHTMLCollectionArray);
OwnPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
RefPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
if (!collection)
collection = HTMLCollection::create(element, type);
return collection.get();
......
......@@ -221,7 +221,7 @@ public:
HTMLPropertiesCollection* properties(Node* node)
{
if (!m_properties)
m_properties = adoptPtr(HTMLPropertiesCollection::create(node));
m_properties = HTMLPropertiesCollection::create(node);
return m_properties.get();
}
......@@ -256,7 +256,7 @@ private:
mutable RefPtr<DOMSettableTokenList> m_itemProp;
mutable RefPtr<DOMSettableTokenList> m_itemRef;
mutable RefPtr<DOMSettableTokenList> m_itemType;
mutable OwnPtr<HTMLPropertiesCollection> m_properties;
mutable RefPtr<HTMLPropertiesCollection> m_properties;
#endif
};
......
......@@ -30,9 +30,9 @@
namespace WebCore {
PassOwnPtr<HTMLAllCollection> HTMLAllCollection::create(Document* document)
PassRefPtr<HTMLAllCollection> HTMLAllCollection::create(Document* document)
{
return adoptPtr(new HTMLAllCollection(document));
return adoptRef(new HTMLAllCollection(document));
}
HTMLAllCollection::HTMLAllCollection(Document* document)
......@@ -46,6 +46,9 @@ HTMLAllCollection::~HTMLAllCollection()
Node* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, unsigned index) const
{
if (!base())
return 0;
invalidateCacheIfNeeded();
updateNameCache();
......
......@@ -32,7 +32,7 @@ namespace WebCore {
class HTMLAllCollection : public HTMLCollection {
public:
static PassOwnPtr<HTMLAllCollection> create(Document*);
static PassRefPtr<HTMLAllCollection> create(Document*);
virtual ~HTMLAllCollection();
Node* namedItemWithIndex(const AtomicString& name, unsigned index) const;
......
......@@ -41,7 +41,6 @@ HTMLCollection::HTMLCollection(Node* base, CollectionType type)
, m_type(type)
, m_base(base)
{
ASSERT(m_base);
m_cache.clear();
}
......@@ -77,17 +76,24 @@ bool HTMLCollection::shouldIncludeChildren(CollectionType type)