Bug 1789202 - [devtools] Expose ChromeUtils as a global to all DevTools modules. r=perftest-reviewers,nchevobbe,AlexandruIonescu

This will help transition to ES Modules as this symbol is exposed to them.

$ sed -ie "/require(.ChromeUtils.)/d" $(git grep -l 'require("ChromeUtils")' devtools/)
$ sed -ie "/loader.lazyRequireGetter(this, .ChromeUtils./d" $(git grep -l 'loader.lazyRequireGetter(this, "ChromeUtils"' devtools/)
+ the edition of builtin-modules.js + eslintrc.js + manual eslint fixes

Differential Revision: https://phabricator.services.mozilla.com/D156402
This commit is contained in:
Alexandre Poirot 2022-09-09 07:22:51 +00:00
parent 7f9229d43d
commit 573f380baf
51 changed files with 5 additions and 54 deletions

View File

@ -12,8 +12,6 @@
* browser window is ready (i.e. fired browser-delayed-startup-finished event)
**/
const ChromeUtils = require("ChromeUtils");
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
BrowserToolboxLauncher:

View File

@ -5,7 +5,6 @@
"use strict";
const { Cu } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const {
DevToolsShim,

View File

@ -27,7 +27,6 @@ var { Ci, Cc } = require("chrome");
const { debounce } = require("devtools/shared/debounce");
const { throttle } = require("devtools/shared/throttle");
const { safeAsyncMethod } = require("devtools/shared/async-utils");
var ChromeUtils = require("ChromeUtils");
var { gDevTools } = require("devtools/client/framework/devtools");
var EventEmitter = require("devtools/shared/event-emitter");
const Selection = require("devtools/client/framework/selection");

View File

@ -18,7 +18,6 @@ loader.lazyRequireGetter(
"devtools/shared/dom-node-constants"
);
const ChromeUtils = require("ChromeUtils");
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);

View File

@ -4,7 +4,6 @@
"use strict";
const ChromeUtils = require("ChromeUtils");
const { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js"
);

View File

