Bug 1596254 - process selectors should deal with null processes. r=mconley draft
authorAndrew McCreight <continuation@gmail.com>
Tue, 19 Nov 2019 09:09:30 -0800
changeset 2496058 f57bbf975cc436516f7dfaf747ebeb90a8cf56f2
parent 2496057 8c66b0d86e9750b328840fcfe7f58a6c3ebbc03d
child 2496059 43f53851231874d8af3b7e5e8d93d18a9d719f14
push id455279
push useramccreight@mozilla.com
push dateMon, 25 Nov 2019 19:56:04 +0000
treeherdertry@59b13b57567a [default view] [failures only]
reviewersmconley
bugs1596254
milestone72.0a1
Bug 1596254 - process selectors should deal with null processes. r=mconley If a process is in the middle of shutting down, it will show up as null in the processes array. Differential Revision: https://phabricator.services.mozilla.com/D53839
dom/base/ProcessSelector.jsm
--- a/dom/base/ProcessSelector.jsm
+++ b/dom/base/ProcessSelector.jsm
@@ -14,17 +14,17 @@ RandomSelector.prototype = {
     if (aProcesses.length < aMaxCount) {
       return Ci.nsIContentProcessProvider.NEW_PROCESS;
     }
 
     let startIdx = Math.floor(Math.random() * aMaxCount);
     let curIdx = startIdx;
 
     do {
-      if (aProcesses[curIdx].opener === aOpener) {
+      if (aProcesses[curIdx] && aProcesses[curIdx].opener === aOpener) {
         return curIdx;
       }
 
       curIdx = (curIdx + 1) % aMaxCount;
     } while (curIdx !== startIdx);
 
     return Ci.nsIContentProcessProvider.NEW_PROCESS;
   },
@@ -48,16 +48,19 @@ MinTabSelector.prototype = {
 
     // Note, that at this point aMaxCount is in the valid range and
     // the reason for not using aProcesses.length here is because if we keep
     // processes alive for testing but want a test to use only single
     // content process we can just keep relying on dom.ipc.processCount = 1
     // this way.
     for (let i = 0; i < aMaxCount; i++) {
       let process = aProcesses[i];
+      if (!process) {
+        continue;
+      }
       let tabCount = process.tabCount;
       if (process.opener === aOpener && tabCount < min) {
         min = tabCount;
         candidate = i;
       }
     }
 
     return candidate;