Bug 1790468 - [remote] Convert /remote/server JSM modules to ESM draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 29 Sep 2022 08:50:46 +0000
changeset 4682694 64112a3ad6467ea9ee1f75a8ee0f70be0fc3c047
parent 4682693 b0f161a121e9d9bcd9fcefc861b65c911f0c95a7
child 4682695 3e6b2fc9e46194326e398e25c47d9be1de06f15f
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/server JSM modules to ESM Differential Diff: PHID-DIFF-3occ5bei6xiwiqrpmxwu
remote/cdp/targets/Target.jsm
remote/jar.mn
remote/server/WebSocketHandshake.jsm
remote/server/WebSocketHandshake.sys.mjs
remote/server/WebSocketTransport.jsm
remote/server/WebSocketTransport.sys.mjs
remote/shared/WebSocketConnection.sys.mjs
remote/shared/webdriver/Session.sys.mjs
remote/webdriver-bidi/NewSessionHandler.jsm
--- a/remote/cdp/targets/Target.jsm
+++ b/remote/cdp/targets/Target.jsm
@@ -7,19 +7,23 @@
 var EXPORTED_SYMBOLS = ["Target"];
 
 const { XPCOMUtils } = ChromeUtils.importESModule(
   "resource://gre/modules/XPCOMUtils.sys.mjs"
 );
 
 const lazy = {};
 