@ -5,7 +5,6 @@
"use strict";
const { components, Ci, Cr, Cu, CC } = require("chrome");
const ChromeUtils = require("ChromeUtils");
loader.lazyRequireGetter(
this,

View File

@ -5,7 +5,6 @@
"use strict";
const EventEmitter = require("devtools/shared/event-emitter");
const ChromeUtils = require("ChromeUtils");
const HeapAnalysesClient = require("devtools/shared/heapsnapshot/HeapAnalysesClient");
function MemoryPanel(iframeWindow, toolbox, commands) {

View File

@ -26,7 +26,6 @@
*/
const { Cu } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {

View File

@ -21,7 +21,6 @@
* * @typedef {import("./@types/perf").ProfilerViewMode} ProfilerViewMode
*/
const ChromeUtils = require("ChromeUtils");
const { createLazyLoaders } = ChromeUtils.import(
"resource://devtools/client/performance-new/typescript-lazy-load.jsm.js"
);

View File

@ -9,7 +9,6 @@ const L10N = new LocalizationHelper(
"devtools/client/locales/device.properties"
);
const ChromeUtils = require("ChromeUtils");
const { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js"
);

View File

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const ChromeUtils = require("ChromeUtils");
const { Cu } = require("chrome");
/**

View File

@ -4,7 +4,6 @@
"use strict";
const ChromeUtils = require("ChromeUtils");
const { Cu } = require("chrome");
const { dumpn } = require("devtools/shared/DevToolsUtils");

View File

@ -15,10 +15,10 @@ module.exports = {
"^devtools/shared/DevToolsUtils": `${fixturesDir}/devtools-utils`,
// This is needed for the Debugger, for some reason
"shared/DevToolsUtils$": `${fixturesDir}/devtools-utils`,
"^ChromeUtils": `${fixturesDir}/ChromeUtils`,
// Mocks only used by node tests.
"Services-mock": `${fixturesDir}/Services`,
"ChromeUtils-mock": `${fixturesDir}/ChromeUtils`,
"^promise": `${fixturesDir}/promise`,
"^chrome": `${fixturesDir}/Chrome`,

View File

@ -11,6 +11,7 @@
*/
function setMocksInGlobal() {
global.Services = require("Services-mock");
global.ChromeUtils = require("ChromeUtils-mock");
global.isWorker = false;

View File

@ -26,7 +26,6 @@ Services.scriptloader.loadSubScript(
EventUtils
);
var ChromeUtils = require("ChromeUtils");
const { TestUtils } = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
);

View File

@ -4,7 +4,6 @@
"use strict";
const ChromeUtils = require("ChromeUtils");
const { BrowserLoader } = ChromeUtils.import(
"resource://devtools/shared/loader/browser-loader.js"
);

View File

@ -106,6 +106,7 @@ global.Services = require(mcRoot +
global.ChromeUtils = {
import: () => {},
defineModuleGetter: () => {},
addProfilerMarker: () => {},
};
global.Cu = { isInAutomation: true };
@ -139,8 +140,6 @@ requireHacker.global_hook("default", (path, module) => {
chrome: () =>
`module.exports = { Cc: {}, Ci: {}, Cu: { now: () => {}}, components: {stack: {caller: ""}} }`,
ChromeUtils: () =>
`module.exports = { addProfilerMarker: () => {}, import: () => ({}) }`,
// Some modules depend on Chrome APIs which don't work in mocha. When such a module
// is required, replace it with a mock version.
"devtools/server/devtools-server": () =>

View File

@ -8,7 +8,6 @@ const EventEmitter = require("devtools/shared/event-emitter");
const KeyShortcuts = require("devtools/client/shared/key-shortcuts");
const { l10n } = require("devtools/client/webconsole/utils/messages");
var ChromeUtils = require("ChromeUtils");
const { BrowserLoader } = ChromeUtils.import(
"resource://devtools/shared/loader/browser-loader.js"
);

View File

@ -9,7 +9,6 @@ const protocol = require("devtools/shared/protocol");
const { Cc, Ci, Cu, Cr } = require("chrome");
const { DevToolsServer } = require("devtools/server/devtools-server");
const ChromeUtils = require("ChromeUtils");
loader.lazyGetter(
this,

View File

@ -6,7 +6,6 @@
const { Ci, Cu } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const EventEmitter = require("devtools/shared/event-emitter");
const protocol = require("devtools/shared/protocol");
const { customHighlighterSpec } = require("devtools/shared/specs/highlighters");

View File

@ -5,7 +5,6 @@
"use strict";
const { Ci } = require("chrome");
loader.lazyRequireGetter(this, "ChromeUtils");
loader.lazyRequireGetter(
this,
"isRemoteBrowserElement",

View File

@ -5,7 +5,6 @@
"use strict";
const { Cc, Ci, Cm, Cr, components } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const { ComponentUtils } = require("resource://gre/modules/ComponentUtils.jsm");
/**

View File

@ -13,7 +13,6 @@
const DEBUG_PLATFORM_EVENTS = false;
const { Cc, Ci } = require("chrome");
const ChromeUtils = require("ChromeUtils");
loader.lazyRequireGetter(
this,

View File

@ -5,7 +5,6 @@
"use strict";
const { Cc, Ci, Cr, components: Components } = require("chrome");
const ChromeUtils = require("ChromeUtils");
loader.lazyRequireGetter(
this,

View File

@ -10,7 +10,6 @@ const protocol = require("devtools/shared/protocol");
const {
propertyIteratorSpec,
} = require("devtools/shared/specs/property-iterator");
loader.lazyRequireGetter(this, "ChromeUtils");
loader.lazyRequireGetter(
this,
"ObjectUtils",

View File

@ -24,7 +24,6 @@
* These dedicated classes are used by the LayoutChangesObserver.
*/
const ChromeUtils = require("ChromeUtils");
const protocol = require("devtools/shared/protocol");
const EventEmitter = require("devtools/shared/event-emitter");
const { reflowSpec } = require("devtools/shared/specs/reflow");

View File

@ -8,7 +8,6 @@ const {
TYPES: { DOCUMENT_EVENT },
} = require("devtools/server/actors/resources/index");
const { Ci } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const isEveryFrameTargetEnabled = Services.prefs.getBoolPref(
"devtools.every-frame-target.enabled",
false

View File

@ -5,7 +5,6 @@
"use strict";
const { Ci, Cu } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const { createStringGrip } = require("devtools/server/actors/object/utils");

View File

@ -60,8 +60,6 @@ loader.lazyRequireGetter(
true
);
loader.lazyRequireGetter(this, "ChromeUtils");
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const SUPPORTED_RULE_TYPES = [

View File

@ -22,7 +22,6 @@
*/
var { Ci, Cu, Cr, Cc } = require("chrome");
const ChromeUtils = require("ChromeUtils");
var { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { assert } = DevToolsUtils;

View File

@ -10,7 +10,6 @@ const { ActorClassWithSpec, Actor } = require("devtools/shared/protocol");
const { webconsoleSpec } = require("devtools/shared/specs/webconsole");
const { Cc, Ci, Cu } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const { DevToolsServer } = require("devtools/server/devtools-server");
const { ThreadActor } = require("devtools/server/actors/thread");
const { ObjectActor } = require("devtools/server/actors/object");

View File

@ -5,7 +5,6 @@
"use strict";
const { Cc, Ci } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const {
CONSOLE_WORKER_IDS,
WebConsoleUtils,

View File

@ -5,7 +5,6 @@
"use strict";
const { Ci } = require("chrome");
const ChromeUtils = require("ChromeUtils");
/**
* A WebProgressListener that listens for file loads.

View File

@ -5,7 +5,6 @@
"use strict";
const { components } = require("chrome");
const ChromeUtils = require("ChromeUtils");
/**
* A ReflowObserver that listens for reflow events from the page.

View File

@ -6,7 +6,6 @@
const { Ci } = require("chrome");
const { isWindowIncluded } = require("devtools/shared/layout/utils");
const ChromeUtils = require("ChromeUtils");
const { WebConsoleUtils } = require("devtools/server/actors/webconsole/utils");
// The page errors listener

View File

@ -8,7 +8,6 @@
const EventEmitter = require("devtools/shared/event-emitter");
const { Ci } = require("chrome");
const ChromeUtils = require("ChromeUtils");
/**
* About "navigationStart - ${WILL_NAVIGATE_TIME_SHIFT}ms":

View File

@ -4,7 +4,6 @@
"use strict";
const ChromeUtils = require("ChromeUtils");
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.sys.mjs");
const protocol = require("devtools/shared/protocol");
const {

View File

@ -21,7 +21,6 @@ loader.lazyRequireGetter(
"devtools/server/actors/utils/stack",
true
);
loader.lazyRequireGetter(this, "ChromeUtils");
loader.lazyRequireGetter(
this,
"ParentProcessTargetActor",

View File

@ -1,7 +1,5 @@
"use strict";
var ChromeUtils = require("ChromeUtils");
exports.setupParent = function({ mm, prefix }) {
const args = [ChromeUtils.getClassName(mm) == "ChromeMessageSender", prefix];
Services.obs.notifyObservers(null, "test:setupParent", JSON.stringify(args));

View File

@ -5,7 +5,6 @@
"use strict";
const { createCommandsDictionary } = require("devtools/shared/commands/index");
const ChromeUtils = require("ChromeUtils");
const { DevToolsLoader } = ChromeUtils.import(
"resource://devtools/shared/loader/Loader.jsm"
);

View File

@ -11,7 +11,6 @@ loader.lazyRequireGetter(
"DevToolsUtils",
"devtools/shared/DevToolsUtils"
);
loader.lazyRequireGetter(this, "ChromeUtils");
loader.lazyRequireGetter(
this,
"NetUtil",

View File

@ -217,7 +217,6 @@ function lazyRequireGetter(obj, properties, module, destructure) {
// List of pseudo modules exposed to all devtools modules.
exports.modules = {
ChromeUtils,
DebuggerNotificationObserver,
HeapSnapshot,
InspectorUtils,
@ -261,6 +260,7 @@ exports.globals = {
Blob,
btoa,
CanonicalBrowsingContext,
ChromeUtils,
BrowsingContext,
WebExtensionPolicy,
WindowGlobalParent,

View File

@ -528,13 +528,13 @@ this.worker = new WorkerDebuggerLoader({
btoa: this.btoa,
atob: this.atob,
Services: Object.create(null),
ChromeUtils,
},
loadSubScript,
modules: {
Debugger,
chrome,
xpcInspector,
ChromeUtils,
DebuggerNotificationObserver,
},
paths: {

View File

@ -7,7 +7,6 @@
const { extend } = require("devtools/shared/extend");
var { Pool } = require("devtools/shared/protocol/Pool");
const { Cu } = require("chrome");
const ChromeUtils = require("ChromeUtils");
/**
* Keep track of which actorSpecs have been created. If a replica of a spec

View File

@ -4,7 +4,6 @@
"use strict";
const ChromeUtils = require("ChromeUtils");
var { settleAll } = require("devtools/shared/DevToolsUtils");
var EventEmitter = require("devtools/shared/event-emitter");

View File

@ -5,7 +5,6 @@
"use strict";
const { Cu } = require("chrome");
const ChromeUtils = require("ChromeUtils");
var { Front } = require("devtools/shared/protocol/Front");
/**

View File

@ -36,7 +36,6 @@
"use strict";
const { Cu, Cc, Ci } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const MemoryReporter = Cc["@mozilla.org/memory-reporter-manager;1"].getService(
Ci.nsIMemoryReporterManager

View File

@ -62,7 +62,6 @@
"use strict";
const ChromeUtils = require("ChromeUtils");
const { components, Cc, Ci } = require("chrome");
loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");

View File

@ -23,7 +23,6 @@ loader.lazyServiceGetter(
"nsIHttpActivityDistributor"
);
const ChromeUtils = require("ChromeUtils");
const { setTimeout } = require("resource://gre/modules/Timer.jsm");
/**

View File

@ -9,7 +9,6 @@
const { Ci, Cc, Cu } = require("chrome");
const { gBrowser, MozillaFileLogger, requestIdleCallback } = dampWindow;
const ChromeUtils = require("ChromeUtils");
const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
const DampLoadParentModule = require("damp-test/actors/DampLoadParent.jsm");

View File

@ -4,7 +4,6 @@
"use strict";
const ChromeUtils = require("ChromeUtils");
const { runTest, testSetup, testTeardown } = require("../head");
const { DevToolsClient } = require("devtools/client/devtools-client");