Title: [127266] trunk
Revision
127266
Author
[email protected]
Date
2012-08-31 08:40:14 -0700 (Fri, 31 Aug 2012)

Log Message

Web Inspector: Update $ to alias to querySelector rather than getElementById
https://bugs.webkit.org/show_bug.cgi?id=92648

Reviewed by Yury Semikhatsky.

Source/WebCore:

Completed implementation started by Addy Osmani. Updates $ to alias to querySelector
with more flexible handling of selectors. Also adds a warning about the change (as per Firebug).

* inspector/InjectedScriptSource.js:
(.):

LayoutTests:

* inspector/console/command-line-api-expected.txt:
* inspector/console/command-line-api-inspect.html:
* inspector/console/command-line-api.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (127265 => 127266)


--- trunk/LayoutTests/ChangeLog	2012-08-31 15:36:04 UTC (rev 127265)
+++ trunk/LayoutTests/ChangeLog	2012-08-31 15:40:14 UTC (rev 127266)
@@ -1,3 +1,14 @@
+2012-08-31  Pavel Feldman  <[email protected]>
+
+        Web Inspector: Update $ to alias to querySelector rather than getElementById
+        https://bugs.webkit.org/show_bug.cgi?id=92648
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/console/command-line-api-expected.txt:
+        * inspector/console/command-line-api-inspect.html:
+        * inspector/console/command-line-api.html:
+
 2012-08-31  Csaba Osztrogonác  <[email protected]>
 
         [Qt][WK2] Unreviewed gardening, add Qt-WK2 specific expected

Modified: trunk/LayoutTests/inspector/console/command-line-api-expected.txt (127265 => 127266)


--- trunk/LayoutTests/inspector/console/command-line-api-expected.txt	2012-08-31 15:36:04 UTC (rev 127265)
+++ trunk/LayoutTests/inspector/console/command-line-api-expected.txt	2012-08-31 15:40:14 UTC (rev 127266)
@@ -1,9 +1,48 @@
+CONSOLE MESSAGE: line 955: The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $("#%s")
 Tests that command line api works.
 
-$0.toString() = "[object HTMLParagraphElement]"
-$3 = undefined
-keys([3,4]).toString() = "0,1"
-values([3,4]).toString() = "3,4"
-$('foo').toString() = "[object HTMLParagraphElement]"
-$$('p#foo').toString() = "[object NodeList]"
 
+
+String($0)
+"[object HTMLParagraphElement]"
+
+
+$3
+undefined
+
+
+String(keys([3,4]))
+"0,1"
+
+
+String(values([3,4]))
+"3,4"
+
+
+String($('#foo'))
+"[object HTMLParagraphElement]"
+
+
+String($('#foo', document.body))
+"[object HTMLParagraphElement]"
+
+
+String($('#foo', 'non-node'))
+"[object HTMLParagraphElement]"
+
+
+String($('#foo', $('#bar')))
+"null"
+
+
+String($$('p#foo'))
+"[object NodeList]"
+
+
+String($$('p#foo', document.body))
+"[object NodeList]"
+
+
+String($('foo'))
+The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $("#foo")
+

Modified: trunk/LayoutTests/inspector/console/command-line-api-inspect-expected.txt (127265 => 127266)


--- trunk/LayoutTests/inspector/console/command-line-api-inspect-expected.txt	2012-08-31 15:36:04 UTC (rev 127265)
+++ trunk/LayoutTests/inspector/console/command-line-api-inspect-expected.txt	2012-08-31 15:40:14 UTC (rev 127266)
@@ -6,7 +6,7 @@
 
 WebInspector.inspect called with: <p>
 WebInspector.inspect's hints are: []
-inspect($('p1')) = 
+inspect($('#p1')) = 
 Selected node id: 'p1'.
 
 Running: testRevealDatabase

Modified: trunk/LayoutTests/inspector/console/command-line-api-inspect.html (127265 => 127266)


