Bug 1432212 - Await startup recorder by using async function. r?maja_zf draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 22 Jan 2018 17:21:52 +0000
changeset 723185 7e82ae59258a271b42d15a1396ec3b115cd6d59a
parent 723179 e9dfb9f6a9f3b252a5e395d87e293a44cfec75dc
child 723186 2fd139d4b52bf4cd85a6da9bdf5409fca19fc578
push id96350
push userbmo:ato@sny.no
push dateMon, 22 Jan 2018 17:33:36 +0000
reviewersmaja_zf
bugs1432212
milestone60.0a1
Bug 1432212 - Await startup recorder by using async function. r?maja_zf Reduces block level indentation by one level by employing an async arrow function and the await statement to wait for the startup tests recorder to do its work. MozReview-Commit-ID: 293qw0W2Puo
testing/marionette/components/marionette.js
--- a/testing/marionette/components/marionette.js
+++ b/testing/marionette/components/marionette.js
@@ -279,36 +279,38 @@ MarionetteComponent.prototype.suppressSa
   }, {once: true});
 };
 
 MarionetteComponent.prototype.init = function() {
   if (this.running || !this.enabled || !this.finalUIStartup) {
     return;
   }
 
-  // Delay initialization until we are done with delayed startup...
-  Services.tm.idleDispatchToMainThread(() => {
-    // ... and with startup tests.
-    let promise = Promise.resolve();
-    if ("@mozilla.org/test/startuprecorder;1" in Cc)
-      promise = Cc["@mozilla.org/test/startuprecorder;1"].getService().wrappedJSObject.done;
-    promise.then(() => {
-      let s;
-      try {
-        Cu.import("chrome://marionette/content/server.js");
-        s = new server.TCPListener(prefs.port);
-        s.start();
-        log.info(`Listening on port ${s.port}`);
-      } finally {
-        if (s) {
-          this.server = s;
-          this.running = true;
-        }
+  // wait for delayed startup...
+  Services.tm.idleDispatchToMainThread(async () => {
+    // ... and for startup tests
+    let startupRecorder = Promise.resolve();
+    if ("@mozilla.org/test/startuprecorder;1" in Cc) {
+      startupRecorder = Cc["@mozilla.org/test/startuprecorder;1"]
+          .getService().wrappedJSObject.done;
+    }
+    await startupRecorder;
+
+    let s;
+    try {
+      Cu.import("chrome://marionette/content/server.js");
+      s = new server.TCPListener(prefs.port);
+      s.start();
+      log.info(`Listening on port ${s.port}`);
+    } finally {
+      if (s) {
+        this.server = s;
+        this.running = true;
       }
-    });
+    }
   });
 };
 
 MarionetteComponent.prototype.uninit = function() {
   if (!this.running) {
     return;
   }
   this.server.stop();