Bug 1790468 - [remote] Convert /remote/components JSM modules to ESM draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 29 Sep 2022 08:50:43 +0000
changeset 4682693 b0f161a121e9d9bcd9fcefc861b65c911f0c95a7
parent 4682692 c46b6202d293e4b2063e72ec7ae3fcfe445ecb22
child 4682694 64112a3ad6467ea9ee1f75a8ee0f70be0fc3c047
push id858552
push userreviewbot
push dateThu, 29 Sep 2022 08:51:11 +0000
treeherdertry@3e6b2fc9e461 [default view] [failures only]
bugs1790468
milestone107.0a1
Bug 1790468 - [remote] Convert /remote/components JSM modules to ESM Differential Diff: PHID-DIFF-jurejnkgdu6zcnmozkzj
remote/cdp/targets/MainProcessTarget.jsm
remote/cdp/targets/TabTarget.jsm
remote/cdp/test/browser/head.js
remote/components/Marionette.jsm
remote/components/Marionette.sys.mjs
remote/components/RemoteAgent.jsm
remote/components/RemoteAgent.sys.mjs
remote/components/components.conf
remote/components/moz.build
remote/jar.mn
remote/marionette/driver.js
remote/server/WebSocketHandshake.jsm
remote/shared/webdriver/Capabilities.sys.mjs
remote/webdriver-bidi/WebDriverBiDiConnection.jsm
toolkit/modules/Troubleshoot.jsm
--- a/remote/cdp/targets/MainProcessTarget.jsm
+++ b/remote/cdp/targets/MainProcessTarget.jsm
@@ -11,20 +11,23 @@ const { XPCOMUtils } = ChromeUtils.impor
 );
 
 const { Target } = ChromeUtils.import(
   "chrome://remote/content/cdp/targets/Target.jsm"
 );
 
 const lazy = {};
 
+ChromeUtils.defineESModuleGetters(lazy, {
+  RemoteAgent: "chrome://remote/content/components/RemoteAgent.sys.mjs",
+});
+
 XPCOMUtils.defineLazyModuleGetters(lazy, {
   MainProcessSession:
     "chrome://remote/content/cdp/sessions/MainProcessSession.jsm",
-  RemoteAgent: "chrome://remote/content/components/RemoteAgent.jsm",
 });
 
 /**
  * The main process Target.
  *
  * Matches BrowserDevToolsAgentHost from chromium, and only support a couple of Domains:
  * https://cs.chromium.org/chromium/src/content/browser/devtools/browser_devtools_agent_host.cc?dr=CSs&g=0&l=80-91
  */
