Bug 1261776 Use SafeElementAt() in service worker job queue. r=ehsan a=abillings
authorBen Kelly <ben@wanderview.com>
Wed, 06 Apr 2016 10:21:14 -0700
changeset 310449 88c116e76afdeaa21a65b880c55af3e546777534
parent 310448 601a549ff293fe0f13e9685c229cef680ca7e571
child 310450 f3a938f7ab1d752effe0ff5d0163e30b6e722e2b
push id9365
push userbkelly@mozilla.com
push dateWed, 06 Apr 2016 17:21:21 +0000
treeherdermozilla-aurora@88c116e76afd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, abillings
bugs1261776
milestone47.0a2
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
@@ -297,19 +297,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 {