Bug 1226443 P6 Ignore update() called during top level service worker script evaluation. r=ehsan
authorBen Kelly <ben@wanderview.com>
Fri, 11 Dec 2015 14:53:11 -0500
changeset 276255 412e32773fbf36ba8f6ccca4247890204bf7880a
parent 276254 5be379df35f17161d004bd830c4e616f89f2984c
child 276256 694a530e236564a3d9f4b9fd7d9e96ae782b3a7b
push id29786
push userphilringnalda@gmail.com
push dateSat, 12 Dec 2015 05:20:21 +0000
treeherdermozilla-central@694a530e2365 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1226443
milestone45.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 1226443 P6 Ignore update() called during top level service worker script evaluation. r=ehsan
dom/workers/ServiceWorkerRegistration.cpp
--- a/dom/workers/ServiceWorkerRegistration.cpp
+++ b/dom/workers/ServiceWorkerRegistration.cpp
@@ -995,16 +995,24 @@ ServiceWorkerRegistrationWorkerThread::U
   MOZ_ASSERT(worker);
   worker->AssertIsOnWorkerThread();
 
   RefPtr<Promise> promise = Promise::Create(worker->GlobalScope(), aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
+  // Avoid infinite update loops by ignoring update() calls during top
+  // level script evaluation.  See:
+  // https://github.com/slightlyoff/ServiceWorker/issues/800
+  if (worker->LoadScriptAsPartOfLoadingServiceWorkerScript()) {
+    promise->MaybeResolve(JS::UndefinedHandleValue);
+    return promise.forget();
+  }
+
   RefPtr<PromiseWorkerProxy> proxy = PromiseWorkerProxy::Create(worker, promise);
   if (!proxy) {
     aRv.Throw(NS_ERROR_DOM_ABORT_ERR);
     return nullptr;
   }
 
   RefPtr<UpdateRunnable> r = new UpdateRunnable(proxy, mScope);
   MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(r)));