Bug 1789981 - [devtools] Convert last DevTools JSM to ESM. r=devtools-reviewers,nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D202438
This commit is contained in:
Alexandre Poirot 2024-03-26 08:29:22 +00:00
parent d10de08d0d
commit 40ad6a2dc0
15 changed files with 59 additions and 93 deletions

View file

@ -4,8 +4,9 @@
"use strict";
const asyncStoreHelper = require("resource://devtools/client/shared/async-store-helper.js");
const { validateBreakpointLocation } = ChromeUtils.import(
"resource://devtools/shared/validate-breakpoint.jsm"
const { validateBreakpointLocation } = ChromeUtils.importESModule(
"resource://devtools/shared/validate-breakpoint.sys.mjs",
{ global: "contextual" }
);
const asyncStore = asyncStoreHelper("debugger", {

View file

@ -9,9 +9,10 @@ const {
blackboxingSpec,
} = require("resource://devtools/shared/specs/blackboxing.js");
const {
SessionDataHelpers,
} = require("resource://devtools/server/actors/watcher/SessionDataHelpers.jsm");
const { SessionDataHelpers } = ChromeUtils.importESModule(
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
{ global: "contextual" }
);
const { SUPPORTED_DATA } = SessionDataHelpers;
const { BLACKBOXING } = SUPPORTED_DATA;

View file

@ -9,9 +9,10 @@ const {
breakpointListSpec,
} = require("resource://devtools/shared/specs/breakpoint-list.js");
const {
SessionDataHelpers,
} = require("resource://devtools/server/actors/watcher/SessionDataHelpers.jsm");
const { SessionDataHelpers } = ChromeUtils.importESModule(
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
{ global: "contextual" }
);
const { SUPPORTED_DATA } = SessionDataHelpers;
const { BREAKPOINTS, XHR_BREAKPOINTS, EVENT_BREAKPOINTS } = SUPPORTED_DATA;

View file

@ -9,9 +9,10 @@ const {
targetConfigurationSpec,
} = require("resource://devtools/shared/specs/target-configuration.js");
const {
SessionDataHelpers,
} = require("resource://devtools/server/actors/watcher/SessionDataHelpers.jsm");
const { SessionDataHelpers } = ChromeUtils.importESModule(
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
{ global: "contextual" }
);
const { isBrowsingContextPartOfContext } = ChromeUtils.importESModule(
"resource://devtools/server/actors/watcher/browsing-context-helpers.sys.mjs",
{ global: "contextual" }

View file

@ -4,9 +4,10 @@
"use strict";
const {
SessionDataHelpers,
} = require("resource://devtools/server/actors/watcher/SessionDataHelpers.jsm");
const { SessionDataHelpers } = ChromeUtils.importESModule(
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
{ global: "contextual" }
);
const { SUPPORTED_DATA } = SessionDataHelpers;
const SessionDataProcessors = {};

View file

@ -9,9 +9,10 @@ const {
threadConfigurationSpec,
} = require("resource://devtools/shared/specs/thread-configuration.js");
const {
SessionDataHelpers,
} = require("resource://devtools/server/actors/watcher/SessionDataHelpers.jsm");
const { SessionDataHelpers } = ChromeUtils.importESModule(
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
{ global: "contextual" }
);
const {
SUPPORTED_DATA: { THREAD_CONFIGURATION },
} = SessionDataHelpers;

View file

@ -2,49 +2,30 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* Helper module alongside WatcherRegistry, which focus on updating the "sessionData" object.
* This object is shared across processes and threads and have to be maintained in all these runtimes.
*/
var EXPORTED_SYMBOLS = ["SessionDataHelpers"];
const lazy = {};
ChromeUtils.defineESModuleGetters(
lazy,
{
validateBreakpointLocation:
"resource://devtools/shared/validate-breakpoint.sys.mjs",
},
{ global: "contextual" }
);
if (typeof module == "object") {
// Allow this JSM to also be loaded as a CommonJS module
// Because this module is used from the worker thread,
// (via target-actor-mixin), and workers can't load JSMs via ChromeUtils.import.
loader.lazyRequireGetter(
lazy,
"validateBreakpointLocation",
"resource://devtools/shared/validate-breakpoint.jsm",
true
ChromeUtils.defineLazyGetter(lazy, "validateEventBreakpoint", () => {
const { loader } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs",
{ global: "contextual" }
);
loader.lazyRequireGetter(
lazy,
"validateEventBreakpoint",
"resource://devtools/server/actors/utils/event-breakpoints.js",
true
);
} else {
ChromeUtils.defineLazyGetter(lazy, "validateBreakpointLocation", () => {
return ChromeUtils.import(
"resource://devtools/shared/validate-breakpoint.jsm"
).validateBreakpointLocation;
});
ChromeUtils.defineLazyGetter(lazy, "validateEventBreakpoint", () => {
const { loader } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);
return loader.require(
"resource://devtools/server/actors/utils/event-breakpoints.js"
).validateEventBreakpoint;
});
}
return loader.require(
"resource://devtools/server/actors/utils/event-breakpoints.js"
).validateEventBreakpoint;
});
// List of all arrays stored in `sessionData`, which are replicated across processes and threads
const SUPPORTED_DATA = {
@ -151,7 +132,7 @@ function idFunction(v) {
return v;
}
const SessionDataHelpers = {
export const SessionDataHelpers = {
SUPPORTED_DATA,
/**
@ -235,10 +216,3 @@ const SessionDataHelpers = {
return true;
},
};
// Allow this JSM to also be loaded as a CommonJS module
// Because this module is used from the worker thread,
// (via target-actor-mixin), and workers can't load JSMs.
if (typeof module == "object") {
module.exports.SessionDataHelpers = SessionDataHelpers;
}

View file

@ -26,8 +26,9 @@
import { ActorManagerParent } from "resource://gre/modules/ActorManagerParent.sys.mjs";
const { SessionDataHelpers } = ChromeUtils.import(
"resource://devtools/server/actors/watcher/SessionDataHelpers.jsm"
const { SessionDataHelpers } = ChromeUtils.importESModule(
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
{ global: "contextual" }
);
const { SUPPORTED_DATA } = SessionDataHelpers;

View file

@ -11,6 +11,6 @@ DIRS += [
DevToolsModules(
"browsing-context-helpers.sys.mjs",
"session-context.js",
"SessionDataHelpers.jsm",
"SessionDataHelpers.sys.mjs",
"WatcherRegistry.sys.mjs",
)

View file

@ -22,13 +22,11 @@ ChromeUtils.defineLazyGetter(lazy, "Loader", () =>
ChromeUtils.defineLazyGetter(lazy, "DevToolsUtils", () =>
lazy.Loader.require("resource://devtools/shared/DevToolsUtils.js")
);
XPCOMUtils.defineLazyModuleGetters(lazy, {
SessionDataHelpers:
"resource://devtools/server/actors/watcher/SessionDataHelpers.jsm",
});
ChromeUtils.defineESModuleGetters(lazy, {
isWindowGlobalPartOfContext:
"resource://devtools/server/actors/watcher/browsing-context-helpers.sys.mjs",
SessionDataHelpers:
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
});
// Name of the attribute into which we save data in `sharedData` object.

View file

@ -8,6 +8,8 @@ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
loader: "resource://devtools/shared/loader/Loader.sys.mjs",
SessionDataHelpers:
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
});
XPCOMUtils.defineLazyServiceGetter(
@ -17,11 +19,6 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIWorkerDebuggerManager"
);
XPCOMUtils.defineLazyModuleGetters(lazy, {
SessionDataHelpers:
"resource://devtools/server/actors/watcher/SessionDataHelpers.jsm",
});
ChromeUtils.defineLazyGetter(lazy, "DevToolsUtils", () =>
lazy.loader.require("devtools/shared/DevToolsUtils")
);

View file

@ -7,8 +7,9 @@
"use strict";
const { SessionDataHelpers } = ChromeUtils.import(
"resource://devtools/server/actors/watcher/SessionDataHelpers.jsm"
const { SessionDataHelpers } = ChromeUtils.importESModule(
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
{ global: "contextual" }
);
const { SUPPORTED_DATA } = SessionDataHelpers;
const { TARGETS } = SUPPORTED_DATA;

View file

@ -173,9 +173,7 @@ function WorkerDebuggerLoader(options) {
}
// If the url has no extension, use ".js" by default.
// Also allow loading JSMs, but they would need a shim in order to
// be loaded as a CommonJS module. (See SessionDataHelpers.jsm)
return url.endsWith(".js") || url.endsWith(".jsm") ? url : url + ".js";
return url.endsWith(".js") ? url : url + ".js";
}
/**

View file

@ -71,7 +71,7 @@ DevToolsModules(
"system.js",
"ThreadSafeDevToolsUtils.js",
"throttle.js",
"validate-breakpoint.jsm",
"validate-breakpoint.sys.mjs",
)
with Files("**"):

View file

@ -2,17 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// Because this function is used from SessionDataHelpers.jsm,
// this has to be a JSM.
var EXPORTED_SYMBOLS = ["validateBreakpointLocation"];
/**
* Given a breakpoint location object, throws if the breakpoint look invalid
*/
function validateBreakpointLocation({ sourceUrl, sourceId, line, column }) {
export function validateBreakpointLocation({
sourceUrl,
sourceId,
line,
column,
}) {
if (!sourceUrl && !sourceId) {
throw new Error(
`Breakpoints expect to have either a sourceUrl or a sourceId.`
@ -40,10 +38,3 @@ function validateBreakpointLocation({ sourceUrl, sourceId, line, column }) {
);
}
}
// Allow this JSM to also be loaded as a CommonJS module
// Because this module is used from the worker thread,
// and workers can't load JSMs.
if (typeof module == "object") {
module.exports.validateBreakpointLocation = validateBreakpointLocation;
}