Simplify HTMLCollection ownership model.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jan 2012 03:30:36 +0000 (03:30 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jan 2012 03:30:36 +0000 (03:30 +0000)
<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):

    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@104373 268f45cc-cd09-0410-ab3c-d52691b4dbfc

38 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/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

index d24c10d..20409ed 100644 (file)
@@ -1,3 +1,18 @@
+2012-01-06  Andreas Kling  <awesomekling@apple.com>
+
+        Simplify HTMLCollection ownership model.
+        <http://webkit.org/b/75437>
+
+        Reviewed by Sam Weinig.
+
+        - 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.
+
 2012-01-06  Dmitry Lomov  <dslomov@google.com>
 
         Unreviewed: more rebaselines in chromium after r104240.
diff --git a/LayoutTests/fast/dom/htmlcollection-protects-base-expected.txt b/LayoutTests/fast/dom/htmlcollection-protects-base-expected.txt
new file mode 100644 (file)
index 0000000..cfab769
--- /dev/null
@@ -0,0 +1,10 @@
+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
+
diff --git a/LayoutTests/fast/dom/htmlcollection-protects-base.html b/LayoutTests/fast/dom/htmlcollection-protects-base.html
new file mode 100644 (file)
index 0000000..d6b9b44
--- /dev/null
@@ -0,0 +1,27 @@
+<!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>
diff --git a/LayoutTests/fast/dom/htmlcollection-zombies-expected.txt b/LayoutTests/fast/dom/htmlcollection-zombies-expected.txt
deleted file mode 100644 (file)
index b4ca6bd..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-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
-
diff --git a/LayoutTests/fast/dom/htmlcollection-zombies.html b/LayoutTests/fast/dom/htmlcollection-zombies.html
deleted file mode 100644 (file)
index 198caf0..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<!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>
index bbb19eb..70be8bc 100755 (executable)
@@ -1,3 +1,161 @@
+2012-01-06  Andreas Kling  <awesomekling@apple.com>
+
+        Simplify HTMLCollection ownership model.
+        <http://webkit.org/b/75437>
+
+        Reviewed by Sam Weinig.
+
+        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):
+
+            Store cached HTMLCollections in OwnPtrs. Methods that used to return
+            PassRefPtr<HTMLCollection> now simply return HTMLCollection*.
+            Updated call sites as appropriate.
+
 2012-01-06  Adam Barth  <abarth@webkit.org>
 
         DOMWindow should be a FrameDestructionObserver
index c685c78..a23d8b2 100644 (file)
@@ -115,10 +115,10 @@ static JSValue namedItemGetter(ExecState* exec, JSValue slotBase, const Identifi
     ASSERT(document);
     ASSERT(document->isHTMLDocument());
 
-    RefPtr<HTMLCollection> collection = document->windowNamedItems(identifierToAtomicString(propertyName));
+    HTMLCollection* collection = document->windowNamedItems(identifierToAtomicString(propertyName));
     if (collection->length() == 1)
         return toJS(exec, thisObj, collection->firstItem());
-    return toJS(exec, thisObj, collection.get());
+    return toJS(exec, thisObj, collection);
 }
 
 bool JSDOMWindow::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
index c00a551..fd51845 100644 (file)
@@ -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());
 
-    RefPtr<HTMLCollection> collection = document->documentNamedItems(identifierToAtomicString(propertyName));
+    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.get());
+    return toJS(exec, thisObj->globalObject(), collection);
 }
 
 // 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().get());
+    return toJS(exec, globalObject(), static_cast<HTMLDocument*>(impl())->all());
 }
 
 void JSHTMLDocument::setAll(ExecState* exec, JSValue value)
index 5bdff14..b74b264 100644 (file)
@@ -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())) {
-            RefPtr<HTMLCollection> items = doc->windowNamedItems(propName);
+            HTMLCollection* items = doc->windowNamedItems(propName);
             if (items->length() >= 1) {
                 if (items->length() == 1)
                     return toV8(items->firstItem());
-                return toV8(items.release());
+                return toV8(items);
             }
         }
     }
