WebCore:
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 May 2006 19:26:09 +0000 (19:26 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 May 2006 19:26:09 +0000 (19:26 +0000)
2006-05-24  Anders Carlsson  <acarlsson@apple.com>

        Reviewed by Maciej.

        http://bugzilla.opendarwin.org/show_bug.cgi?id=9093
        Implement document.scripts

        * bindings/js/kjs_html.cpp:
        (KJS::JSHTMLDocument::getValueProperty):
        Return document.scripts() instead of a placeholder object.

        * dom/Document.cpp:
        (WebCore::Document::scripts):
        * dom/Document.h:
        Add Document::scripts.

        * html/HTMLCollection.cpp:
        (WebCore::HTMLCollection::traverseNextItem):
        * html/HTMLCollection.h:
        (WebCore::HTMLCollection::):
        Add scripts collection type which traverses all script elements.

LayoutTests:

2006-05-24  Anders Carlsson  <acarlsson@apple.com>

        Reviewed by Maciej.

        Add tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=9093
        Implement document.scripts

        * fast/dom/document-scripts-expected.txt: Added.
        * fast/dom/document-scripts.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/document-scripts-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/document-scripts.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/bindings/js/kjs_html.cpp
WebCore/dom/Document.cpp
WebCore/dom/Document.h
WebCore/html/HTMLCollection.cpp
WebCore/html/HTMLCollection.h

index 58e2b506963638340449c187a0a0b0eaff31264e..b2c44f883e5a476f07a0d3683391cfe76a642ba0 100644 (file)
@@ -1,3 +1,13 @@
+2006-05-24  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Maciej.
+
+        Add tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=9093
+        Implement document.scripts
+        
+        * fast/dom/document-scripts-expected.txt: Added.
+        * fast/dom/document-scripts.html: Added.
+
 2006-05-24  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Geoff.
diff --git a/LayoutTests/fast/dom/document-scripts-expected.txt b/LayoutTests/fast/dom/document-scripts-expected.txt
new file mode 100644 (file)
index 0000000..f6d3b12
--- /dev/null
@@ -0,0 +1,5 @@
+This tests that document.scripts works correctly.
+PASS: 2 should be 2 and is.
+FAIL: first should be first but instead is [object SCRIPT]
+FAIL: second should be second but instead is [object SCRIPT]
+
diff --git a/LayoutTests/fast/dom/document-scripts.html b/LayoutTests/fast/dom/document-scripts.html
new file mode 100644 (file)
index 0000000..80f3ed0
--- /dev/null
@@ -0,0 +1,53 @@
+<html>
+<head>
+<script id="first"></script>
+<script id="second">
+function debug(str) {
+    var c = document.getElementById('console')
+    c.appendChild(document.createTextNode(str + '\n'));
+}
+
+function print(message, color) 
+{
+    var paragraph = document.createElement("div");
+    paragraph.appendChild(document.createTextNode(message));
+    paragraph.style.fontFamily = "monospace";
+    if (color)
+        paragraph.style.color = color;
+    document.getElementById("console").appendChild(paragraph);
+}
+
+var element, range, nodeFilter, cssRule, cssPrimitiveValue, cssStyleDeclaration, event;
+var originalNodeConstructor;
+
+function shouldBe(a, b)
+{
+    var evalA;
+    try {
+        evalA = eval(a);
+    } catch(e) {
+        evalA = e;
+    }
+    if (evalA == b)
+        print("PASS: " + a + " should be " + b + " and is.", "green");
+    else
+        print("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
+}
+
+function runTests() {
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+        
+    shouldBe(document.scripts.length, 2);
+    shouldBe("document.scripts[0].id", "first");
+    shouldBe("document.scripts[1].id", "second");
+}
+
+</script>
+</head>
+<body onload="runTests();">
+This tests that document.scripts works correctly.
+<pre id="console">
+</pre>
+</body>
+</html>
\ No newline at end of file
index cbd42c198e794e69702008eb6b9d49d17fa018bc..f2adae1f561b8b49dc5cfae3acf763cfc532cab1 100644 (file)
@@ -1,3 +1,25 @@
+2006-05-24  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Maciej.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=9093
+        Implement document.scripts
+        
+        * bindings/js/kjs_html.cpp:
+        (KJS::JSHTMLDocument::getValueProperty):
+        Return document.scripts() instead of a placeholder object.
+        
+        * dom/Document.cpp:
+        (WebCore::Document::scripts):
+        * dom/Document.h:
+        Add Document::scripts.
+        
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::traverseNextItem):
+        * html/HTMLCollection.h:
+        (WebCore::HTMLCollection::):
+        Add scripts collection type which traverses all script elements.
+        
 2006-05-24  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Geoff.
index fa9206d659fffb47330ba8fd5e88ffe2e61acfc3..54c5ce676c7abef9043c49ed7e1bc7e6aeda72da 100644 (file)
@@ -266,13 +266,8 @@ JSValue *JSHTMLDocument::getValueProperty(ExecState *exec, int token) const
     return getHTMLCollection(exec, doc.forms().get());
   case Anchors:
     return getHTMLCollection(exec, doc.anchors().get());
-  case Scripts: // TODO (IE-specific)
-    {
-      // To be implemented. Meanwhile, return an object with a length property set to 0
-      JSObject *obj = new JSObject;
-      obj->put(exec, lengthPropertyName, jsNumber(0));
-      return obj;
-    }
+  case Scripts:
+    return getHTMLCollection(exec, doc.scripts().get());
   case All:
     // If "all" has been overwritten, return the overwritten value
     if (JSValue *v = getDirect("all"))
index b254c6441804599f8c47eff848937a9694f24ce3..a30abfe4239e34ecc42ec6c2f92afcd99903bc93 100644 (file)
@@ -3069,6 +3069,11 @@ PassRefPtr<HTMLCollection> Document::objects()
     return new HTMLCollection(this, HTMLCollection::DOC_OBJECTS);
 }
 
