From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../webconsole/commands/experimental-commands.ftl | 22 ++++++++++++-- .../server/actors/webconsole/commands/manager.js | 35 ++++++++++++++++++++-- .../actors/webconsole/eager-ecma-allowlist.js | 23 +++++--------- .../server/actors/webconsole/eval-with-debugger.js | 20 +++++++++---- .../webconsole/listeners/console-file-activity.js | 2 +- .../actors/webconsole/listeners/document-events.js | 10 ++----- 6 files changed, 77 insertions(+), 35 deletions(-) (limited to 'devtools/server/actors/webconsole') diff --git a/devtools/server/actors/webconsole/commands/experimental-commands.ftl b/devtools/server/actors/webconsole/commands/experimental-commands.ftl index b11c29006b..66cb9d151e 100644 --- a/devtools/server/actors/webconsole/commands/experimental-commands.ftl +++ b/devtools/server/actors/webconsole/commands/experimental-commands.ftl @@ -9,13 +9,29 @@ webconsole-commands-usage-trace3 = :trace - Toggles the JavaScript tracer + Toggles the JavaScript tracer. + + The tracer will display all functions being called by your page. It supports the following arguments: - --logMethod to be set to ‘console’ for logging to the web console (the default), or ‘stdout’ for logging to the standard output, + --logMethod to be set to ‘console’ for logging to the web console (the default), or ‘stdout’ for logging to the standard output. + + --return Optional flag to be passed to also log when functions return. + --values Optional flag to be passed to log function call arguments as well as returned values (when returned frames are enabled). + --on-next-interaction Optional flag, when set, the tracer will only start on next mousedown or keydown event. + + --dom-mutations Optional flag, when set, the tracer will log all DOM Mutations. + When passing a value, you can restrict to a particular mutation type via a coma-separated list: + - ‘add’ will only track DOM Node being added, + - ‘attributes’ will only track DOM Node whose attributes changed, + - ‘remove’ will only track DOM Node being removed. + --max-depth Optional flag, will restrict logging trace to a given depth passed as argument. + --max-records Optional flag, will automatically stop the tracer after having logged the passed amount of top level frames. - --prefix Optional string which will be logged in front of all the trace logs, + + --prefix Optional string which will be logged in front of all the trace logs. + --help or --usage to show this message. diff --git a/devtools/server/actors/webconsole/commands/manager.js b/devtools/server/actors/webconsole/commands/manager.js index 538ee7eac1..025e197e3b 100644 --- a/devtools/server/actors/webconsole/commands/manager.js +++ b/devtools/server/actors/webconsole/commands/manager.js @@ -11,6 +11,13 @@ loader.lazyRequireGetter( true ); +loader.lazyRequireGetter( + this, + ["DOM_MUTATIONS"], + "resource://devtools/server/tracer/tracer.jsm", + true +); + loader.lazyGetter(this, "l10n", () => { return new Localization( [ @@ -88,7 +95,7 @@ const WebConsoleCommandsManager = { * } * }); */ - register({ name, isSideEffectFree, command, validArguments, usage }) { + register({ name, isSideEffectFree, command, validArguments }) { if ( typeof command != "function" && !(typeof command == "object" && typeof command.get == "function") @@ -684,7 +691,7 @@ WebConsoleCommandsManager.register({ WebConsoleCommandsManager.register({ name: "help", isSideEffectFree: false, - command(owner, args) { + command(owner) { owner.helperResult = { type: "help" }; }, }); @@ -873,13 +880,35 @@ WebConsoleCommandsManager.register({ const tracerActor = owner.consoleActor.parentActor.getTargetScopedActor("tracer"); const logMethod = args.logMethod || "console"; + let traceDOMMutations = null; + if ("dom-mutations" in args) { + // When no value is passed, track all types of mutations + if (args["dom-mutations"] === true) { + traceDOMMutations = ["add", "attributes", "remove"]; + } else if (typeof args["dom-mutations"] == "string") { + // Otherwise consider the value as coma seperated list and remove any white space. + traceDOMMutations = args["dom-mutations"].split(",").map(e => e.trim()); + const acceptedValues = Object.values(DOM_MUTATIONS); + if (!traceDOMMutations.every(e => acceptedValues.includes(e))) { + throw new Error( + `:trace --dom-mutations only accept a list of strings whose values can be: ${acceptedValues}` + ); + } + } else { + throw new Error( + ":trace --dom-mutations accept only no arguments, or a list mutation type strings (add,attributes,remove)" + ); + } + } // Note that toggleTracing does some sanity checks and will throw meaningful error // when the arguments are wrong. const enabled = tracerActor.toggleTracing({ logMethod, prefix: args.prefix || null, + traceFunctionReturn: !!args.returns, traceValues: !!args.values, traceOnNextInteraction: args["on-next-interaction"] || null, + traceDOMMutations, maxDepth: args["max-depth"] || null, maxRecords: args["max-records"] || null, }); @@ -895,7 +924,9 @@ WebConsoleCommandsManager.register({ "max-depth", "max-records", "on-next-interaction", + "dom-mutations", "prefix", + "returns", "values", ], }); diff --git a/devtools/server/actors/webconsole/eager-ecma-allowlist.js b/devtools/server/actors/webconsole/eager-ecma-allowlist.js index defe98ad8b..041a4c4194 100644 --- a/devtools/server/actors/webconsole/eager-ecma-allowlist.js +++ b/devtools/server/actors/webconsole/eager-ecma-allowlist.js @@ -46,7 +46,11 @@ const functionAllowList = [ Array.prototype.reduceRight, Array.prototype.slice, Array.prototype.some, + Array.prototype.toReversed, + Array.prototype.toSorted, + Array.prototype.toSpliced, Array.prototype.values, + Array.prototype.with, ArrayBuffer, ArrayBuffer.isView, ArrayBuffer.prototype.slice, @@ -94,7 +98,10 @@ const functionAllowList = [ TypedArray.prototype.slice, TypedArray.prototype.some, TypedArray.prototype.subarray, + TypedArray.prototype.toReversed, + TypedArray.prototype.toSorted, TypedArray.prototype.values, + TypedArray.prototype.with, ...allProperties(JSON), Map, Map.prototype.forEach, @@ -230,20 +237,4 @@ const getterAllowList = [ getter(TypedArray, Symbol.species), ]; -// TODO: Integrate in main list when changes array by copy ships by default -const changesArrayByCopy = [ - Array.prototype.toReversed, - Array.prototype.toSorted, - Array.prototype.toSpliced, - Array.prototype.with, - TypedArray.prototype.toReversed, - TypedArray.prototype.toSorted, - TypedArray.prototype.with, -]; -for (const fn of changesArrayByCopy) { - if (typeof fn == "function") { - functionAllowList.push(fn); - } -} - module.exports = { functions: functionAllowList, getters: getterAllowList }; diff --git a/devtools/server/actors/webconsole/eval-with-debugger.js b/devtools/server/actors/webconsole/eval-with-debugger.js index d422d6cd5e..34836c354f 100644 --- a/devtools/server/actors/webconsole/eval-with-debugger.js +++ b/devtools/server/actors/webconsole/eval-with-debugger.js @@ -8,9 +8,15 @@ const Debugger = require("Debugger"); const DevToolsUtils = require("resource://devtools/shared/DevToolsUtils.js"); const lazy = {}; -ChromeUtils.defineESModuleGetters(lazy, { - Reflect: "resource://gre/modules/reflect.sys.mjs", -}); +if (!isWorker) { + ChromeUtils.defineESModuleGetters( + lazy, + { + Reflect: "resource://gre/modules/reflect.sys.mjs", + }, + { global: "contextual" } + ); +} loader.lazyRequireGetter( this, ["isCommand"], @@ -600,8 +606,12 @@ function nativeIsEagerlyEvaluateable(fn) { return true; } + // This needs to use isSameNativeWithJitInfo instead of isSameNative, given + // DOM methods share single native function with different JSJitInto, + // and isSameNative cannot distinguish between side-effect-free methods + // and others. const natives = gSideEffectFreeNatives.get(fn.name); - return natives && natives.some(n => fn.isSameNative(n)); + return natives && natives.some(n => fn.isSameNativeWithJitInfo(n)); } function updateConsoleInputEvaluation(dbg, webConsole) { @@ -616,7 +626,7 @@ function updateConsoleInputEvaluation(dbg, webConsole) { } } -function getEvalInput(string, bindings) { +function getEvalInput(string) { const trimmedString = string.trim(); // Add easter egg for console.mihai(). if ( diff --git a/devtools/server/actors/webconsole/listeners/console-file-activity.js b/devtools/server/actors/webconsole/listeners/console-file-activity.js index 7e5ae0d1a8..ccc28c3b2a 100644 --- a/devtools/server/actors/webconsole/listeners/console-file-activity.js +++ b/devtools/server/actors/webconsole/listeners/console-file-activity.js @@ -82,7 +82,7 @@ ConsoleFileActivityListener.prototype = { * URI has been loaded, then the remote Web Console instance is notified. * @private */ - _checkFileActivity(progress, request, state, status) { + _checkFileActivity(progress, request, state) { if (!(state & Ci.nsIWebProgressListener.STATE_START)) { return; } diff --git a/devtools/server/actors/webconsole/listeners/document-events.js b/devtools/server/actors/webconsole/listeners/document-events.js index 1c1f926436..42296bf62e 100644 --- a/devtools/server/actors/webconsole/listeners/document-events.js +++ b/devtools/server/actors/webconsole/listeners/document-events.js @@ -90,13 +90,7 @@ DocumentEventsListener.prototype = { }); }, - onWillNavigate({ - window, - isTopLevel, - newURI, - navigationStart, - isFrameSwitching, - }) { + onWillNavigate({ isTopLevel, newURI, navigationStart, isFrameSwitching }) { // Ignore iframes if (!isTopLevel) { return; @@ -177,7 +171,7 @@ DocumentEventsListener.prototype = { }); }, - onStateChange(progress, request, flag, status) { + onStateChange(progress, request, flag) { progress.QueryInterface(Ci.nsIDocShell); // Ignore destroyed, or progress for same-process iframes if (progress.isBeingDestroyed() || progress != this.webProgress) { -- cgit v1.2.3