Bug 1261776 Use SafeElementAt() in service worker job queue. r=ehsan
authorBen Kelly <ben@wanderview.com>
Wed, 06 Apr 2016 10:21:36 -0700
changeset 291951 453f314bd7aeb86e190f17370e77e779a01d90ab
parent 291950 946e39f5d97dd31ed852ae19150143181d945844
child 291952 a3f8a4e83cdd6c8274b4713ca6d1fa01fe9c5bcb
push id30149
push usercbook@mozilla.com
push dateThu, 07 Apr 2016 09:52:31 +0000
treeherdermozilla-central@b6683e141c47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1261776
milestone48.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 1261776 Use SafeElementAt() in service worker job queue. r=ehsan
dom/workers/ServiceWorkerManager.cpp
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -310,19 +310,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 {