+PassRefPtr<HTMLCollection> Document::scripts()
+{
+    return new HTMLCollection(this, HTMLCollection::DOC_SCRIPTS);
+}
+
 PassRefPtr<HTMLCollection> Document::links()
 {
     return new HTMLCollection(this, HTMLCollection::DOC_LINKS);
index 6c23750497a56eec663565f0dc6b5a2707a10f19..e17218d6efa1aededefafebda5710e48466220b9 100644 (file)
@@ -199,6 +199,7 @@ public:
     PassRefPtr<HTMLCollection> anchors();
     PassRefPtr<HTMLCollection> all();
     PassRefPtr<HTMLCollection> objects();
+    PassRefPtr<HTMLCollection> scripts();
     PassRefPtr<HTMLCollection> windowNamedItems(const String& name);
     PassRefPtr<HTMLCollection> documentNamedItems(const String& name);
 
index 75235aa28ab9c7c1e766de996cac4869224f4e44..bac71c615572588a487984b37e49f08ea83b7e5c 100644 (file)
@@ -113,6 +113,10 @@ Node *HTMLCollection::traverseNextItem(Node *current) const
                 if (e->hasLocalName(imgTag))
                     found = true;
                 break;
+            case DOC_SCRIPTS:
+                if (e->hasLocalName(scriptTag))
+                    found = true;
+                break;
             case DOC_FORMS:
                 if(e->hasLocalName(formTag))
                     found = true;
index 10ebd80a6bec9ae47f9d6889be690461235e8867..1732cc3de6327035d92476fba8db1a93eed66f39 100644 (file)
@@ -51,6 +51,7 @@ public:
         DOC_FORMS,     // all FORMS
         DOC_LINKS,     // all A _and_ AREA elements with a value for href
         DOC_ANCHORS,      // all A elements with a value for name
+        DOC_SCRIPTS,   // all SCRIPT element
         // from HTMLTable, HTMLTableSection, HTMLTableRow
         TABLE_ROWS,    // all rows in this table or tablesection
         TABLE_TBODIES, // all TBODY elements in this table