Title: [103166] trunk
Revision
103166
Author
[email protected]
Date
2011-12-17 19:57:51 -0800 (Sat, 17 Dec 2011)

Log Message

Cache and reuse the HTMLAllCollection returned by document.all.
<http://webkit.org/b/74768>

Reviewed by Antti Koivisto.

Source/WebCore: 

Let Document cache the document.all collection, just like we do for
the other collections (.links, .images, etc.)
This is primarily a memory optimization, as repeated calls to
document.all will no longer cause collection objects to stack up.

Tests: fast/dom/document-collection-idempotence.html
       fast/dom/gc-9.html

* dom/Document.h:
* dom/Document.cpp:
(WebCore::Document::all):

    Cache the HTMLAllCollection and reuse it across calls instead of
    creating a new one each time.

* html/HTMLAllCollection.h:
* html/HTMLAllCollection.cpp:
(WebCore::HTMLAllCollection::create):
(WebCore::HTMLAllCollection::HTMLAllCollection):

    Make the HTMLAllCollection constructor take a Document* to enforce
    the fact that it's the only way it should ever be created.

* html/HTMLAllCollection.idl:
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):

    Custom reachability code for JSC, same as HTMLCollection.

LayoutTests: 

Update tests to document the new behavior of document.all.

* fast/dom/document-collection-idempotence-expected.txt:
* fast/dom/document-collection-idempotence.html:
* fast/dom/gc-9-expected.txt:
* fast/dom/gc-9.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (103165 => 103166)


--- trunk/LayoutTests/ChangeLog	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/LayoutTests/ChangeLog	2011-12-18 03:57:51 UTC (rev 103166)
@@ -1,3 +1,17 @@
+2011-12-17  Andreas Kling  <[email protected]>
+
+        Cache and reuse the HTMLAllCollection returned by document.all.
+        <http://webkit.org/b/74768>
+
+        Reviewed by Antti Koivisto.
+
+        Update tests to document the new behavior of document.all.
+
+        * fast/dom/document-collection-idempotence-expected.txt:
+        * fast/dom/document-collection-idempotence.html:
+        * fast/dom/gc-9-expected.txt:
+        * fast/dom/gc-9.html:
+
 2011-12-17  Adrienne Walker  <[email protected]>
 
         [chromium] Mark svg/W3C-SVG-1.1/animate-elem* tests as flaky crashers

Modified: trunk/LayoutTests/fast/dom/document-collection-idempotence-expected.txt (103165 => 103166)


--- trunk/LayoutTests/fast/dom/document-collection-idempotence-expected.txt	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/LayoutTests/fast/dom/document-collection-idempotence-expected.txt	2011-12-18 03:57:51 UTC (rev 103166)
@@ -1,9 +1,9 @@
-This test verifies that the HTMLCollection getters on document (excluding .all) returns the same object when called repeatedly.
+This test verifies that the HTMLCollection getters on document return the same object when called repeatedly.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS document.all === document.all is false
+PASS document.all === document.all is true
 PASS document.images === document.images is true
 PASS document.embeds === document.embeds is true
 PASS document.plugins === document.plugins is true

Modified: trunk/LayoutTests/fast/dom/document-collection-idempotence.html (103165 => 103166)


--- trunk/LayoutTests/fast/dom/document-collection-idempotence.html	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/LayoutTests/fast/dom/document-collection-idempotence.html	2011-12-18 03:57:51 UTC (rev 103166)
@@ -7,12 +7,10 @@
 <body>
 <script>
 
-description("This test verifies that the HTMLCollection getters on document (excluding .all) returns the same object when called repeatedly.");
+description("This test verifies that the HTMLCollection getters on document return the same object when called repeatedly.");
 
-var collections = [ "images", "embeds", "plugins", "applets", "links", "forms", "anchors", "scripts" ];
+var collections = [ "all", "images", "embeds", "plugins", "applets", "links", "forms", "anchors", "scripts" ];
 