index aef37c7..41ae071 100644 (file)
@@ -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>();
 
-    RefPtr<HTMLCollection> items = htmlDocument->documentNamedItems(key);
+    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.release());
+    return toV8(items);
 }
 
 // HTMLDocument ----------------------------------------------------------------
index 66fb473..7698d24 100644 (file)
@@ -567,14 +567,6 @@ 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()
@@ -4176,7 +4168,7 @@ KURL Document::openSearchDescriptionURL()
     if (!head())
         return KURL();
 
-    RefPtr<HTMLCollection> children = head()->children();
+    HTMLCollection* children = head()->children();
     for (Node* child = children->firstItem(); child; child = children->nextItem()) {
         if (!child->hasTagName(linkTag))
             continue;
@@ -4301,81 +4293,81 @@ bool Document::hasSVGRootNode() const
 }
 #endif
 
-const RefPtr<HTMLCollection>& Document::cachedCollection(CollectionType type)
+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];
+    return m_collections[type].get();
 }
 
-PassRefPtr<HTMLCollection> Document::images()
+HTMLCollection* Document::images()
 {
     return cachedCollection(DocImages);
 }
 
-PassRefPtr<HTMLCollection> Document::applets()
+HTMLCollection* Document::applets()
 {
     return cachedCollection(DocApplets);
 }
 
-PassRefPtr<HTMLCollection> Document::embeds()
+HTMLCollection* Document::embeds()
 {
     return cachedCollection(DocEmbeds);
 }
 
-PassRefPtr<HTMLCollection> Document::plugins()
+HTMLCollection* Document::plugins()
 {
     // This is an alias for embeds() required for the JS DOM bindings.
     return cachedCollection(DocEmbeds);
 }
 
-PassRefPtr<HTMLCollection> Document::objects()
+HTMLCollection* Document::objects()
 {
     return cachedCollection(DocObjects);
 }
 
-PassRefPtr<HTMLCollection> Document::scripts()
+HTMLCollection* Document::scripts()
 {
     return cachedCollection(DocScripts);
 }
 
-PassRefPtr<HTMLCollection> Document::links()
+HTMLCollection* Document::links()
 {
     return cachedCollection(DocLinks);
 }
 
-PassRefPtr<HTMLCollection> Document::forms()
+HTMLCollection* Document::forms()
 {
     return cachedCollection(DocForms);
 }
 
-PassRefPtr<HTMLCollection> Document::anchors()
+HTMLCollection* Document::anchors()
 {
     return cachedCollection(DocAnchors);
 }
 
-PassRefPtr<HTMLAllCollection> Document::all()
+HTMLAllCollection* Document::all()
 {
     if (!m_allCollection)
         m_allCollection = HTMLAllCollection::create(this);
-    return m_allCollection;
+    return m_allCollection.get();
 }
 
-PassRefPtr<HTMLCollection> Document::windowNamedItems(const AtomicString& name)
+HTMLCollection* Document::windowNamedItems(const AtomicString& name)
 {
-    RefPtr<HTMLNameCollection>& collection = m_windowNamedItemCollections.add(name.impl(), 0).first->second;
+    OwnPtr<HTMLNameCollection>& collection = m_windowNamedItemCollections.add(name.impl(), nullptr).first->second;
     if (!collection)
         collection = HTMLNameCollection::create(this, WindowNamedItems, name);
-    return collection;
+    return collection.get();
 }
 
-PassRefPtr<HTMLCollection> Document::documentNamedItems(const AtomicString& name)
+HTMLCollection* Document::documentNamedItems(const AtomicString& name)
 {
-    RefPtr<HTMLNameCollection>& collection = m_documentNamedItemCollections.add(name.impl(), 0).first->second;
+    OwnPtr<HTMLNameCollection>& collection = m_documentNamedItemCollections.add(name.impl(), nullptr).first->second;
     if (!collection)
         collection = HTMLNameCollection::create(this, DocumentNamedItems, name);
-    return collection;
+    return collection.get();
 }
 
 void Document::finishedParsing()
