Bug 1287889 - Adopt webconsole _lastConsoleInputEvaluation when the debugger changes. r?bgrinstead draft
authorLuca Greco <lgreco@mozilla.com>
Mon, 25 Jul 2016 10:09:14 +0200
changeset 392959 5d4c9e9ae90a2824eef4cc6ed175e175e43d1125
parent 392958 4b8fcc9be4e9f0e9d4735e90c58f8f923421a02f
child 392960 9b8306225d09623d5fdba95cae332a3452ecb83a
push id24157
push userluca.greco@alcacoop.it
push dateTue, 26 Jul 2016 16:01:12 +0000
reviewersbgrinstead
bugs1287889
milestone50.0a1
Bug 1287889 - Adopt webconsole _lastConsoleInputEvaluation when the debugger changes. r?bgrinstead MozReview-Commit-ID: 8ujphVlekIL
devtools/client/debugger/test/mochitest/browser_dbg_split-console-paused-reload.js
devtools/client/debugger/test/mochitest/doc_split-console-paused-reload.html
devtools/server/actors/webconsole.js
--- a/devtools/client/debugger/test/mochitest/browser_dbg_split-console-paused-reload.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg_split-console-paused-reload.js
@@ -32,17 +32,36 @@ function* runTests() {
   yield ensureThreadClientState(panel, "paused");
   info("Breakpoint was hit.");
   EventUtils.sendMouseEvent({ type: "mousedown" },
     frames.selectedItem.target,
     dbgWin);
   info("The breadcrumb received focus.");
 
   // This is the meat of the test.
-  let result = toolbox.once("webconsole-ready", () => {
-    ok(toolbox.splitConsole, "Split console is shown.");
-    is(dbgWin.gThreadClient.state, "paused", "Execution is still paused.");
-    Services.prefs.clearUserPref("devtools.toolbox.splitconsoleEnabled");
-  });
-  EventUtils.synthesizeKey("VK_ESCAPE", {}, dbgWin);
-  yield result;
-  yield resumeDebuggerThenCloseAndFinish(panel);
+  let jsterm = yield getSplitConsole(toolbox);
+
+  is(dbgWin.gThreadClient.state, "paused", "Execution is still paused.");
+
+  let dbgFrameConsoleEvalResult = yield jsterm.execute("privateVar");
+
+  is(
+    dbgFrameConsoleEvalResult.querySelector(".console-string").textContent,
+    '"privateVarValue"',
+    "Got the expected split console result on paused debugger"
+  );
+
+  yield dbgWin.gThreadClient.resume();
+
+  is(dbgWin.gThreadClient.state, "attached", "Execution is resumed.");
+
+  // Get the last evaluation result adopted by the new debugger.
+  let mainTargetConsoleEvalResult = yield jsterm.execute("$_");
+
+  is(
+    mainTargetConsoleEvalResult.querySelector(".console-string").textContent,
+    '"privateVarValue"',
+    "Got the expected split console log on $_ executed on resumed debugger"
+  );
+
+  Services.prefs.clearUserPref("devtools.toolbox.splitconsoleEnabled");
+  yield closeDebuggerAndFinish(panel);
 }
--- a/devtools/client/debugger/test/mochitest/doc_split-console-paused-reload.html
+++ b/devtools/client/debugger/test/mochitest/doc_split-console-paused-reload.html
@@ -5,16 +5,18 @@
 <html>
   <head>
     <meta charset="utf-8"/>
     <title>Test page for opening a split-console when execution is paused</title>
   </head>
 
   <body>
     <script type="text/javascript">
-      function runDebuggerStatement() {
-        debugger;
+      function executeFunction() {
+        let privateVar = { propKey: "privateVarValue" };
+
+        window.foobar = "foobar";
       }
-      window.foobar = 1;
+      executeFunction();
     </script>
   </body>
 
 </html>
--- a/devtools/server/actors/webconsole.js
+++ b/devtools/server/actors/webconsole.js
@@ -1291,17 +1291,29 @@ WebConsoleActor.prototype =
     // Ready to evaluate the string.
     helpers.evalInput = aString;
 
     let evalOptions;
     if (typeof aOptions.url == "string") {
       evalOptions = { url: aOptions.url };
     }
 
+    // If the debugger object is changed from the last evaluation,
+    // adopt this._lastConsoleInputEvaluation value in the new debugger,
+    // to prevents "Debugger.Object belongs to a different Debugger" exceptions
+    // related to the $_ bindings.
+    if (this._lastConsoleInputEvaluation &&
+        this._lastConsoleInputEvaluation.global !== dbgWindow) {
+      this._lastConsoleInputEvaluation = dbg.adoptDebuggeeValue(
+        this._lastConsoleInputEvaluation
+      );
+    }
+
     let result;
+
     if (frame) {
       result = frame.evalWithBindings(aString, bindings, evalOptions);
     }
     else {
       result = dbgWindow.executeInGlobalWithBindings(aString, bindings, evalOptions);
       // Attempt to initialize any declarations found in the evaluated string
       // since they may now be stuck in an "initializing" state due to the
       // error. Already-initialized bindings will be ignored.