-shouldBe("document.all === document.all", "false");
-
 for (i = 0; i < collections.length; ++i) {
     var collection = collections[i];
     shouldBe("document." + collection + " === document." + collection, "true");

Modified: trunk/LayoutTests/fast/dom/gc-9-expected.txt (103165 => 103166)


--- trunk/LayoutTests/fast/dom/gc-9-expected.txt	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/LayoutTests/fast/dom/gc-9-expected.txt	2011-12-18 03:57:51 UTC (rev 103166)
@@ -14,8 +14,8 @@
 PASS: document.getElementsByTagName('canvas')[0].getContext('2d').createLinearGradient(0, 0, 0, 0).myCustomProperty should be undefined and is.
 PASS: document.getElementsByTagName('canvas')[0].getContext('2d').createPattern(new Image(), 'no-repeat').myCustomProperty should be undefined and is.
 PASS: document.getElementsByTagName('select')[0].options.myCustomProperty should be undefined and is.
-PASS: document.all.myCustomProperty should be undefined and is.
 PASS: document.body.childNodes.myCustomProperty should be undefined and is.
+PASS: document.all.myCustomProperty should be 1 and is.
 PASS: document.images.myCustomProperty should be 1 and is.
 PASS: document.embeds.myCustomProperty should be 1 and is.
 PASS: document.applets.myCustomProperty should be 1 and is.
@@ -50,8 +50,8 @@
 PASS: document.getElementsByTagName('canvas')[0].getContext('2d').createLinearGradient(0, 0, 0, 0).myCustomProperty should be undefined and is.
 PASS: document.getElementsByTagName('canvas')[0].getContext('2d').createPattern(new Image(), 'no-repeat').myCustomProperty should be undefined and is.
 PASS: document.getElementsByTagName('select')[0].options.myCustomProperty should be undefined and is.
-PASS: document.all.myCustomProperty should be undefined and is.
 PASS: document.body.childNodes.myCustomProperty should be undefined and is.
+PASS: document.all.myCustomProperty should be 1 and is.
 PASS: document.images.myCustomProperty should be 1 and is.
 PASS: document.embeds.myCustomProperty should be 1 and is.
 PASS: document.applets.myCustomProperty should be 1 and is.

Modified: trunk/LayoutTests/fast/dom/gc-9.html (103165 => 103166)


--- trunk/LayoutTests/fast/dom/gc-9.html	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/LayoutTests/fast/dom/gc-9.html	2011-12-18 03:57:51 UTC (rev 103166)
@@ -123,9 +123,9 @@
     [ "document.getElementsByTagName('canvas')[0].getContext('2d').createLinearGradient(0, 0, 0, 0)" ], // CanvasGradient
     [ "document.getElementsByTagName('canvas')[0].getContext('2d').createPattern(new Image(), 'no-repeat')" ], // CanvasPattern
     [ "document.getElementsByTagName('select')[0].options" ],
-    [ "document.all" ],
     [ "document.body.childNodes" ],
 
+    [ "document.all", "allow custom" ],
     [ "document.images", "allow custom" ],
     [ "document.embeds", "allow custom" ],
     [ "document.applets", "allow custom" ],

Modified: trunk/Source/WebCore/ChangeLog (103165 => 103166)


--- trunk/Source/WebCore/ChangeLog	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/Source/WebCore/ChangeLog	2011-12-18 03:57:51 UTC (rev 103166)
@@ -1,5 +1,41 @@
 2011-12-17  Andreas Kling  <[email protected]>
 
+        Cache and reuse the HTMLAllCollection returned by document.all.
+        <http://webkit.org/b/74768>
+
+        Reviewed by Antti Koivisto.
+
+        Let Document cache the document.all collection, just like we do for
+        the other collections (.links, .images, etc.)
+        This is primarily a memory optimization, as repeated calls to
+        document.all will no longer cause collection objects to stack up.
+
+        Tests: fast/dom/document-collection-idempotence.html
+               fast/dom/gc-9.html
+
+        * dom/Document.h:
+        * dom/Document.cpp:
+        (WebCore::Document::all):
+
+            Cache the HTMLAllCollection and reuse it across calls instead of
+            creating a new one each time.
+
+        * html/HTMLAllCollection.h:
+        * html/HTMLAllCollection.cpp:
+        (WebCore::HTMLAllCollection::create):
+        (WebCore::HTMLAllCollection::HTMLAllCollection):
+
+            Make the HTMLAllCollection constructor take a Document* to enforce
+            the fact that it's the only way it should ever be created.
+
+        * html/HTMLAllCollection.idl:
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+
+            Custom reachability code for JSC, same as HTMLCollection.
+
+2011-12-17  Andreas Kling  <[email protected]>
+
         HTMLCollection: Simplify itemAfter().
         <http://webkit.org/b/74795>
 

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (103165 => 103166)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2011-12-18 03:57:51 UTC (rev 103166)
@@ -2303,7 +2303,7 @@
                 $rootString .= "    void* root = WebCore::root(element);\n";
             } elsif ($interfaceName eq "CanvasRenderingContext") {
                 $rootString  = "    void* root = WebCore::root(js${implClassName}->impl()->canvas());\n";
-            } elsif ($interfaceName eq "HTMLCollection") {
+            } elsif ($interfaceName eq "HTMLCollection" or $interfaceName eq "HTMLAllCollection") {
                 $rootString  = "    void* root = WebCore::root(js${implClassName}->impl()->base());\n";
             } else {
                 $rootString  = "    void* root = WebCore::root(js${implClassName}->impl());\n";

Modified: trunk/Source/WebCore/dom/Document.cpp (103165 => 103166)


--- trunk/Source/WebCore/dom/Document.cpp	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/Source/WebCore/dom/Document.cpp	2011-12-18 03:57:51 UTC (rev 103166)
@@ -4242,7 +4242,9 @@
 
 PassRefPtr<HTMLAllCollection> Document::all()
 {
-    return HTMLAllCollection::create(this);
+    if (!m_allCollection)
+        m_allCollection = HTMLAllCollection::create(this);
+    return m_allCollection;
 }
 
 PassRefPtr<HTMLCollection> Document::windowNamedItems(const String &name)

Modified: trunk/Source/WebCore/dom/Document.h (103165 => 103166)


--- trunk/Source/WebCore/dom/Document.h	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/Source/WebCore/dom/Document.h	2011-12-18 03:57:51 UTC (rev 103166)
@@ -1370,6 +1370,7 @@
     CheckedRadioButtons m_checkedRadioButtons;
 
     RefPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];