--- a/remote/cdp/targets/TabTarget.jsm
+++ b/remote/cdp/targets/TabTarget.jsm
@@ -12,21 +12,21 @@ const { XPCOMUtils } = ChromeUtils.impor
 
 const { Target } = ChromeUtils.import(
   "chrome://remote/content/cdp/targets/Target.jsm"
 );
 
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
+  RemoteAgent: "chrome://remote/content/components/RemoteAgent.sys.mjs",
   TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
 });
 
 XPCOMUtils.defineLazyModuleGetters(lazy, {
-  RemoteAgent: "chrome://remote/content/components/RemoteAgent.jsm",
   TabSession: "chrome://remote/content/cdp/sessions/TabSession.jsm",
 });
 
 XPCOMUtils.defineLazyServiceGetter(
   lazy,
   "Favicons",
   "@mozilla.org/browser/favicon-service;1",
   "nsIFaviconService"
--- a/remote/cdp/test/browser/head.js
+++ b/remote/cdp/test/browser/head.js
@@ -1,17 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
 
-const { RemoteAgent } = ChromeUtils.import(
-  "chrome://remote/content/components/RemoteAgent.jsm"
+const { RemoteAgent } = ChromeUtils.importESModule(
+  "chrome://remote/content/components/RemoteAgent.sys.mjs"
 );
 const { RemoteAgentError } = ChromeUtils.import(
   "chrome://remote/content/cdp/Error.jsm"
 );
 const { TabManager } = ChromeUtils.importESModule(
   "chrome://remote/content/shared/TabManager.sys.mjs"
 );
 
rename from remote/components/Marionette.jsm
rename to remote/components/Marionette.sys.mjs
--- a/remote/components/Marionette.jsm
+++ b/remote/components/Marionette.sys.mjs
@@ -1,19 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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";
-
-var EXPORTED_SYMBOLS = ["Marionette", "MarionetteFactory"];
-
-const { XPCOMUtils } = ChromeUtils.importESModule(
-  "resource://gre/modules/XPCOMUtils.sys.mjs"
-);
+import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
 
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
   Deferred: "chrome://remote/content/shared/Sync.sys.mjs",
   Log: "chrome://remote/content/shared/Log.sys.mjs",
   RecommendedPreferences:
     "chrome://remote/content/shared/RecommendedPreferences.sys.mjs",
@@ -306,19 +300,19 @@ class MarionetteContentProcess {
     return reply[0];
   }
 
   get QueryInterface() {
     return ChromeUtils.generateQI(["nsIMarionette"]);
   }
 }
 
-var Marionette;
+export var Marionette;
 if (isRemote) {
   Marionette = new MarionetteContentProcess();
 } else {
   Marionette = new MarionetteParentProcess();
 }
 
 // This is used by the XPCOM codepath which expects a constructor
-const MarionetteFactory = function() {
+export const MarionetteFactory = function() {
   return Marionette;
 };
rename from remote/components/RemoteAgent.jsm
rename to remote/components/RemoteAgent.sys.mjs
--- a/remote/components/RemoteAgent.jsm
+++ b/remote/components/RemoteAgent.sys.mjs
@@ -1,19 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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";
-
-var EXPORTED_SYMBOLS = ["RemoteAgent", "RemoteAgentFactory"];
-
-const { XPCOMUtils } = ChromeUtils.importESModule(
-  "resource://gre/modules/XPCOMUtils.sys.mjs"
-);
+import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
 
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
   Deferred: "chrome://remote/content/shared/Sync.sys.mjs",
   Log: "chrome://remote/content/shared/Log.sys.mjs",
 });
 
@@ -503,19 +497,19 @@ class RemoteAgentContentProcess {
     return reply[0];
   }
 
   get QueryInterface() {
     return ChromeUtils.generateQI(["nsIRemoteAgent"]);
   }
 }
 
-var RemoteAgent;
+export var RemoteAgent;
 if (isRemote) {
   RemoteAgent = new RemoteAgentContentProcess();
 } else {
   RemoteAgent = new RemoteAgentParentProcess();
 }
 
 // This is used by the XPCOM codepath which expects a constructor