index 38610cb..baeeb53 100644 (file)
@@ -410,19 +410,19 @@ public:
 
     PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
 
-    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();
+    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();
 
     // Other methods (not part of DOM)
     bool isHTMLDocument() const { return m_isHTML; }
@@ -1182,7 +1182,7 @@ private:
     PageVisibilityState visibilityState() const;
 #endif
 
-    const RefPtr<HTMLCollection>& cachedCollection(CollectionType);
+    HTMLCollection* cachedCollection(CollectionType);
 
     int m_guardRefCount;
 
@@ -1365,10 +1365,10 @@ private:
     
     CheckedRadioButtons m_checkedRadioButtons;
 
-    RefPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];
-    RefPtr<HTMLAllCollection> m_allCollection;
+    OwnPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];
+    OwnPtr<HTMLAllCollection> m_allCollection;
 
-    typedef HashMap<AtomicStringImpl*, RefPtr<HTMLNameCollection> > NamedCollectionMap;
+    typedef HashMap<AtomicStringImpl*, OwnPtr<HTMLNameCollection> > NamedCollectionMap;
     NamedCollectionMap m_documentNamedItemCollections;
     NamedCollectionMap m_windowNamedItemCollections;
 
index 1093116..79a7130 100644 (file)
@@ -123,16 +123,6 @@ 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
index c5cf6cd..4036a31 100644 (file)
@@ -43,25 +43,19 @@ public:
     using NodeRareData::needsFocusAppearanceUpdateSoonAfterAttach;
     using NodeRareData::setNeedsFocusAppearanceUpdateSoonAfterAttach;
 
-    typedef FixedArray<RefPtr<HTMLCollection>, NumNodeCollectionTypes> CachedHTMLCollectionArray;
+    typedef FixedArray<OwnPtr<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);
 
-        RefPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
+        OwnPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
         if (!collection)
             collection = HTMLCollection::create(element, type);
         return collection.get();
