Web Inspector: store last evaluation result in $_
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Aug 2012 13:21:41 +0000 (13:21 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Aug 2012 13:21:41 +0000 (13:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93377

Reviewed by Vsevolod Vlasov.

Source/WebCore:

All "console" evaluations end up in that variable on command line API.

Test: inspector/console/console-last-result.html

* inspector/InjectedScriptSource.js:
(.):

LayoutTests:

* inspector/console/console-last-result-expected.txt: Added.
* inspector/console/console-last-result.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/console/console-last-result-expected.txt [new file with mode: 0644]
LayoutTests/inspector/console/console-last-result.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/InjectedScriptSource.js

index 9f2fc99..3470a73 100644 (file)
@@ -1,3 +1,13 @@
+2012-08-08  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: store last evaluation result in $_
+        https://bugs.webkit.org/show_bug.cgi?id=93377
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/console/console-last-result-expected.txt: Added.
+        * inspector/console/console-last-result.html: Added.
+
 2012-08-08  KwangYong Choi  <ky0.choi@samsung.com>
 
         [EFL] Support DataList for <input type="range">
diff --git a/LayoutTests/inspector/console/console-last-result-expected.txt b/LayoutTests/inspector/console/console-last-result-expected.txt
new file mode 100644 (file)
index 0000000..000dce6
--- /dev/null
@@ -0,0 +1,7 @@
+Tests that console exposes last evaluation result as $_.
+
+1+1
+2
+$_
+2
+
diff --git a/LayoutTests/inspector/console/console-last-result.html b/LayoutTests/inspector/console/console-last-result.html
new file mode 100644 (file)
index 0000000..7464587
--- /dev/null
@@ -0,0 +1,32 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/console-test.js"></script>
+<script>
+
+function test()
+{
+    InspectorTest.evaluateInConsole("1+1", step1);
+
+    function step1()
+    {
+        InspectorTest.evaluateInConsole("$_", callback);
+    }
+
+    function callback()
+    {
+        InspectorTest.dumpConsoleMessages();
+        InspectorTest.completeTest();
+    }
+}
+
+</script>
+</head>
+
+<body onload="runTest()">
+<p>
+    Tests that console exposes last evaluation result as $_.
+</p>
+
+</body>
+</html>
index 16e04c5..0e254d3 100644 (file)
@@ -1,3 +1,17 @@
+2012-08-08  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: store last evaluation result in $_
+        https://bugs.webkit.org/show_bug.cgi?id=93377
+
+        Reviewed by Vsevolod Vlasov.
+
+        All "console" evaluations end up in that variable on command line API.
+
+        Test: inspector/console/console-last-result.html
+
+        * inspector/InjectedScriptSource.js:
+        (.):
+
 2012-08-08  Simon Hausmann  <simon.hausmann@nokia.com>
 
         [Qt] Port internal findMethodIndex method matcher to use JSC C API
index 0335c98..0f68f82 100644 (file)
@@ -404,7 +404,7 @@ InjectedScript.prototype = {
     {
         try {
             return { wasThrown: false,
-                     result: this._wrapObject(this._evaluateOn(evalFunction, object, expression, isEvalOnCallFrame, injectCommandLineAPI), objectGroup, returnByValue) };
+                     result: this._wrapObject(this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI), objectGroup, returnByValue) };
         } catch (e) {
             return this._createThrownValue(e, objectGroup);
         }
@@ -428,12 +428,13 @@ InjectedScript.prototype = {
     /**
      * @param {Function} evalFunction
      * @param {Object} object
+     * @param {string} objectGroup
      * @param {string} expression
      * @param {boolean} isEvalOnCallFrame
      * @param {boolean} injectCommandLineAPI
      * @return {*}
      */
-    _evaluateOn: function(evalFunction, object, expression, isEvalOnCallFrame, injectCommandLineAPI)
+    _evaluateOn: function(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI)
     {
         // Only install command line api object for the time of evaluation.
         // Surround the expression in with statements to inject our command line API so that
@@ -444,7 +445,10 @@ InjectedScript.prototype = {
                 inspectedWindow.console._commandLineAPI = new CommandLineAPI(this._commandLineAPIImpl, isEvalOnCallFrame ? object : null);
                 expression = "with ((window && window.console && window.console._commandLineAPI) || {}) {\n" + expression + "\n}";
             }
-            return evalFunction.call(object, expression);
+            var result = evalFunction.call(object, expression);
+            if (objectGroup === "console")
+                this._lastResult = result;
+            return result;
         } finally {
             if (injectCommandLineAPI && inspectedWindow.console)
                 delete inspectedWindow.console._commandLineAPI;
@@ -797,6 +801,8 @@ function CommandLineAPI(commandLineAPIImpl, callFrame)
 
         this.__defineGetter__("$" + i, commandLineAPIImpl._inspectedObject.bind(commandLineAPIImpl, i));
     }
+
+    this.$_ = injectedScript._lastResult;
 }
 
 /**