+    RefPtr<HTMLAllCollection> m_allCollection;
 
     typedef HashMap<AtomicStringImpl*, CollectionCache*> NamedCollectionMap;
     FixedArray<CollectionCache, NumUnnamedDocumentCachedTypes> m_collectionInfo;

Modified: trunk/Source/WebCore/html/HTMLAllCollection.cpp (103165 => 103166)


--- trunk/Source/WebCore/html/HTMLAllCollection.cpp	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/Source/WebCore/html/HTMLAllCollection.cpp	2011-12-18 03:57:51 UTC (rev 103166)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,13 +31,13 @@
 
 namespace WebCore {
 
-PassRefPtr<HTMLAllCollection> HTMLAllCollection::create(PassRefPtr<Node> base)
+PassRefPtr<HTMLAllCollection> HTMLAllCollection::create(Document* document)
 {
-    return adoptRef(new HTMLAllCollection(base));
+    return adoptRef(new HTMLAllCollection(document));
 }
 
-HTMLAllCollection::HTMLAllCollection(PassRefPtr<Node> base)
-    : HTMLCollection(base, DocAll)
+HTMLAllCollection::HTMLAllCollection(Document* document)
+    : HTMLCollection(document, DocAll)
     , m_idsDone(false)
 {
 }

Modified: trunk/Source/WebCore/html/HTMLAllCollection.h (103165 => 103166)


--- trunk/Source/WebCore/html/HTMLAllCollection.h	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/Source/WebCore/html/HTMLAllCollection.h	2011-12-18 03:57:51 UTC (rev 103166)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -32,13 +32,13 @@
 
 class HTMLAllCollection : public HTMLCollection {
 public:
-    static PassRefPtr<HTMLAllCollection> create(PassRefPtr<Node>);
+    static PassRefPtr<HTMLAllCollection> create(Document*);
     virtual ~HTMLAllCollection();
 
     Node* nextNamedItem(const AtomicString& name) const; // In case of multiple items named the same way.
 
 private:
-    HTMLAllCollection(PassRefPtr<Node>);
+    HTMLAllCollection(Document*);
 
     mutable bool m_idsDone; // for nextNamedItem()
 

Modified: trunk/Source/WebCore/html/HTMLAllCollection.idl (103165 => 103166)


--- trunk/Source/WebCore/html/HTMLAllCollection.idl	2011-12-18 03:41:45 UTC (rev 103165)
+++ trunk/Source/WebCore/html/HTMLAllCollection.idl	2011-12-18 03:57:51 UTC (rev 103166)
@@ -29,7 +29,8 @@
         HasIndexGetter,
         HasNameGetter,
         CustomCall,
-        MasqueradesAsUndefined
+        MasqueradesAsUndefined,
+        GenerateIsReachable
     ] HTMLAllCollection {
         readonly attribute unsigned long length;
         [Custom] Node item(in [Optional=CallWithDefaultValue] unsigned long index);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to