bug 1600111: remote: make nsIRemoteAgent.listen() sync r=remote-protocol-reviewers,maja_zf
authorAndreas Tolfsen <ato@sny.no>
Wed, 04 Dec 2019 11:57:13 +0000
changeset 505301 13fb375eaf14bd9fae5c607aa60015d2b3bd0f2d
parent 505300 14e3e7d7a496f6a71c01ae224cda0bca82a76d77
child 505302 32f84899fc000d95337a25c14a27470d0c52e3ee
child 505303 40b6d9ae060135379c2e9379fbc038f1ed99f548
push id36881
push userdvarga@mozilla.com
push dateWed, 04 Dec 2019 16:22:31 +0000
treeherdermozilla-central@13fb375eaf14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersremote-protocol-reviewers, maja_zf
bugs1600111, 1512319
milestone73.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 1600111: remote: make nsIRemoteAgent.listen() sync r=remote-protocol-reviewers,maja_zf Interfaces exposed over XPIDL cannot be marked async, otherwise their return values get lost. This patch makes nsIRemoteAgent.listen() synchronous by removing the use of async/await. Unfortunately Rust does not yet support deserialising promises sent across XPIDL, documented in https://bugzilla.mozilla.org/show_bug.cgi?id=1512319. In an effort to retain the original API internally the function now returns a promise. This means the function can be awaited in JS only, which we make use of in remote/test/browser/head.js. Differential Revision: https://phabricator.services.mozilla.com/D55173
remote/RemoteAgent.jsm
--- a/remote/RemoteAgent.jsm
+++ b/remote/RemoteAgent.jsm
@@ -26,17 +26,17 @@ const FORCE_LOCAL = "remote.force-local"
 
 const LOOPBACKS = ["localhost", "127.0.0.1", "[::1]"];
 
 class RemoteAgentClass {
   get listening() {
     return !!this.server && !this.server.isStopped();
   }
 
-  async listen(url) {
+  listen(url) {
     if (!Preferences.get(ENABLED, false)) {
       throw new Error("Remote agent is disabled by preference");
     }
     if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
       throw new Error(
         "Remote agent can only be instantiated from the parent process"
       );
     }
@@ -51,17 +51,17 @@ class RemoteAgentClass {
     }
 
     // nsIServerSocket uses -1 for atomic port allocation
     if (port === 0) {
       port = -1;
     }
 
     if (this.listening) {
-      return;
+      return Promise.resolve();
     }
 
     Preferences.set(RecommendedPreferences);
 
     this.server = new HttpServer();
     this.server.registerPrefixHandler("/json/", new JSONHandler(this));
 
     this.targets = new Targets();
@@ -72,16 +72,20 @@ class RemoteAgentClass {
       this.server.registerPathHandler(target.path, target);
     });
     this.targets.on("target-destroyed", (eventName, target) => {
       // TODO: removes the entry added by registerPathHandler,
       // but we should instead have nsIHttpServer.unregisterPathHandler
       delete this.server._handler._overridePaths[target.path];
     });
 
+    return this.asyncListen(host, port);
+  }
+
+  async asyncListen(host, port) {
     try {
       await this.targets.watchForTargets();
 
       // Immediatly instantiate the main process target in order
       // to be accessible via HTTP endpoint on startup
       const mainTarget = this.targets.getMainProcessTarget();
 
       this.server._start(port, host);