Bug 1492434 - Convert _getContentProcessTarget to async in order to correctly forward rejections r=jdescottes
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 03 Oct 2018 08:27:36 +0000
changeset 487798 9cd5d357528d307a79a4568c141cc707c7424d75
parent 487797 79065fca7cc10cf88911f07ef8781739b32bc10f
child 487799 9368d2715723b4f692b67ae088c125cbb26cb2ea
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersjdescottes
bugs1492434
milestone64.0a1
Bug 1492434 - Convert _getContentProcessTarget to async in order to correctly forward rejections r=jdescottes MozReview-Commit-ID: 50HYZyUkflN Depends on D7413 Differential Revision: https://phabricator.services.mozilla.com/D7414
devtools/client/framework/devtools-browser.js
--- a/devtools/client/framework/devtools-browser.js
+++ b/devtools/client/framework/devtools-browser.js
@@ -303,47 +303,40 @@ var gDevToolsBrowser = exports.gDevTools
     const win = Services.wm.getMostRecentWindow("devtools:webide");
     if (win) {
       win.focus();
     } else {
       Services.ww.openWindow(null, "chrome://webide/content/", "webide", "chrome,centerscreen,resizable", null);
     }
   },
 
-  _getContentProcessTarget(processId) {
+  async _getContentProcessTarget(processId) {
     // Create a DebuggerServer in order to connect locally to it
     DebuggerServer.init();
     DebuggerServer.registerAllActors();
     DebuggerServer.allowChromeProcess = true;
 
     const transport = DebuggerServer.connectPipe();
     const client = new DebuggerClient(transport);
 
-    return new Promise(resolve => {
-      client.connect().then(() => {
-        client.getProcess(processId)
-              .then(response => {
-                const options = {
-                  form: response.form,
-                  client: client,
-                  chrome: true,
-                };
-                return TargetFactory.forRemoteTab(options);
-              })
-              .then(target => {
-                // Ensure closing the connection in order to cleanup
-                // the debugger client and also the server created in the
-                // content process
-                target.on("close", () => {
-                  client.close();
-                });
-                resolve(target);
-              });
-      });
+    await client.connect();
+    const response = await client.getProcess(processId);
+    const options = {
+      form: response.form,
+      client: client,
+      chrome: true,
+    };
+    const target = await TargetFactory.forRemoteTab(options);
+    // Ensure closing the connection in order to cleanup
+    // the debugger client and also the server created in the
+    // content process
+    target.on("close", () => {
+      client.close();
     });
+    return target;
   },
 
   /**
    * Open the Browser Content Toolbox for the provided gBrowser instance.
    * Returns a promise that resolves with a toolbox instance. If no content process is
    * available, the promise will be rejected and a message will be displayed to the user.
    *
    * Used by menus.js