Bug 1287889 - Adopt webconsole _lastConsoleInputEvaluation when the debugger changes. r?bgrinstead
MozReview-Commit-ID: 8ujphVlekIL
--- 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.