index 2249e52..9bb73eb 100644 (file)
@@ -221,7 +221,7 @@ public:
     HTMLPropertiesCollection* properties(Node* node)
     {
         if (!m_properties)
-            m_properties = HTMLPropertiesCollection::create(node);
+            m_properties = adoptPtr(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 RefPtr<HTMLPropertiesCollection> m_properties;
+    mutable OwnPtr<HTMLPropertiesCollection> m_properties;
 #endif
 };
 
index 3dc07a3..ea7ae97 100644 (file)
@@ -30,9 +30,9 @@
 
 namespace WebCore {
 
-PassRefPtr<HTMLAllCollection> HTMLAllCollection::create(Document* document)
+PassOwnPtr<HTMLAllCollection> HTMLAllCollection::create(Document* document)
 {
-    return adoptRef(new HTMLAllCollection(document));
+    return adoptPtr(new HTMLAllCollection(document));
 }
 
 HTMLAllCollection::HTMLAllCollection(Document* document)
@@ -46,9 +46,6 @@ HTMLAllCollection::~HTMLAllCollection()
 
 Node* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, unsigned index) const
 {
-    if (!base())
-        return 0;
-
     invalidateCacheIfNeeded();
     updateNameCache();
 
index ae97a53..d636bbd 100644 (file)
@@ -32,7 +32,7 @@ namespace WebCore {
 
 class HTMLAllCollection : public HTMLCollection {
 public:
-    static PassRefPtr<HTMLAllCollection> create(Document*);
+    static PassOwnPtr<HTMLAllCollection> create(Document*);
     virtual ~HTMLAllCollection();
 
     Node* namedItemWithIndex(const AtomicString& name, unsigned index) const;
index 0803fe9..e6f2eac 100644 (file)
@@ -41,6 +41,7 @@ HTMLCollection::HTMLCollection(Node* base, CollectionType type)
     , m_type(type)
     , m_base(base)
 {
+    ASSERT(m_base);
     m_cache.clear();
 }
 
@@ -76,24 +77,17 @@ bool HTMLCollection::shouldIncludeChildren(CollectionType type)
     return false;
 }
 
-PassRefPtr<HTMLCollection> HTMLCollection::create(Node* base, CollectionType type)
+PassOwnPtr<HTMLCollection> HTMLCollection::create(Node* base, CollectionType type)
 {
-    return adoptRef(new HTMLCollection(base, type));
+    return adoptPtr(new HTMLCollection(base, type));
 }
 
 HTMLCollection::~HTMLCollection()
 {
 }
 
-void HTMLCollection::detachFromNode()
-{
-    m_base = 0;
-}
-
 void HTMLCollection::invalidateCacheIfNeeded() const
 {
-    ASSERT(m_base);
-
     uint64_t docversion = static_cast<HTMLDocument*>(m_base->document())->domTreeVersion();
 
     if (m_cache.version == docversion)
@@ -161,8 +155,6 @@ static Node* nextNodeOrSibling(Node* base, Node* node, bool includeChildren)
 
 Element* HTMLCollection::itemAfter(Element* previous) const
 {
-    ASSERT(m_base);
-
     Node* current;
     if (!previous)
         current = m_base->firstChild();
@@ -182,8 +174,6 @@ Element* HTMLCollection::itemAfter(Element* previous) const
 
 unsigned HTMLCollection::calcLength() const
 {
-    ASSERT(m_base);
-
     unsigned len = 0;
     for (Element* current = itemAfter(0); current; current = itemAfter(current))
         ++len;
@@ -194,9 +184,6 @@ unsigned HTMLCollection::calcLength() const
 // calculation every time if anything has changed
 unsigned HTMLCollection::length() const
 {
-    if (!m_base)
-        return 0;
-
     invalidateCacheIfNeeded();
     if (!m_cache.hasLength) {
         m_cache.length = calcLength();
@@ -207,9 +194,6 @@ unsigned HTMLCollection::length() const
 
 Node* HTMLCollection::item(unsigned index) const
 {
-    if (!m_base)
-        return 0;
-
      invalidateCacheIfNeeded();
      if (m_cache.current && m_cache.position == index)
          return m_cache.current;
@@ -236,7 +220,6 @@ Node* HTMLCollection::firstItem() const
 
 Node* HTMLCollection::nextItem() const
 {
-     ASSERT(m_base);
      invalidateCacheIfNeeded();
 
      // Look for the 'second' item. The first one is currentItem, already given back.
@@ -276,9 +259,6 @@ bool HTMLCollection::checkForNameMatch(Element* element, bool checkName, const A
 
 Node* HTMLCollection::namedItem(const AtomicString& name) const
 {
-    if (!m_base)
-        return 0;
-
     // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp
     // This method first searches for an object with a matching id
     // attribute. If a match is not found, the method then searches for an
@@ -306,8 +286,6 @@ Node* HTMLCollection::namedItem(const AtomicString& name) const
 
 void HTMLCollection::updateNameCache() const
 {
-    ASSERT(m_base);
-
     if (m_cache.hasNameCache)
         return;
 
@@ -328,9 +306,6 @@ void HTMLCollection::updateNameCache() const
 
 bool HTMLCollection::hasNamedItem(const AtomicString& name) const
 {
-    if (!m_base)
-        return false;
-
     if (name.isEmpty())
         return false;
 
@@ -352,9 +327,6 @@ bool HTMLCollection::hasNamedItem(const AtomicString& name) const
 
 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Node> >& result) const
 {
-    if (!m_base)
-        return;
-
     ASSERT(result.isEmpty());
     if (name.isEmpty())
         return;
@@ -374,9 +346,6 @@ void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Node> >&
 
 PassRefPtr<NodeList> HTMLCollection::tags(const String& name)
 {
-    if (!m_base)
-        return 0;
-
     return m_base->getElementsByTagName(name);
 }
 
index 76bc241..02a52e4 100644 (file)
 #ifndef HTMLCollection_h
 #define HTMLCollection_h
 
+#include "Node.h"
 #include "CollectionType.h"
-#include <wtf/RefCounted.h>
 #include <wtf/Forward.h>
 #include <wtf/HashMap.h>
+#include <wtf/PassOwnPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
 class Document;
 class Element;
-class Node;
 class NodeList;
 
-class HTMLCollection : public RefCounted<HTMLCollection> {
+class HTMLCollection {
 public:
-    static PassRefPtr<HTMLCollection> create(Node* base, CollectionType);
+    static PassOwnPtr<HTMLCollection> create(Node* base, CollectionType);
     virtual ~HTMLCollection();
 
+    void ref() { m_base->ref(); }
+    void deref() { m_base->deref(); }
+
     unsigned length() const;
     
     virtual Node* item(unsigned index) const;
@@ -58,8 +61,6 @@ public:
     Node* base() const { return m_base; }
     CollectionType type() const { return static_cast<CollectionType>(m_type); }
 
-    void detachFromNode();
-
 protected:
     HTMLCollection(Node* base, CollectionType);
 
index 964d342..f6cc7da 100644 (file)
@@ -47,7 +47,7 @@ PassRefPtr<HTMLDataListElement> HTMLDataListElement::create(const QualifiedName&
     return adoptRef(new HTMLDataListElement(tagName, document));
 }
 
-PassRefPtr<HTMLCollection> HTMLDataListElement::options()
+HTMLCollection* HTMLDataListElement::options()
 {
     return ensureCachedHTMLCollection(DataListOptions);
 }
index 97e608f..64bfc89 100644 (file)
@@ -43,7 +43,7 @@ class HTMLDataListElement : public HTMLElement {
 public:
     static PassRefPtr<HTMLDataListElement> create(const QualifiedName&, Document*);
 
-    PassRefPtr<HTMLCollection> options();
+    HTMLCollection* options();
 
 private:
     HTMLDataListElement(const QualifiedName&, Document*);
index 573d581..3769b49 100644 (file)
@@ -824,7 +824,7 @@ void HTMLElement::setTabIndex(int value)
     setAttribute(tabindexAttr, String::number(value));
 }
 
-PassRefPtr<HTMLCollection> HTMLElement::children()
+HTMLCollection* HTMLElement::children()
 {
     return ensureCachedHTMLCollection(NodeChildren);
 }
index b98b2dd..a86b2b9 100644 (file)
@@ -39,8 +39,8 @@ class HTMLElement : public StyledElement {
 public:
     static PassRefPtr<HTMLElement> create(const QualifiedName& tagName, Document*);
 
-    PassRefPtr<HTMLCollection> children();
-    
+    HTMLCollection* children();
+
     virtual String title() const;
 
     virtual short tabIndex() const;
index 6b19d44..d25653f 100644 (file)
@@ -40,9 +40,9 @@ HTMLFormCollection::HTMLFormCollection(HTMLFormElement* form)
 {
 }
 
-PassRefPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLFormElement* form)
+PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLFormElement* form)
 {
-    return adoptRef(new HTMLFormCollection(form));
+    return adoptPtr(new HTMLFormCollection(form));
 }
 
 HTMLFormCollection::~HTMLFormCollection()
@@ -51,15 +51,11 @@ HTMLFormCollection::~HTMLFormCollection()
 
 unsigned HTMLFormCollection::calcLength() const
 {
-    ASSERT(base());
     return static_cast<HTMLFormElement*>(base())->length();
 }
 
 Node* HTMLFormCollection::item(unsigned index) const
 {
-    if (!base())
-        return 0;
-
     invalidateCacheIfNeeded();
 
     if (m_cache.current && m_cache.position == index)
@@ -96,9 +92,6 @@ Node* HTMLFormCollection::item(unsigned index) const
 
 Element* HTMLFormCollection::getNamedItem(const QualifiedName& attrName, const AtomicString& name) const
 {
-    if (!base())
-        return 0;
-
     m_cache.position = 0;
     return getNamedFormItem(attrName, name, 0);
 }
@@ -143,9 +136,6 @@ Node* HTMLFormCollection::nextItem() const
 
 Node* HTMLFormCollection::namedItem(const AtomicString& name) const
 {
-    if (!base())
-        return 0;
-
     // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp
     // This method first searches for an object with a matching id
     // attribute. If a match is not found, the method then searches for an
@@ -161,9 +151,6 @@ Node* HTMLFormCollection::namedItem(const AtomicString& name) const
 
 void HTMLFormCollection::updateNameCache() const
 {
-    if (!base())
-        return;
-
     if (m_cache.hasNameCache)
         return;
 
index 7d29638..60c6d2b 100644 (file)
@@ -35,7 +35,7 @@ class QualifiedName;
 
 class HTMLFormCollection : public HTMLCollection {
 public:
-    static PassRefPtr<HTMLFormCollection> create(HTMLFormElement*);
+    static PassOwnPtr<HTMLFormCollection> create(HTMLFormElement*);
 
     virtual ~HTMLFormCollection();
 
index dab47ef..38757d5 100644 (file)
@@ -91,9 +91,6 @@ PassRefPtr<HTMLFormElement> HTMLFormElement::create(const QualifiedName& tagName
 
 HTMLFormElement::~HTMLFormElement()
 {
-    if (m_elementsCollection)
-        m_elementsCollection->detachFromNode();
-
     if (!shouldAutocomplete())
         document()->unregisterForPageCacheSuspensionCallbacks(this);
 
@@ -501,11 +498,11 @@ void HTMLFormElement::removeImgElement(HTMLImageElement* e)
     removeFromVector(m_imageElements, e);
 }
 
-PassRefPtr<HTMLCollection> HTMLFormElement::elements()
+HTMLCollection* HTMLFormElement::elements()
 {
     if (!m_elementsCollection)
         m_elementsCollection = HTMLFormCollection::create(this);
-    return m_elementsCollection;
+    return m_elementsCollection.get();
 }
 
 String HTMLFormElement::name() const
index 2dd8af1..08c1141 100644 (file)
@@ -47,7 +47,7 @@ public:
     static PassRefPtr<HTMLFormElement> create(const QualifiedName&, Document*);
     virtual ~HTMLFormElement();
 
-    PassRefPtr<HTMLCollection> elements();
+    HTMLCollection* elements();
     void getNamedElements(const AtomicString&, Vector<RefPtr<Node> >&);
 
     unsigned length() const;
@@ -149,7 +149,7 @@ private:
 
     FormSubmission::Attributes m_attributes;
     OwnPtr<AliasMap> m_elementAliases;
-    RefPtr<HTMLFormCollection> m_elementsCollection;
+    OwnPtr<HTMLFormCollection> m_elementsCollection;
 
     CheckedRadioButtons m_checkedRadioButtons;
 
index 46d1049..f5f4729 100644 (file)
@@ -1576,7 +1576,7 @@ HTMLOptionElement* HTMLInputElement::selectedOption() const
     HTMLDataListElement* sourceElement = dataList();
     if (!sourceElement)
         return 0;
-    RefPtr<HTMLCollection> options = sourceElement->options();
+    HTMLCollection* options = sourceElement->options();
     if (!options)
         return 0;
     unsigned length = options->length();
index 098295b..bf4a3b3 100644 (file)
@@ -82,7 +82,7 @@ bool HTMLMapElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size,
 
 HTMLImageElement* HTMLMapElement::imageElement()
 {
-    RefPtr<HTMLCollection> coll = document()->images();
+    HTMLCollection* coll = document()->images();
     for (Node* curr = coll->firstItem(); curr; curr = coll->nextItem()) {
         if (!curr->hasTagName(imgTag))
             continue;
@@ -126,7 +126,7 @@ void HTMLMapElement::parseMappedAttribute(Attribute* attribute)
     HTMLElement::parseMappedAttribute(attribute);
 }
 
-PassRefPtr<HTMLCollection> HTMLMapElement::areas()
+HTMLCollection* HTMLMapElement::areas()
 {
     return ensureCachedHTMLCollection(MapAreas);
 }
index 3006766..925895c 100644 (file)
@@ -41,7 +41,7 @@ public:
     bool mapMouseEvent(LayoutPoint location, const LayoutSize&, HitTestResult&);
     
     HTMLImageElement* imageElement();
-    PassRefPtr<HTMLCollection> areas();
+    HTMLCollection* areas();
 
 private:
     HTMLMapElement(const QualifiedName&, Document*);
index ad73d32..aaf5b4d 100644 (file)
@@ -40,9 +40,6 @@ HTMLNameCollection::HTMLNameCollection(Document* document, CollectionType type,
 
 Element* HTMLNameCollection::itemAfter(Element* previous) const
 {
-    if (!base())
-        return 0;
-
     ASSERT(previous != base());
 
     Node* current;
index c4087cb..f844657 100644 (file)
@@ -33,9 +33,9 @@ class Document;
 
 class HTMLNameCollection : public HTMLCollection {
 public:
-    static PassRefPtr<HTMLNameCollection> create(Document* document, CollectionType type, const AtomicString& name)
+    static PassOwnPtr<HTMLNameCollection> create(Document* document, CollectionType type, const AtomicString& name)
     {
-        return adoptRef(new HTMLNameCollection(document, type, name));
+        return adoptPtr(new HTMLNameCollection(document, type, name));
     }
 
 private:
index 3abb353..ca8a1b0 100644 (file)
@@ -32,9 +32,9 @@ HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement* select)
 {
 }
 
-PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(HTMLSelectElement* select)
+PassOwnPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(HTMLSelectElement* select)
 {
-    return adoptRef(new HTMLOptionsCollection(select));
+    return adoptPtr(new HTMLOptionsCollection(select));
 }
 
 void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, ExceptionCode &ec)
@@ -59,9 +59,6 @@ void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, int index
     ec = 0;
     HTMLSelectElement* select = toHTMLSelectElement(base());
 
-    if (!select)
-        return;
-
     if (index == -1 || unsigned(index) >= length())
         select->add(newOption, 0, ec);
     else
@@ -72,29 +69,21 @@ void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, int index
 
 void HTMLOptionsCollection::remove(int index)
 {
-    if (!base())
-        return;
     toHTMLSelectElement(base())->remove(index);
 }
 
 int HTMLOptionsCollection::selectedIndex() const
 {
-    if (!base())
-        return -1;
     return toHTMLSelectElement(base())->selectedIndex();
 }
 
 void HTMLOptionsCollection::setSelectedIndex(int index)
 {
-    if (!base())
-        return;
     toHTMLSelectElement(base())->setSelectedIndex(index);
 }
 
 void HTMLOptionsCollection::setLength(unsigned length, ExceptionCode& ec)
 {
-    if (!base())
-        return;
     toHTMLSelectElement(base())->setLength(length, ec);
 }
 
index 333334b..bc9bdfa 100644 (file)
@@ -35,7 +35,7 @@ typedef int ExceptionCode;
 
 class HTMLOptionsCollection : public HTMLCollection {
 public:
-    static PassRefPtr<HTMLOptionsCollection> create(HTMLSelectElement*);
+    static PassOwnPtr<HTMLOptionsCollection> create(HTMLSelectElement*);
 
     void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&);
     void add(PassRefPtr<HTMLOptionElement>, int index, ExceptionCode&);
index 439bae6..86fcecf 100644 (file)
@@ -49,9 +49,9 @@ static inline bool compareTreeOrder(Node* node1, Node* node2)
     return (node2->compareDocumentPosition(node1) & (Node::DOCUMENT_POSITION_PRECEDING | Node::DOCUMENT_POSITION_DISCONNECTED)) == Node::DOCUMENT_POSITION_PRECEDING;
 }
 
-PassRefPtr<HTMLPropertiesCollection> HTMLPropertiesCollection::create(PassRefPtr<Node> itemNode)
+PassOwnPtr<HTMLPropertiesCollection> HTMLPropertiesCollection::create(PassRefPtr<Node> itemNode)
 {
-    return adoptRef(new HTMLPropertiesCollection(itemNode));
+    return adoptPtr(new HTMLPropertiesCollection(itemNode));
 }
 
 HTMLPropertiesCollection::HTMLPropertiesCollection(PassRefPtr<Node> itemNode)
@@ -123,9 +123,6 @@ void HTMLPropertiesCollection::findPropetiesOfAnItem(Node* root) const
 
 unsigned HTMLPropertiesCollection::length() const
 {
-    if (!base())
-        return 0;
-
     if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr))
         return 0;
 
@@ -136,9 +133,6 @@ unsigned HTMLPropertiesCollection::length() const
 
 Node* HTMLPropertiesCollection::item(unsigned index) const
 {
-    if (!base())
-        return 0;
-
     if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr))
         return 0;
 
@@ -157,9 +151,6 @@ PassRefPtr<DOMStringList> HTMLPropertiesCollection::names() const
     m_properties.clear();
     m_propertyNames->clear();
 
-    if (!base())
-        return 0;
-
     if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr))
         return m_propertyNames;
 
index ca822f1..e7524f9 100644 (file)
@@ -41,7 +41,7 @@ class DOMStringList;
 
 class HTMLPropertiesCollection : public HTMLCollection {
 public:
-    static PassRefPtr<HTMLPropertiesCollection> create(PassRefPtr<Node>);
+    static PassOwnPtr<HTMLPropertiesCollection> create(PassRefPtr<Node>);
     virtual ~HTMLPropertiesCollection();
 
     unsigned length() const OVERRIDE;
index 95421f3..bfebf8e 100644 (file)
@@ -92,12 +92,6 @@ HTMLSelectElement::HTMLSelectElement(const QualifiedName& tagName, Document* doc
     ASSERT(hasTagName(selectTag));
 }
 
-HTMLSelectElement::~HTMLSelectElement()
-{
-    if (m_optionsCollection)
-        m_optionsCollection->detachFromNode();
-}
-
 PassRefPtr<HTMLSelectElement> HTMLSelectElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
 {
     ASSERT(tagName.matches(selectTag));
@@ -331,11 +325,11 @@ RenderObject* HTMLSelectElement::createRenderer(RenderArena* arena, RenderStyle*
     return new (arena) RenderListBox(this);
 }
 
-PassRefPtr<HTMLOptionsCollection> HTMLSelectElement::options()
+HTMLOptionsCollection* HTMLSelectElement::options()
 {
     if (!m_optionsCollection)
         m_optionsCollection = HTMLOptionsCollection::create(this);
-    return m_optionsCollection;
+    return m_optionsCollection.get();
 }
 
 void HTMLSelectElement::updateListItemSelectedStates()
index 5363cc7..5c1abde 100644 (file)
 
 #include "Event.h"
 #include "HTMLFormControlElementWithState.h"
+#include "HTMLOptionsCollection.h"
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
 class HTMLOptionElement;
-class HTMLOptionsCollection;
 
 class HTMLSelectElement : public HTMLFormControlElementWithState {
 public:
     static PassRefPtr<HTMLSelectElement> create(const QualifiedName&, Document*, HTMLFormElement*);
 
-    virtual ~HTMLSelectElement();
-
     int selectedIndex() const;
     void setSelectedIndex(int);
 
@@ -63,7 +61,7 @@ public:
     String value() const;
     void setValue(const String&);
 
-    PassRefPtr<HTMLOptionsCollection> options();
+    HTMLOptionsCollection* options();
 
     void optionElementChildrenChanged();
 
@@ -175,7 +173,7 @@ private:
 
     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
 
-    RefPtr<HTMLOptionsCollection> m_optionsCollection;
+    OwnPtr<HTMLOptionsCollection> m_optionsCollection;
 
     // m_listItems contains HTMLOptionElement, HTMLOptGroupElement, and HTMLHRElement objects.
     mutable Vector<HTMLElement*> m_listItems;