Bug 1456051 - Make server an ES module. r=maja_zf
authorAndreas Tolfsen <ato@sny.no>
Mon, 23 Apr 2018 10:19:52 +0100
changeset 468591 08b2848c73e155b73220360a990764363a7bd821
parent 468590 2746c64ce7f1750b93ff5495066e54583008844d
child 468592 11731cdc9a54bfa255ca0cad3de5b2f748ec2afe
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1456051
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1456051 - Make server an ES module. r=maja_zf MozReview-Commit-ID: Cc8LEdVtmVg
testing/marionette/components/marionette.js
testing/marionette/doc/internals/server.rst
testing/marionette/server.js
--- a/testing/marionette/components/marionette.js
+++ b/testing/marionette/components/marionette.js
@@ -435,18 +435,18 @@ class MarionetteMainProcess {
             log.debug(`Setting recommended pref ${k} to ${v}`);
             Preferences.set(k, v);
             this.alteredPrefs.add(k);
           }
         }
       }
 
       try {
-        ChromeUtils.import("chrome://marionette/content/server.js");
-        let listener = new server.TCPListener(MarionettePrefs.port);
+        const {TCPListener} = ChromeUtils.import("chrome://marionette/content/server.js", {});
+        let listener = new TCPListener(MarionettePrefs.port);
         listener.start();
         this.server = listener;
       } catch (e) {
         log.fatal("Remote protocol server failed to start", e);
         this.uninit();
         Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
       }
 
--- a/testing/marionette/doc/internals/server.rst
+++ b/testing/marionette/doc/internals/server.rst
@@ -1,4 +1,12 @@
 server module
 =============
-.. js:autoclass:: server
+
+TCPConnection
+-------------
+.. js:autoclass:: TCPConnection
   :members:
+
+TCPListener
+-----------
+.. js:autoclass:: TCPListener
+  :members:
--- a/testing/marionette/server.js
+++ b/testing/marionette/server.js
@@ -28,48 +28,51 @@ const {
   Response,
 } = ChromeUtils.import("chrome://marionette/content/message.js", {});
 const {DebuggerTransport} = ChromeUtils.import("chrome://marionette/content/transport.js", {});
 
 const logger = Log.repository.getLogger("Marionette");
 
 const {KeepWhenOffline, LoopbackOnly} = Ci.nsIServerSocket;
 
-this.EXPORTED_SYMBOLS = ["server"];
+this.EXPORTED_SYMBOLS = [
+  "TCPConnection",
+  "TCPListener",
+];
 
 /** @namespace */
 this.server = {};
 
 const PROTOCOL_VERSION = 3;
 
 const PREF_CONTENT_LISTENER = "marionette.contentListener";
 const PREF_PORT = "marionette.port";
 
 /**
  * Bootstraps Marionette and handles incoming client connections.
  *
  * Starting the Marionette server will open a TCP socket sporting the
- * debugger transport interface on the provided <var>port</var>.
- * For every new connection, a {@link server.TCPConnection} is created.
+ * debugger transport interface on the provided `port`.  For every
+ * new connection, a {@link TCPConnection} is created.
  */
-server.TCPListener = class {
+class TCPListener {
   /**
    * @param {number} port
    *     Port for server to listen to.
    */
   constructor(port) {
     this.port = port;
     this.socket = null;
     this.conns = new Set();
     this.nextConnID = 0;
     this.alive = false;
   }
 
   /**
-   * Function produces a GeckoDriver.
+   * Function produces a {@link GeckoDriver}.
    *
    * Determines the application to initialise the driver with.
    *
    * @return {GeckoDriver}
    *     A driver instance.
    */
   driverFactory() {
     Preferences.set(PREF_CONTENT_LISTENER, false);
@@ -128,47 +131,48 @@ server.TCPListener = class {
     this.alive = false;
   }
 
   onSocketAccepted(serverSocket, clientSocket) {
     let input = clientSocket.openInputStream(0, 0, 0);
     let output = clientSocket.openOutputStream(0, 0, 0);
     let transport = new DebuggerTransport(input, output);
 
-    let conn = new server.TCPConnection(
+    let conn = new TCPConnection(
         this.nextConnID++, transport, this.driverFactory.bind(this));
     conn.onclose = this.onConnectionClosed.bind(this);
     this.conns.add(conn);
 
     logger.debug(`Accepted connection ${conn.id} ` +
         `from ${clientSocket.host}:${clientSocket.port}`);
     conn.sayHello();
     transport.ready();
   }
 
   onConnectionClosed(conn) {
     logger.debug(`Closed connection ${conn.id}`);
     this.conns.delete(conn);
   }
-};
+}
+this.TCPListener = TCPListener;
 
 /**
  * Marionette client connection.
  *
  * Dispatches packets received to their correct service destinations
  * and sends back the service endpoint's return values.
  *
  * @param {number} connID
  *     Unique identifier of the connection this dispatcher should handle.
  * @param {DebuggerTransport} transport
  *     Debugger transport connection to the client.
  * @param {function(): GeckoDriver} driverFactory
  *     Factory function that produces a {@link GeckoDriver}.
  */
-server.TCPConnection = class {
+class TCPConnection {
   constructor(connID, transport, driverFactory) {
     this.id = connID;
     this.conn = transport;
 
     // transport hooks are TCPConnection#onPacket
     // and TCPConnection#onClosed
     this.conn.hooks = this;
 
@@ -303,17 +307,17 @@ server.TCPConnection = class {
 
   /**
    * Fail-safe creation of a new instance of {@link Response}.
    *
    * @param {number} msgID
    *     Message ID to respond to.  If it is not a number, -1 is used.
    *
    * @return {Response}
-   *     Response to the message with <var>msgID</var>.
+   *     Response to the message with `msgID`.
    */
   createResponse(msgID) {
     if (typeof msgID != "number") {
       msgID = -1;
     }
     return new Response(msgID, this.send.bind(this));
   }
 
@@ -397,11 +401,12 @@ server.TCPConnection = class {
   }
 
   log_(msg) {
     let dir = (msg.origin == Message.Origin.Client ? "->" : "<-");
     logger.trace(`${this.id} ${dir} ${msg}`);
   }
 
   toString() {
-    return `[object server.TCPConnection ${this.id}]`;
+    return `[object TCPConnection ${this.id}]`;
   }
-};
+}
+this.TCPConnection = TCPConnection;