2009-10-27 Joseph Pecoraro <joepeck@webkit.org>
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Oct 2009 19:37:56 +0000 (19:37 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Oct 2009 19:37:56 +0000 (19:37 +0000)
        Reviewed by Timothy Hatcher.

        Web Inspector: Pretty Print all HTML Collection Types like we do for NodeList
        https://bugs.webkit.org/show_bug.cgi?id=30709

        Test: inspector/console-format-collections.html

        * inspector/front-end/InjectedScript.js:
        (Object.type): check for instances of HTMLCollection like we do for NodeList
        * inspector/front-end/inspector.js: added WebInspector.pendingDispatches counter
        (WebInspector.dispatch): increment and decrement dispatch counter
        (WebInspector.runAfterPendingDispatches): run when there are no more dispatches

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

LayoutTests/ChangeLog
LayoutTests/inspector/console-format-collections-expected.txt [new file with mode: 0644]
LayoutTests/inspector/console-format-collections.html [new file with mode: 0644]
LayoutTests/inspector/evaluate-in-frontend.js
WebCore/ChangeLog
WebCore/inspector/front-end/InjectedScript.js
WebCore/inspector/front-end/inspector.js

index 050c87d..6f25578 100644 (file)
@@ -1,3 +1,14 @@
+2009-10-27  Joseph Pecoraro  <joepeck@webkit.org>
+
+        Reviewed by Timothy Hatcher.
+
+        Web Inspector: Pretty Print all HTML Collection Types like we do for NodeList
+        https://bugs.webkit.org/show_bug.cgi?id=30709
+
+        * inspector/console-format-collections-expected.txt: Added.
+        * inspector/console-format-collections.html: Added.
+        * inspector/evaluate-in-frontend.js: Changed innerHTML to DOM elements instead.
+
 2009-10-27  Adele Peterson  <adele@apple.com>
 
         Test for <rdar://problem/7269075> REGRESSION (Safari 4.0.3-ToT): After pressing Shift-PageDown, pressing Shift-Up 
diff --git a/LayoutTests/inspector/console-format-collections-expected.txt b/LayoutTests/inspector/console-format-collections-expected.txt
new file mode 100644 (file)
index 0000000..80f1be4
--- /dev/null
@@ -0,0 +1,15 @@
+CONSOLE MESSAGE: line 14: [object NodeList]
+CONSOLE MESSAGE: line 18: [object HTMLCollection]
+CONSOLE MESSAGE: line 22: [object HTMLOptionsCollection]
+CONSOLE MESSAGE: line 26: [object HTMLAllCollection]
+CONSOLE MESSAGE: line 30: [object HTMLCollection]
+CONSOLE MESSAGE: line 34: [object NodeList]
+Tests that console nicely formats HTML Collections and NodeLists.
+
+console-format-collections.html:14[<select id="sel" name="sel">]
+console-format-collections.html:18[<script src="evaluate-in-frontend.js">, <script>]
+console-format-collections.html:22[<option value="1">one</option>, <option value="2">two</option>]
+console-format-collections.html:26[<html>, <head>, <script src="evaluate-in-frontend.js">, <script>, <body onload="onload()">, <p> Tests that console nicely formats HTML Collections and NodeLists. </p>, <div style="display:none">, <form id="f">, <select id="sel" name="sel">, <option value="1">one</option>, <option value="2">two</option>, <input type="radio" name="x" value="x1">, <input type="radio" name="x" value="x2">, <div id="frontend-script" style="display:none">, <div id="output">]
+console-format-collections.html:30[<select id="sel" name="sel">, <input type="radio" name="x" value="x1">, <input type="radio" name="x" value="x2">]
+console-format-collections.html:34[<input type="radio" name="x" value="x1">, <input type="radio" name="x" value="x2">]
+
diff --git a/LayoutTests/inspector/console-format-collections.html b/LayoutTests/inspector/console-format-collections.html
new file mode 100644 (file)
index 0000000..35a96df
--- /dev/null
@@ -0,0 +1,79 @@
+<html>
+<head>
+<script src="evaluate-in-frontend.js"></script>
+<script>
+
+function doit()
+{
+    var formElement = document.getElementById("f");
+    var selectElement = document.getElementById("sel");
+    var spanElement = document.getElementById("span");
+
+    // NodeList
+    var nodelist = document.getElementsByTagName("select");
+    console.log(nodelist);
+
+    // HTMLCollection
+    var htmlcollection = document.head.children;
+    console.log(htmlcollection);
+
+    // HTMLOptionsCollection
+    var options = selectElement.options;
+    console.log(options);
+
+    // HTMLAllCollection
+    var all = document.all;
+    console.log(all);
+
+    // HTMLFormControlsCollection (currently shows HTMLCollection)
+    var formControls = formElement.elements;
+    console.log(formControls);
+
+    // RadioNodeList (currently shows NodeList)
+    var radioNodeList = formElement.x;
+    console.log(radioNodeList);
+
+    evaluateInWebInspector("dumpMessages", function(result) {
+        for (var i = 0; i < result.length; ++i)
+            output(result[i]);
+        notifyDone();
+    });
+}
+
+</script>
+</head>
+
+<body onload="onload()">
+<p>
+Tests that console nicely formats HTML Collections and NodeLists.
+</p>
+<div style="display:none">
+    <form id="f">
+        <select id="sel" name="sel">
+            <option value="1">one</option>
+            <option value="2">two</option>
+        </select>
+        <input type="radio" name="x" value="x1" /> x1
+        <input type="radio" name="x" value="x2" /> x2
+    </form>
+</div>
+
+<div id="frontend-script" style="display:none">
+function dumpMessages(testController)
+{
+    testController.waitUntilDone();
+    WebInspector.runAfterPendingDispatches(function() {
+        var result = [];
+        var messages = WebInspector.console.messages;
+        for (var i = 0; i < messages.length; ++i)
+            result.push(messages[i].toMessageElement().textContent.replace(/\u200b/g, ""));
+        testController.notifyDone(result);
+    });
+}
+</div>
+
+<div id="output">
+</div>
+
+</body>
+</html>
index 1a4e7ab..79b2cb1 100755 (executable)
@@ -46,7 +46,6 @@ function evaluateInWebInspector(script, callback)
         if (window.layoutTestController)
             layoutTestController.evaluateInWebInspector(callId, script);
     }, 0);