+ChromeUtils.defineESModuleGetters(lazy, {
+  WebSocketHandshake:
+    "chrome://remote/content/server/WebSocketHandshake.sys.mjs",
+});
+
 XPCOMUtils.defineLazyModuleGetters(lazy, {
   CDPConnection: "chrome://remote/content/cdp/CDPConnection.jsm",
-  WebSocketHandshake: "chrome://remote/content/server/WebSocketHandshake.jsm",
 });
 
 /**
  * Base class for all the targets.
  */
 class Target {
   /**
    * @param TargetList targetList
--- a/remote/jar.mn
+++ b/remote/jar.mn
@@ -4,18 +4,18 @@
 
 remote.jar:
 % content remote %content/
   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)
+  content/server/WebSocketHandshake.sys.mjs (server/WebSocketHandshake.sys.mjs)
+  content/server/WebSocketTransport.sys.mjs (server/WebSocketTransport.sys.mjs)
 
   # shared modules (all protocols)
   content/shared/AppInfo.sys.mjs (shared/AppInfo.sys.mjs)
   content/shared/Format.sys.mjs (shared/Format.sys.mjs)
   content/shared/Log.sys.mjs (shared/Log.sys.mjs)
   content/shared/MobileTabBrowser.sys.mjs (shared/MobileTabBrowser.sys.mjs)
   content/shared/Navigate.sys.mjs (shared/Navigate.sys.mjs)
   content/shared/PDF.sys.mjs (shared/PDF.sys.mjs)
rename from remote/server/WebSocketHandshake.jsm
rename to remote/server/WebSocketHandshake.sys.mjs
--- a/remote/server/WebSocketHandshake.jsm
+++ b/remote/server/WebSocketHandshake.sys.mjs
@@ -1,23 +1,17 @@
 /* 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 = ["WebSocketHandshake"];
-
 // This file is an XPCOM service-ified copy of ../devtools/server/socket/websocket-server.js.
 
-const CC = Components.Constructor;
+import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
 
-const { XPCOMUtils } = ChromeUtils.importESModule(
-  "resource://gre/modules/XPCOMUtils.sys.mjs"
-);
+const CC = Components.Constructor;
 
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
   executeSoon: "chrome://remote/content/shared/Sync.sys.mjs",
   Log: "chrome://remote/content/shared/Log.sys.mjs",
   RemoteAgent: "chrome://remote/content/components/RemoteAgent.sys.mjs",
 });
@@ -315,9 +309,9 @@ async function upgrade(request, response
     requestLine: `${request.method} ${request.path}`,
     headers,
   };
   await serverHandshake(convertedRequest, output);
 
   return createWebSocket(transport, input, output);
 }
 
-const WebSocketHandshake = { upgrade };
+export const WebSocketHandshake = { upgrade };
rename from remote/server/WebSocketTransport.jsm
rename to remote/server/WebSocketTransport.sys.mjs
--- a/remote/server/WebSocketTransport.jsm
+++ b/remote/server/WebSocketTransport.sys.mjs
@@ -1,29 +1,23 @@
 /* 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/. */
 
 // This is an XPCOM service-ified copy of ../devtools/shared/transport/websocket-transport.js.
 
-"use strict";
-
-var EXPORTED_SYMBOLS = ["WebSocketTransport"];
-
-const { XPCOMUtils } = ChromeUtils.importESModule(
-  "resource://gre/modules/XPCOMUtils.sys.mjs"
-);
+import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
 
 const lazy = {};
 
 XPCOMUtils.defineLazyModuleGetters(lazy, {
   EventEmitter: "resource://gre/modules/EventEmitter.jsm",
 });
 
-function WebSocketTransport(socket) {
+export function WebSocketTransport(socket) {
   lazy.EventEmitter.decorate(this);
 
   this.active = false;
   this.hooks = null;
   this.socket = socket;
 }
 
 WebSocketTransport.prototype = {
--- a/remote/shared/WebSocketConnection.sys.mjs
+++ b/remote/shared/WebSocketConnection.sys.mjs
@@ -5,20 +5,18 @@
 
 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
 
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
   Log: "chrome://remote/content/shared/Log.sys.mjs",
   truncate: "chrome://remote/content/shared/Format.sys.mjs",
-});
-
-XPCOMUtils.defineLazyModuleGetters(lazy, {
-  WebSocketTransport: "chrome://remote/content/server/WebSocketTransport.jsm",
+  WebSocketTransport:
+    "chrome://remote/content/server/WebSocketTransport.sys.mjs",
 });
 
 XPCOMUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get());
 
 export class WebSocketConnection {
   /**
    * @param {WebSocket} webSocket
    *     The WebSocket server connection to wrap.
--- a/remote/shared/webdriver/Session.sys.mjs
+++ b/remote/shared/webdriver/Session.sys.mjs
@@ -9,24 +9,25 @@ const lazy = {};
 ChromeUtils.defineESModuleGetters(lazy, {
   Capabilities: "chrome://remote/content/shared/webdriver/Capabilities.sys.mjs",
   error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
   Log: "chrome://remote/content/shared/Log.sys.mjs",
   RootMessageHandler:
     "chrome://remote/content/shared/messagehandler/RootMessageHandler.sys.mjs",
   RootMessageHandlerRegistry:
     "chrome://remote/content/shared/messagehandler/RootMessageHandlerRegistry.sys.mjs",
+  WebSocketHandshake:
+    "chrome://remote/content/server/WebSocketHandshake.sys.mjs",
 });
 
 XPCOMUtils.defineLazyModuleGetters(lazy, {
   accessibility: "chrome://remote/content/marionette/accessibility.js",
   allowAllCerts: "chrome://remote/content/marionette/cert.js",
   WebDriverBiDiConnection:
     "chrome://remote/content/webdriver-bidi/WebDriverBiDiConnection.jsm",
-  WebSocketHandshake: "chrome://remote/content/server/WebSocketHandshake.jsm",
 });
 
 XPCOMUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get());
 
 /**
  * Representation of WebDriver session.
  */
 export class WebDriverSession {
--- a/remote/webdriver-bidi/NewSessionHandler.jsm
+++ b/remote/webdriver-bidi/NewSessionHandler.jsm
@@ -7,20 +7,24 @@
 var EXPORTED_SYMBOLS = ["WebDriverNewSessionHandler"];
 
 const { XPCOMUtils } = ChromeUtils.importESModule(
   "resource://gre/modules/XPCOMUtils.sys.mjs"
 );
 
 const lazy = {};
 
+ChromeUtils.defineESModuleGetters(lazy, {
+  WebSocketHandshake:
+    "chrome://remote/content/server/WebSocketHandshake.sys.mjs",
+});
+
 XPCOMUtils.defineLazyModuleGetters(lazy, {
   WebDriverBiDiConnection:
     "chrome://remote/content/webdriver-bidi/WebDriverBiDiConnection.jsm",
-  WebSocketHandshake: "chrome://remote/content/server/WebSocketHandshake.jsm",
 });
 
 /**
  * httpd.js JSON handler for direct BiDi connections.
  */
 class WebDriverNewSessionHandler {
   /**
    * Construct a new JSON handler.