Added support for some Firebug Command Line APIs.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Aug 2008 03:57:39 +0000 (03:57 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Aug 2008 03:57:39 +0000 (03:57 +0000)
        Reviewed by Tim Hatcher.

        https://bugs.webkit.org/show_bug.cgi?id=19867
        https://bugs.webkit.org/show_bug.cgi?id=19868
        https://bugs.webkit.org/show_bug.cgi?id=19869
        https://bugs.webkit.org/show_bug.cgi?id=19875
        https://bugs.webkit.org/show_bug.cgi?id=19876
        https://bugs.webkit.org/show_bug.cgi?id=19880

        * page/inspector/Console.js:
        (WebInspector.Console.prototype._evalInInspectedWindow):
        Create an object on the inspected window that holds the console
        command line API functions. This object is used in a with statement
        around the typed expression.

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

WebCore/ChangeLog
WebCore/page/inspector/Console.js

index 283031d..a9c55f2 100644 (file)
@@ -1,3 +1,22 @@
+2008-08-11  Keishi Hattori  <casey.hattori@gmail.com>
+
+        Added support for some Firebug Command Line APIs.
+
+        Reviewed by Tim Hatcher.
+
+        https://bugs.webkit.org/show_bug.cgi?id=19867
+        https://bugs.webkit.org/show_bug.cgi?id=19868
+        https://bugs.webkit.org/show_bug.cgi?id=19869
+        https://bugs.webkit.org/show_bug.cgi?id=19875
+        https://bugs.webkit.org/show_bug.cgi?id=19876
+        https://bugs.webkit.org/show_bug.cgi?id=19880
+
+        * page/inspector/Console.js:
+        (WebInspector.Console.prototype._evalInInspectedWindow):
+        Create an object on the inspected window that holds the console
+        command line API functions. This object is used in a with statement
+        around the typed expression.
+
 2008-08-11  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Antti.
index 9b4fa3d..f47875b 100644 (file)
@@ -331,7 +331,31 @@ WebInspector.Console.prototype = {
     {
         if (WebInspector.panels.scripts.paused)
             return WebInspector.panels.scripts.evaluateInSelectedCallFrame(expression);
-        return InspectorController.inspectedWindow().eval(expression);
+
+        var inspectedWindow = InspectorController.inspectedWindow();
+        if (!inspectedWindow._inspectorCommandLineAPI) {
+            inspectedWindow.eval("window._inspectorCommandLineAPI = { \
+                $: function() { return document.getElementById.apply(document, arguments) }, \
+                $$: function() { return document.querySelectorAll.apply(document, arguments) }, \
+                $x: function(xpath, context) { \
+                    var nodes = []; \
+                    try { \
+                        var doc = context || document; \
+                        var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null); \
+                        var node; \
+                        while (node = results.iterateNext()) nodes.push(node); \
+                    } catch (e) {} \
+                    return nodes; \
+                }, \
+                keys: function(o) { var a = []; for (k in o) a.push(k); return a; }, \
+                values: function(o) { var a = []; for (k in o) a.push(o[k]); return a; }, \
+                profile: function() { return console.profile.apply(console, arguments) }, \
+                profileEnd: function() { return console.profileEnd.apply(console, arguments) } \
+            };");
+        }
+
+        expression = "with (window._inspectorCommandLineAPI) { " + expression + " }";
+        return inspectedWindow.eval(expression);
     },
 
     _enterKeyPressed: function(event)