Bug 1497292 - Switch RootClient calls from callbacks to promises. r=yulia
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 09 Oct 2018 08:06:10 +0000
changeset 496058 22aa7c97d46d178a324f8c0b5598cc5b3caca492
parent 496057 80a1352b7cd979a40dd722c78b16a41e14e0ae67
child 496059 99cc4ced26e020d6a31335647738c361f86e4bfe
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1497292
milestone64.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 1497292 - Switch RootClient calls from callbacks to promises. r=yulia MozReview-Commit-ID: B1Z3tCjCHU3 Differential Revision: https://phabricator.services.mozilla.com/D8023
devtools/client/debugger/test/mochitest/head.js
devtools/client/framework/target.js
devtools/server/tests/mochitest/test_getProcess.html
devtools/shared/client/debugger-client.js
--- a/devtools/client/debugger/test/mochitest/head.js
+++ b/devtools/client/debugger/test/mochitest/head.js
@@ -164,17 +164,17 @@ function getTargetActorForUrl(aClient, a
 
   return deferred.promise;
 }
 
 function getAddonActorForId(aClient, aAddonId) {
   info("Get addon actor for ID: " + aAddonId);
   let deferred = promise.defer();
 
-  aClient.listAddons(aResponse => {
+  aClient.listAddons().then(aResponse => {
     let addonTargetActor = aResponse.addons.filter(aGrip => aGrip.id == aAddonId).pop();
     info("got addon actor for ID: " + aAddonId);
     deferred.resolve(addonTargetActor);
   });
 
   return deferred.promise;
 }
 
--- a/devtools/client/framework/target.js
+++ b/devtools/client/framework/target.js
@@ -281,33 +281,29 @@ TabTarget.prototype = {
    *       "substring": {
    *         "_retval": "primitive"
    *       }
    *     }
    *   }],
    *  "events": {}
    * }
    */
-  getActorDescription: function(actorName) {
+  getActorDescription: async function(actorName) {
     if (!this.client) {
       throw new Error("TabTarget#getActorDescription() can only be called on " +
                       "remote tabs.");
     }
 
-    return new Promise(resolve => {
-      if (this._protocolDescription &&
-          this._protocolDescription.types[actorName]) {
-        resolve(this._protocolDescription.types[actorName]);
-      } else {
-        this.client.mainRoot.protocolDescription(description => {
-          this._protocolDescription = description;
-          resolve(description.types[actorName]);
-        });
-      }
-    });
+    if (this._protocolDescription &&
+        this._protocolDescription.types[actorName]) {
+      return this._protocolDescription.types[actorName];
+    }
+    const description = await this.client.mainRoot.protocolDescription();
+    this._protocolDescription = description;
+    return description.types[actorName];
   },
 
   /**
    * Returns a boolean indicating whether or not the specific actor
    * type exists. Must be a remote target.
    *
    * @param {String} actorName
    * @return {Boolean}
--- a/devtools/server/tests/mochitest/test_getProcess.html
+++ b/devtools/server/tests/mochitest/test_getProcess.html
@@ -56,17 +56,17 @@ function runTests() {
 
   function listProcess() {
     // Call listProcesses in order to start receiving new process notifications
     client.addListener("processListChanged", function listener() {
       client.removeListener("processListChanged", listener);
       ok(true, "Received processListChanged event");
       getProcess();
     });
-    client.mainRoot.listProcesses(response => {
+    client.mainRoot.listProcesses().then(response => {
       processCount = response.processes.length;
       // Create a remote iframe to spawn a new process
       createRemoteIframe();
     });
   }
 
   function createRemoteIframe() {
     iframe = document.createElement("iframe");
--- a/devtools/shared/client/debugger-client.js
+++ b/devtools/shared/client/debugger-client.js
@@ -321,26 +321,26 @@ DebuggerClient.prototype = {
 
     return deferred.promise;
   },
 
   /*
    * This function exists only to preserve DebuggerClient's interface;
    * new code should say 'client.mainRoot.listTabs()'.
    */
-  listTabs: function(options, onResponse) {
-    return this.mainRoot.listTabs(options, onResponse);
+  listTabs: function(options) {
+    return this.mainRoot.listTabs(options);
   },
 
   /*
    * This function exists only to preserve DebuggerClient's interface;
    * new code should say 'client.mainRoot.listAddons()'.
    */
-  listAddons: function(onResponse) {
-    return this.mainRoot.listAddons(onResponse);
+  listAddons: function() {
+    return this.mainRoot.listAddons();
   },
 
   getTab: function(filter) {
     return this.mainRoot.getTab(filter);
   },
 
   /**
    * Attach to a target actor: