Bug 1538781 - Use the right thread for console evaluations when paused in a worker thread's frame, r=nchevobbe.

Differential Revision: https://phabricator.services.mozilla.com/D27625

--HG--
extra : rebase_source : 40502542b215c47145deea98bbcf826d61e8bc62
This commit is contained in:
Brian Hackett 2019-04-15 13:27:53 -10:00
Родитель 4b0a8ec90f
Коммит 535c0317a3
10 изменённых файлов: 92 добавлений и 9 удалений

Просмотреть файл

@ -139,6 +139,10 @@ DebuggerPanel.prototype = {
return { frames, selected };
},
lookupConsoleClient: function(thread) {
return this._client.lookupConsoleClient(thread);
},
getMappedExpression(expression) {
return this._actions.getMappedExpression(expression);
},

Просмотреть файл

@ -512,7 +512,8 @@ const clientCommands = {
setEventListenerBreakpoints,
waitForWorkers,
detachWorkers,
hasWasmSupport
hasWasmSupport,
lookupConsoleClient
};
export { setupCommands, clientCommands };

Просмотреть файл

@ -26,7 +26,7 @@ function autocompleteUpdate(force, getterPath) {
}
const inputValue = services.getInputValue();
const frameActorId = services.getFrameActor();
const { frameActor: frameActorId, client } = services.getFrameActor();
const cursor = services.getInputCursor();
const state = getState().autocomplete;
@ -73,7 +73,7 @@ function autocompleteUpdate(force, getterPath) {
return dispatch(autocompleteDataFetch({
input,
frameActorId,
client: services.getWebConsoleClient(),
client,
authorizedEvaluations,
force,
}));

Просмотреть файл

@ -674,8 +674,11 @@ class JSTerm extends Component {
"lines": str.split(/\n/).length,
});
return this.webConsoleClient.evaluateJSAsync(str, {
frameActor: this.props.serviceContainer.getFrameActor(options.frame),
const { frameActor, client } =
this.props.serviceContainer.getFrameActor(options.frame);
return client.evaluateJSAsync(str, {
frameActor,
...options,
});
}

Просмотреть файл

@ -50,6 +50,8 @@ support-files =
test-error-worker2.js
test-eval-in-stackframe.html
test-eval-sources.html
test-evaluate-worker.html
test-evaluate-worker.js
test-external-script-errors.html
test-external-script-errors.js
test-iframe-insecure-form-action.html
@ -412,3 +414,4 @@ tags = trackingprotection
[browser_webconsole_warning_groups.js]
[browser_webconsole_websocket.js]
[browser_webconsole_worker_error.js]
[browser_webconsole_worker_evaluate.js]

Просмотреть файл

@ -0,0 +1,32 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// When the debugger is paused in a worker thread, console evaluations should
// be performed in that worker's selected frame.
"use strict";
const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
"test/mochitest/test-evaluate-worker.html";
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
const {jsterm} = hud;
await openDebugger();
const toolbox = gDevTools.getToolbox(hud.target);
const dbg = createDebuggerContext(toolbox);
jsterm.execute("pauseInWorker(42)");
await waitForPaused(dbg);
await openConsole();
const onMessage = waitForMessage(hud, "42");
jsterm.execute("data");
await onMessage;
ok(true, "Evaluated console message in worker thread");
});

Просмотреть файл

@ -0,0 +1,9 @@
<script>
"use strict";
var w = new Worker("test-evaluate-worker.js");
// eslint-disable-next-line no-unused-vars
function pauseInWorker(value) {
w.postMessage(value);
}
</script>

Просмотреть файл

@ -0,0 +1,8 @@
"use strict";
self.addEventListener("message", ({ data }) => foo(data));
function foo(data) {
// eslint-disable-next-line no-debugger
debugger;
}

Просмотреть файл

@ -131,19 +131,30 @@ class WebConsoleWrapper {
* frame depth given.
*
* @param {Number} frame: optional frame depth.
* @return {String|null}: The FrameActor ID for the given frame depth (or the
* selected frame if it exists).
* @return { frameActor: String|null, client: Object }:
* frameActor is the FrameActor ID for the given frame depth
* (or the selected frame if it exists), null if no frame was found.
* client is the WebConsole client for the thread the frame is
* associated with.
*/
getFrameActor: (frame = null) => {
const state = this.hud.getDebuggerFrames();
if (!state) {
return null;
return { frameActor: null, client: webConsoleUI.webConsoleClient };
}
const grip = Number.isInteger(frame)
? state.frames[frame]
: state.frames[state.selected];
return grip ? grip.actor : null;
if (!grip) {
return { frameActor: null, client: webConsoleUI.webConsoleClient };
}
return {
frameActor: grip.actor,
client: this.hud.lookupConsoleClient(grip.thread),
};
},
inputHasSelection: () => {

Просмотреть файл

@ -252,6 +252,18 @@ class WebConsole {
return panel.getFrames();
}
/**
* Return the console client to use when interacting with a thread.
*
* @param {String} thread: The ID of the target thread.
* @returns {Object} The console client associated with the thread.
*/
lookupConsoleClient(thread) {
const toolbox = gDevTools.getToolbox(this.target);
const panel = toolbox.getPanel("jsdebugger");
return panel.lookupConsoleClient(thread);
}
/**
* Given an expression, returns an object containing a new expression, mapped by the
* parser worker to provide additional feature for the user (top-level await,