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"; "use strict";
const asyncStoreHelper = require("resource://devtools/client/shared/async-store-helper.js"); const asyncStoreHelper = require("resource://devtools/client/shared/async-store-helper.js");
const { validateBreakpointLocation } = ChromeUtils.import( const { validateBreakpointLocation } = ChromeUtils.importESModule(
"resource://devtools/shared/validate-breakpoint.jsm" "resource://devtools/shared/validate-breakpoint.sys.mjs",
{ global: "contextual" }
); );
const asyncStore = asyncStoreHelper("debugger", { const asyncStore = asyncStoreHelper("debugger", {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -22,13 +22,11 @@ ChromeUtils.defineLazyGetter(lazy, "Loader", () =>
ChromeUtils.defineLazyGetter(lazy, "DevToolsUtils", () => ChromeUtils.defineLazyGetter(lazy, "DevToolsUtils", () =>
lazy.Loader.require("resource://devtools/shared/DevToolsUtils.js") lazy.Loader.require("resource://devtools/shared/DevToolsUtils.js")
); );
XPCOMUtils.defineLazyModuleGetters(lazy, {
SessionDataHelpers:
"resource://devtools/server/actors/watcher/SessionDataHelpers.jsm",
});
ChromeUtils.defineESModuleGetters(lazy, { ChromeUtils.defineESModuleGetters(lazy, {
isWindowGlobalPartOfContext: isWindowGlobalPartOfContext:
"resource://devtools/server/actors/watcher/browsing-context-helpers.sys.mjs", "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. // 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 = {}; const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, { ChromeUtils.defineESModuleGetters(lazy, {
loader: "resource://devtools/shared/loader/Loader.sys.mjs", loader: "resource://devtools/shared/loader/Loader.sys.mjs",
SessionDataHelpers:
"resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
}); });
XPCOMUtils.defineLazyServiceGetter( XPCOMUtils.defineLazyServiceGetter(
@ -17,11 +19,6 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIWorkerDebuggerManager" "nsIWorkerDebuggerManager"
); );
XPCOMUtils.defineLazyModuleGetters(lazy, {
SessionDataHelpers:
"resource://devtools/server/actors/watcher/SessionDataHelpers.jsm",
});
ChromeUtils.defineLazyGetter(lazy, "DevToolsUtils", () => ChromeUtils.defineLazyGetter(lazy, "DevToolsUtils", () =>
lazy.loader.require("devtools/shared/DevToolsUtils") lazy.loader.require("devtools/shared/DevToolsUtils")
); );

View file

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

View file

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

View file

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

View file

@ -2,17 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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 * 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) { if (!sourceUrl && !sourceId) {
throw new Error( throw new Error(
`Breakpoints expect to have either a sourceUrl or a sourceId.` `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;
}