Bug 1921020 - [devtools] Allow evaluating console results reusing the Tracer actor Object Actor Pool. r=devtools-reviewers,devtools-backward-compat-reviewers,nchevobbe

This helps ensure that the object actors returned by the console actor evaluation RDP request
are the same for the same JS values being processed and notified via the tracer ressources.
This allows identifying same objects when doing a search per value.

Differential Revision: https://phabricator.services.mozilla.com/D225237
This commit is contained in:
Alexandre Poirot 2024-11-04 14:42:51 +00:00
parent f44efeef5f
commit 663cd4297a
4 changed files with 37 additions and 9 deletions

View File

@ -268,21 +268,39 @@ async function removeBreakpoint(location) {
});
}
async function evaluateExpressions(scripts, options) {
return Promise.all(scripts.map(script => evaluate(script, options)));
async function evaluateExpressions(expressions, options) {
return Promise.all(
expressions.map(expression => evaluate(expression, options))
);
}
async function evaluate(script, { frameId, threadId } = {}) {
if (!currentTarget() || !script) {
/**
* Evaluate some JS expression in a given thread.
*
* @param {String} expression
* @param {Object} options
* @param {String} options.frameId
* Optional frame actor ID into which the expression should be evaluated.
* @param {String} options.threadId
* Optional thread actor ID into which the expression should be evaluated.
* @param {Boolean} options.evalInTracer
* To be set to true, if the object actors created during the evaluation
* should be registered in the tracer actor Pool.
* @return {Object}
* See ScriptCommand.execute JS Doc.
*/
async function evaluate(expression, { frameId, threadId, evalInTracer } = {}) {
if (!currentTarget() || !expression) {
return { result: null };
}
const selectedTargetFront = threadId ? lookupTarget(threadId) : null;
return commands.scriptCommand.execute(script, {
return commands.scriptCommand.execute(expression, {
frameActor: frameId,
selectedTargetFront,
disableBreaks: true,
evalInTracer,
});
}

View File

@ -908,7 +908,8 @@ class WebConsoleActor extends Actor {
evalInfo,
input,
request.eager,
mapped
mapped,
request.evalInTracer
);
resolve(result);
} catch (err) {
@ -919,7 +920,7 @@ class WebConsoleActor extends Actor {
}
// eslint-disable-next-line complexity
prepareEvaluationResult(evalInfo, input, eager, mapped) {
prepareEvaluationResult(evalInfo, input, eager, mapped, evalInTracer) {
const evalResult = evalInfo.result;
const helperResult = evalInfo.helperResult;
@ -1039,7 +1040,6 @@ class WebConsoleActor extends Actor {
}
}
}
// If a value is encountered that the devtools server doesn't support yet,
// the console should remain functional.
let resultGrip;
@ -1047,7 +1047,10 @@ class WebConsoleActor extends Actor {
try {
const objectActor =
this.targetActor.threadActor.getThreadLifetimeObject(result);
if (objectActor) {
if (evalInTracer) {
const tracerActor = this.targetActor.getTargetScopedActor("tracer");
resultGrip = tracerActor.createValueGrip(result);
} else if (objectActor) {
resultGrip = this.targetActor.threadActor.createValueGrip(result);
} else {
resultGrip = this.createValueGrip(result);

View File

@ -43,6 +43,11 @@ class ScriptCommand {
* visible in the debugger UI.
* @param {boolean} options.preferConsoleCommandsOverLocalSymbols: Set to true to force
* overriding local symbols defined by the page with same-name console commands.
* @param {boolean} options.evalInTracer: Set to true to store the evaluation result object
* actors within the Tracer Object Actor Pool.
* So that if the evaluation result object has already been processed by the JS Tracer,
* we will receive the same Object Actor.
* This helps later match the object when doing a search per value.
*
* @return {Promise}: A promise that resolves with the response.
*/
@ -111,6 +116,7 @@ class ScriptCommand {
disableBreaks: options.disableBreaks,
preferConsoleCommandsOverLocalSymbols:
options.preferConsoleCommandsOverLocalSymbols,
evalInTracer: options.evalInTracer,
})
.then(packet => {
resultID = packet.resultID;

View File

@ -158,6 +158,7 @@ const webconsoleSpecPrototype = {
eager: Option(0, "nullable:boolean"),
disableBreaks: Option(0, "nullable:boolean"),
preferConsoleCommandsOverLocalSymbols: Option(0, "nullable:boolean"),
evalInTracer: Option(0, "nullable:boolean"),
},
response: RetVal("console.evaluatejsasync"),
},