-
 }
 
 function notifyDone()
@@ -62,7 +61,8 @@ function notifyDone()
 function output(text)
 {
     var output = document.getElementById("output");
-    output.innerHTML += text + "<BR>";
+    output.appendChild(document.createTextNode(text));
+    output.appendChild(document.createElement("br"));
 }
 
 window.didEvaluateForTestInFrontend = function(callId, jsonResult)
index d376eeb..9be5fa2 100644 (file)
@@ -1,3 +1,18 @@
+2009-10-27  Joseph Pecoraro  <joepeck@webkit.org>
+
+        Reviewed by Timothy Hatcher.
+
+        Web Inspector: Pretty Print all HTML Collection Types like we do for NodeList
+        https://bugs.webkit.org/show_bug.cgi?id=30709
+
+        Test: inspector/console-format-collections.html
+
+        * inspector/front-end/InjectedScript.js:
+        (Object.type): check for instances of HTMLCollection like we do for NodeList
+        * inspector/front-end/inspector.js: added WebInspector.pendingDispatches counter
+        (WebInspector.dispatch): increment and decrement dispatch counter
+        (WebInspector.runAfterPendingDispatches): run when there are no more dispatches
+
 2009-10-27  Kelly Norton  <knorton@google.com>
 
         Reviewed by Timothy Hatcher.
index b912a28..3bed8da 100644 (file)
@@ -1158,6 +1158,8 @@ Object.type = function(obj)
         return "regexp";
     if (obj instanceof win.NodeList)
         return "array";
+    if (obj instanceof win.HTMLCollection || obj instanceof win.HTMLAllCollection)
+        return "array";
     if (obj instanceof win.Error)
         return "error";
     return type;
index 4eea946..da6697c 100644 (file)
@@ -374,6 +374,7 @@ WebInspector.loaded = function()
     document.body.addStyleClass("platform-" + platform);
 
     this._loadPreferences();
+    this.pendingDispatches = 0;
 
     this.drawer = new WebInspector.Drawer();
     this.console = new WebInspector.ConsoleView(this.drawer);
@@ -497,10 +498,22 @@ WebInspector.dispatch = function() {
     function delayDispatch()
     {
         WebInspector[methodName].apply(WebInspector, parameters);
+        WebInspector.pendingDispatches--;
     }
+    WebInspector.pendingDispatches++;
     setTimeout(delayDispatch, 0);
 }
 
+WebInspector.runAfterPendingDispatches = function(callback)
+{
+    if (WebInspector.pendingDispatches === 0) {
+        callback();
+        return;
+    }
+
+    setTimeout(WebInspector.runAfterPendingDispatches, 0, callback);
+}
+
 WebInspector.windowUnload = function(event)
 {
     InspectorController.windowUnloading();