Bug 1450073 - Update listAllWorkers try/catch to be resilient if listWorkers failed;r=ochameau draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 27 Apr 2018 21:41:10 +0200
changeset 789212 cb4e8dd6c443b7c9ae9be24f06f76e25e0f43e1a
parent 789088 bd4943b8fbe7ea98426b190c77ddd63020723363
child 789213 ce445e43a606e78ef8e288c3d3fead685fe33e30
child 790547 f04dd8f1cc226ad71127be3025ad3bc7d12cc2b0
push id108223
push userjdescottes@mozilla.com
push dateFri, 27 Apr 2018 20:12:20 +0000
reviewersochameau
bugs1450073
milestone61.0a1
Bug 1450073 - Update listAllWorkers try/catch to be resilient if listWorkers failed;r=ochameau The issue with the previous approach is that calling listWorkers on other processes can fail leading us to return an empty result set, while we could still return the information coming from the main process workers. MozReview-Commit-ID: 8KBpGQH3qYH
devtools/shared/client/root-client.js
--- a/devtools/shared/client/root-client.js
+++ b/devtools/shared/client/root-client.js
@@ -101,26 +101,20 @@ RootClient.prototype = {
    *         - {Array} service
    *           array of form-like objects for serviceworkers
    *         - {Array} shared
    *           Array of WorkerActor forms, containing shared workers.
    *         - {Array} other
    *           Array of WorkerActor forms, containing other workers.
    */
   listAllWorkers: async function() {
-    let result = {
-      service: [],
-      shared: [],
-      other: []
-    };
+    let registrations = [];
+    let workers = [];
 
     try {
-      let registrations = [];
-      let workers = [];
-
       // List service worker registrations
       ({ registrations } = await this.listServiceWorkerRegistrations());
 
       // List workers from the Parent process
       ({ workers } = await this.listWorkers());
 
       // And then from the Child processes
       let { processes } = await this.listProcesses();
@@ -132,67 +126,73 @@ RootClient.prototype = {
         let { form } = await this._client.getProcess(process.id);
         let processActor = form.actor;
         let response = await this._client.request({
           to: processActor,
           type: "listWorkers"
         });
         workers = workers.concat(response.workers);
       }
-
-      registrations.forEach(form => {
-        result.service.push({
-          name: form.url,
-          url: form.url,
-          scope: form.scope,
-          fetch: form.fetch,
-          registrationActor: form.actor,
-          active: form.active
-        });
-      });
-
-      workers.forEach(form => {
-        let worker = {
-          name: form.url,
-          url: form.url,
-          workerActor: form.actor
-        };
-        switch (form.type) {
-          case Ci.nsIWorkerDebugger.TYPE_SERVICE:
-            let registration = result.service.find(r => r.scope === form.scope);
-            if (registration) {
-              // XXX: Race, sometimes a ServiceWorkerRegistrationInfo doesn't
-              // have a scriptSpec, but its associated WorkerDebugger does.
-              if (!registration.url) {
-                registration.name = registration.url = form.url;
-              }
-              registration.workerActor = form.actor;
-            } else {
-              worker.fetch = form.fetch;
-
-              // If a service worker registration could not be found, this means we are in
-              // e10s, and registrations are not forwarded to other processes until they
-              // reach the activated state. Augment the worker as a registration worker to
-              // display it in aboutdebugging.
-              worker.scope = form.scope;
-              worker.active = false;
-              result.service.push(worker);
-            }
-            break;
-          case Ci.nsIWorkerDebugger.TYPE_SHARED:
-            result.shared.push(worker);
-            break;
-          default:
-            result.other.push(worker);
-        }
-      });
     } catch (e) {
       // Something went wrong, maybe our client is disconnected?
     }
 
+    let result = {
+      service: [],
+      shared: [],
+      other: []
+    };
+
+    registrations.forEach(form => {
+      result.service.push({
+        name: form.url,
+        url: form.url,
+        scope: form.scope,
+        fetch: form.fetch,
+        registrationActor: form.actor,
+        active: form.active
+      });
+    });
+
+    workers.forEach(form => {
+      let worker = {
+        name: form.url,
+        url: form.url,
+        workerActor: form.actor
+      };
+      switch (form.type) {
+        case Ci.nsIWorkerDebugger.TYPE_SERVICE:
+          let registration = result.service.find(r => r.scope === form.scope);
+          if (registration) {
+            // XXX: Race, sometimes a ServiceWorkerRegistrationInfo doesn't
+            // have a scriptSpec, but its associated WorkerDebugger does.
+            if (!registration.url) {
+              registration.name = registration.url = form.url;
+            }
+            registration.workerActor = form.actor;
+          } else {
+            worker.fetch = form.fetch;
+
+            // If a service worker registration could not be found, this means we are in
+            // e10s, and registrations are not forwarded to other processes until they
+            // reach the activated state. Augment the worker as a registration worker to
+            // display it in aboutdebugging.
+            worker.scope = form.scope;
+            worker.active = false;
+            result.service.push(worker);
+          }
+          break;
+        case Ci.nsIWorkerDebugger.TYPE_SHARED:
+          result.shared.push(worker);
+          break;
+        default:
+          result.other.push(worker);
+      }
+    });
+
     return result;
   },
 
   /**
    * Fetch the TabActor for the currently selected tab, or for a specific
    * tab given as first parameter.
    *
    * @param [optional] object filter