-var RemoteAgentFactory = function() {
+export var RemoteAgentFactory = function() {
   return RemoteAgent;
 };
--- a/remote/components/components.conf
+++ b/remote/components/components.conf
@@ -6,24 +6,24 @@ Classes = [
     # Remote Agent
     {
         "cid": "{8f685a9d-8181-46d6-a71d-869289099c6d}",
         "contract_ids": ["@mozilla.org/remote/agent;1"],
         "categories": {
             "command-line-handler": "m-remote",
             "profile-after-change": "RemoteAgent",
         },
-        "jsm": "chrome://remote/content/components/RemoteAgent.jsm",
+        'esModule': "chrome://remote/content/components/RemoteAgent.sys.mjs",
         "constructor": "RemoteAgentFactory",
     },
 
     # Marionette
     {
         "cid": "{786a1369-dca5-4adc-8486-33d23c88010a}",
         "contract_ids": ["@mozilla.org/remote/marionette;1"],
         "categories": {
             "command-line-handler": "m-marionette",
             "profile-after-change": "Marionette",
         },
-        "jsm": "chrome://remote/content/components/Marionette.jsm",
+        'esModule': "chrome://remote/content/components/Marionette.sys.mjs",
         "constructor": "MarionetteFactory",
     },
 ]
--- a/remote/components/moz.build
+++ b/remote/components/moz.build
@@ -6,12 +6,12 @@ XPIDL_MODULE = "remote"
 
 XPIDL_SOURCES += [
     "nsIMarionette.idl",
     "nsIRemoteAgent.idl",
 ]
 
 XPCOM_MANIFESTS += ["components.conf"]
 
-with Files("Marionette.jsm"):
+with Files("Marionette.sys.mjs"):
     BUG_COMPONENT = ("Testing", "Marionette")
 with Files("nsIMarionette.idl"):
     BUG_COMPONENT = ("Testing", "Marionette")
--- a/remote/jar.mn
+++ b/remote/jar.mn
@@ -1,16 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # 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/.
 
 remote.jar:
 % content remote %content/
-  content/components/Marionette.jsm (components/Marionette.jsm)
-  content/components/RemoteAgent.jsm (components/RemoteAgent.jsm)
+  content/components/Marionette.sys.mjs (components/Marionette.sys.mjs)
+  content/components/RemoteAgent.sys.mjs (components/RemoteAgent.sys.mjs)
 
   # transport layer (http / websocket)
   content/server/HTTPD.jsm (../netwerk/test/httpserver/httpd.js)
   content/server/WebSocketHandshake.jsm (server/WebSocketHandshake.jsm)
   content/server/WebSocketTransport.jsm (server/WebSocketTransport.jsm)
 
   # shared modules (all protocols)
   content/shared/AppInfo.sys.mjs (shared/AppInfo.sys.mjs)
--- a/remote/marionette/driver.js
+++ b/remote/marionette/driver.js
@@ -17,18 +17,20 @@ const { element } = ChromeUtils.import(
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
   AppInfo: "chrome://remote/content/shared/AppInfo.sys.mjs",
   assert: "chrome://remote/content/shared/webdriver/Assert.sys.mjs",
   error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
   EventPromise: "chrome://remote/content/shared/Sync.sys.mjs",
   Log: "chrome://remote/content/shared/Log.sys.mjs",
+  Marionette: "chrome://remote/content/components/Marionette.sys.mjs",
   pprint: "chrome://remote/content/shared/Format.sys.mjs",
   print: "chrome://remote/content/shared/PDF.sys.mjs",
+  RemoteAgent: "chrome://remote/content/components/RemoteAgent.sys.mjs",
   TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
   Timeouts: "chrome://remote/content/shared/webdriver/Capabilities.sys.mjs",
   UnhandledPromptBehavior:
     "chrome://remote/content/shared/webdriver/Capabilities.sys.mjs",
   waitForInitialNavigationCompleted:
     "chrome://remote/content/shared/Navigate.sys.mjs",
   WebDriverSession: "chrome://remote/content/shared/webdriver/Session.sys.mjs",
   windowManager: "chrome://remote/content/shared/WindowManager.sys.mjs",
@@ -47,25 +49,23 @@ XPCOMUtils.defineLazyModuleGetters(lazy,
   disableEventsActor:
     "chrome://remote/content/marionette/actors/MarionetteEventsParent.jsm",
   enableEventsActor:
     "chrome://remote/content/marionette/actors/MarionetteEventsParent.jsm",
   getMarionetteCommandsActorProxy:
     "chrome://remote/content/marionette/actors/MarionetteCommandsParent.jsm",
   IdlePromise: "chrome://remote/content/marionette/sync.js",
   l10n: "chrome://remote/content/marionette/l10n.js",
-  Marionette: "chrome://remote/content/components/Marionette.jsm",
   MarionettePrefs: "chrome://remote/content/marionette/prefs.js",
   modal: "chrome://remote/content/marionette/modal.js",
   navigate: "chrome://remote/content/marionette/navigate.js",
   permissions: "chrome://remote/content/marionette/permissions.js",
   reftest: "chrome://remote/content/marionette/reftest.js",
   registerCommandsActor:
     "chrome://remote/content/marionette/actors/MarionetteCommandsParent.jsm",
-  RemoteAgent: "chrome://remote/content/components/RemoteAgent.jsm",
   TimedPromise: "chrome://remote/content/marionette/sync.js",
   unregisterCommandsActor:
     "chrome://remote/content/marionette/actors/MarionetteCommandsParent.jsm",
   waitForObserverTopic: "chrome://remote/content/marionette/sync.js",
   WebReference: "chrome://remote/content/marionette/element.js",
   WindowState: "chrome://remote/content/marionette/browser.js",
 });
 
--- a/remote/server/WebSocketHandshake.jsm
+++ b/remote/server/WebSocketHandshake.jsm
@@ -14,20 +14,17 @@ const { XPCOMUtils } = ChromeUtils.impor
   "resource://gre/modules/XPCOMUtils.sys.mjs"
 );
 
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
   executeSoon: "chrome://remote/content/shared/Sync.sys.mjs",
   Log: "chrome://remote/content/shared/Log.sys.mjs",
-});
-
-XPCOMUtils.defineLazyModuleGetters(lazy, {
-  RemoteAgent: "chrome://remote/content/components/RemoteAgent.jsm",
+  RemoteAgent: "chrome://remote/content/components/RemoteAgent.sys.mjs",
 });
 
 XPCOMUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get());
 
 XPCOMUtils.defineLazyGetter(lazy, "CryptoHash", () => {
   return CC("@mozilla.org/security/hash;1", "nsICryptoHash", "initWithString");
 });
 
--- a/remote/shared/webdriver/Capabilities.sys.mjs
+++ b/remote/shared/webdriver/Capabilities.sys.mjs
@@ -6,22 +6,21 @@ import { XPCOMUtils } from "resource://g
 
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
   AppInfo: "chrome://remote/content/shared/AppInfo.sys.mjs",
   assert: "chrome://remote/content/shared/webdriver/Assert.sys.mjs",
   error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
   pprint: "chrome://remote/content/shared/Format.sys.mjs",
+  RemoteAgent: "chrome://remote/content/components/RemoteAgent.sys.mjs",
 });
 
 XPCOMUtils.defineLazyModuleGetters(lazy, {
   Preferences: "resource://gre/modules/Preferences.jsm",
-
-  RemoteAgent: "chrome://remote/content/components/RemoteAgent.jsm",
 });
 
 XPCOMUtils.defineLazyGetter(lazy, "remoteAgent", () => {
   return Cc["@mozilla.org/remote/agent;1"].createInstance(Ci.nsIRemoteAgent);
 });
 
 /** Representation of WebDriver session timeouts. */
 export class Timeouts {
--- a/remote/webdriver-bidi/WebDriverBiDiConnection.jsm
+++ b/remote/webdriver-bidi/WebDriverBiDiConnection.jsm
@@ -15,20 +15,17 @@ const { WebSocketConnection } = ChromeUt
 );
 
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
   assert: "chrome://remote/content/shared/webdriver/Assert.sys.mjs",
   error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
   Log: "chrome://remote/content/shared/Log.sys.mjs",
-});
-
-XPCOMUtils.defineLazyModuleGetters(lazy, {
-  RemoteAgent: "chrome://remote/content/components/RemoteAgent.jsm",
+  RemoteAgent: "chrome://remote/content/components/RemoteAgent.sys.mjs",
 });
 
 XPCOMUtils.defineLazyGetter(lazy, "logger", () =>
   lazy.Log.get(lazy.Log.TYPES.WEBDRIVER_BIDI)
 );
 
 class WebDriverBiDiConnection extends WebSocketConnection {
   /**
--- a/toolkit/modules/Troubleshoot.jsm
+++ b/toolkit/modules/Troubleshoot.jsm
@@ -988,18 +988,18 @@ if (AppConstants.MOZ_SANDBOX) {
     }
 
     done(data);
   };
 }
 
 if (AppConstants.ENABLE_WEBDRIVER) {
   dataProviders.remoteAgent = function remoteAgent(done) {
-    const { RemoteAgent } = ChromeUtils.import(
-      "chrome://remote/content/components/RemoteAgent.jsm"
+    const { RemoteAgent } = ChromeUtils.importESModule(
+      "chrome://remote/content/components/RemoteAgent.sys.mjs"
     );
     const { running, scheme, host, port } = RemoteAgent;
     let url = "";
     if (running) {
       url = `${scheme}://${host}:${port}/`;
     }
     done({ running, url });
   };