Bug 1261776 Use SafeElementAt() in service worker job queue. r=ehsan a=abillings
authorBen Kelly <ben@wanderview.com>
Wed, 06 Apr 2016 10:20:55 -0700
changeset 317719 637539f2aa3c614d8fa5fbba85632909caad85f0
parent 317718 1c9d427df90e3e3cff7569afcfd98ca555ba3306
child 317720 eb9d7f199164cfb81745aedb375ec89a55f96f0b
push id5858
push userbkelly@mozilla.com
push dateWed, 06 Apr 2016 17:21:03 +0000
treeherdermozilla-beta@637539f2aa3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, abillings
bugs1261776
milestone46.0
Bug 1261776 Use SafeElementAt() in service worker job queue. r=ehsan a=abillings
dom/workers/ServiceWorkerManager.cpp
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -300,19 +300,24 @@ private:
     }
   }
 
   void
   Done(ServiceWorkerJob* aJob)
   {
     MOZ_ASSERT(aJob);
     QueueData& queue = GetQueue(aJob->mJobType);
-    MOZ_ASSERT(!queue.mJobs.IsEmpty());
-    MOZ_ASSERT(queue.mJobs[0] == aJob);
-    if (NS_WARN_IF(queue.mJobs[0] != aJob)) {
+    // XXX There are some corner cases where jobs can double-complete.  Until
+    // we track all these down we do a non-fatal assert in debug builds and
+    // a runtime check to verify the queue is in the correct state.
+    NS_ASSERTION(!queue.mJobs.IsEmpty(),
+                 "Job queue should contain the job that just completed.");
+    NS_ASSERTION(queue.mJobs[0] == aJob,
+                 "Job queue should contain the job that just completed.");
+    if (NS_WARN_IF(queue.mJobs.SafeElementAt(0, nullptr) != aJob)) {
       return;
     }
     Pop(queue);
   }
 };
 
 namespace {