--- trunk/LayoutTests/inspector/console/command-line-api-inspect.html	2012-08-31 15:36:04 UTC (rev 127265)
+++ trunk/LayoutTests/inspector/console/command-line-api-inspect.html	2012-08-31 15:40:14 UTC (rev 127266)
@@ -33,7 +33,7 @@
         function testRevealElement(next)
         {
             InspectorTest.addSniffer(WebInspector, "_updateFocusedNode", step2);
-            evalAndDump("inspect($('p1'))");
+            evalAndDump("inspect($('#p1'))");
 
             function step2()
             {

Modified: trunk/LayoutTests/inspector/console/command-line-api.html (127265 => 127266)


--- trunk/LayoutTests/inspector/console/command-line-api.html	2012-08-31 15:36:04 UTC (rev 127265)
+++ trunk/LayoutTests/inspector/console/command-line-api.html	2012-08-31 15:40:14 UTC (rev 127266)
@@ -1,18 +1,24 @@
 <html>
 <head>
 <script src=""
+<script src=""
 <script src=""
 <script>
 
 var test = function()
 {
     var expressions = [
-        "$0.toString()",
+        "String($0)",
         "$3",
-        "keys([3,4]).toString()",
-        "values([3,4]).toString()",
-        "$('foo').toString()",
-        "$$('p#foo').toString()"
+        "String(keys([3,4]))",
+        "String(values([3,4]))",
+        "String($('#foo'))",
+        "String($('#foo', document.body))",
+        "String($('#foo', 'non-node'))",
+        "String($('#foo', $('#bar')))",
+        "String($$('p#foo'))",
+        "String($$('p#foo', document.body))",
+        "String($('foo'))"
     ];
 
     InspectorTest.selectNodeWithId("foo", step1);
@@ -20,12 +26,14 @@
     function step1(node)
     {
         if (!expressions.length) {
+            InspectorTest.dumpConsoleMessages();
             InspectorTest.completeTest();
             return;
         }
         var _expression_ = expressions[0];
         expressions.splice(0, 1);
-        InspectorTest.evaluateInConsoleAndDump(_expression_, step1);
+        WebInspector.log("\n");
+        InspectorTest.evaluateInConsole(_expression_, step1);
     }
 }
 
@@ -35,7 +43,7 @@
 <body _onload_="runTest()">
 <p id="foo">
 Tests that command line api works.
-</p>
+</p><p id="bar"></p>
 
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (127265 => 127266)


--- trunk/Source/WebCore/ChangeLog	2012-08-31 15:36:04 UTC (rev 127265)
+++ trunk/Source/WebCore/ChangeLog	2012-08-31 15:40:14 UTC (rev 127266)
@@ -1,3 +1,16 @@
+2012-08-31  Pavel Feldman  <[email protected]>
+
+        Web Inspector: Update $ to alias to querySelector rather than getElementById
+        https://bugs.webkit.org/show_bug.cgi?id=92648
+
+        Reviewed by Yury Semikhatsky.
+
+        Completed implementation started by Addy Osmani. Updates $ to alias to querySelector
+        with more flexible handling of selectors. Also adds a warning about the change (as per Firebug).
+
+        * inspector/InjectedScriptSource.js:
+        (.):
+
 2012-08-31  Andrey Kosyakov  <[email protected]>
 
         Web Inspector: disable popover on click outside of popover anchor

Modified: trunk/Source/WebCore/inspector/InjectedScriptSource.js (127265 => 127266)


--- trunk/Source/WebCore/inspector/InjectedScriptSource.js	2012-08-31 15:36:04 UTC (rev 127265)
+++ trunk/Source/WebCore/inspector/InjectedScriptSource.js	2012-08-31 15:40:14 UTC (rev 127266)
@@ -937,16 +937,52 @@
 }
 
 CommandLineAPIImpl.prototype = {
-    $: function()
+    /**
+     * @param {string} selector
+     * @param {Node=} start
+     */
+    $: function (selector, start)
     {
-        return document.getElementById.apply(document, arguments)
+        if (this._canQuerySelectorOnNode(start))
+            return start.querySelector(selector);
+
+        var result = document.querySelector(selector);
+        if (result)
+            return result;
+        if (selector && selector[0] !== "#") {
+            result = document.getElementById(selector);
+            if (result) {
+                console.warn("The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $(\"#%s\")", selector );
+                return null;
+            }
+        }
+        return result;
     },
 
-    $$: function()
+    /**
+     * @param {string} selector
+     * @param {Node=} start
+     */
+    $$: function (selector, start)
     {
-        return document.querySelectorAll.apply(document, arguments)
+        if (this._canQuerySelectorOnNode(start))
+            return start.querySelectorAll(selector);
+        return document.querySelectorAll(selector);
     },
 
+    /**
+     * @param {Node} node
+     * @return {boolean}
+     */
+    _canQuerySelectorOnNode: function(node)
+    {
+        return !!node && InjectedScriptHost.type(node) === "node" && (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE);
+    },
+
+    /**
+     * @param {string} xpath
+     * @param {Node=} context
+     */
     $x: function(xpath, context)
     {
         var doc = (context && context.ownerDocument) || inspectedWindow.document;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to