Bug 1465670 P8 Convert WorkerPrivate::LoadScriptAsPartOfLoadingServiceWorkerScript() to simply IsLoadWorkerScript(). r=asuth
authorBen Kelly <ben@wanderview.com>
Tue, 05 Jun 2018 10:49:13 -0700
changeset 421458 c8103e36d8cff7ae4d18244f1ea5bef53c78c1b1
parent 421457 eab80a391434d02618c5f47a04eb28982dccad0c
child 421459 300f70a00d0be95050e62e3e757304bd1fceeb9e
push id34093
push useraiakab@mozilla.com
push dateTue, 05 Jun 2018 21:58:58 +0000
treeherdermozilla-central@da28b92efe6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1465670
milestone62.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 1465670 P8 Convert WorkerPrivate::LoadScriptAsPartOfLoadingServiceWorkerScript() to simply IsLoadWorkerScript(). r=asuth
dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp
dom/workers/ScriptLoader.cpp
dom/workers/WorkerPrivate.h
--- a/dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp
+++ b/dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp
@@ -726,17 +726,17 @@ ServiceWorkerRegistrationWorkerThread::U
   if (NS_WARN_IF(!workerRef)) {
     return ServiceWorkerRegistrationPromise::CreateAndReject(
       NS_ERROR_DOM_INVALID_STATE_ERR, __func__);
   }
 
   // Avoid infinite update loops by ignoring update() calls during top
   // level script evaluation.  See:
   // https://github.com/slightlyoff/ServiceWorker/issues/800
-  if (workerRef->Private()->LoadScriptAsPartOfLoadingServiceWorkerScript()) {
+  if (workerRef->Private()->IsLoadingWorkerScript()) {
     return ServiceWorkerRegistrationPromise::CreateAndResolve(mDescriptor,
                                                               __func__);
   }
 
   // Eventually we need to support all workers, but for right now this
   // code assumes we're on a service worker global as self.registration.
   if (NS_WARN_IF(!workerRef->Private()->IsServiceWorker())) {
     return ServiceWorkerRegistrationPromise::CreateAndReject(
--- a/dom/workers/ScriptLoader.cpp
+++ b/dom/workers/ScriptLoader.cpp
@@ -908,17 +908,17 @@ private:
     mCacheCreator = nullptr;
   }
 
   nsresult
   RunInternal()
   {
     AssertIsOnMainThread();
 
-    if (IsMainWorkerScript() && mWorkerPrivate->IsServiceWorker()) {
+    if (IsMainWorkerScript()) {
       mWorkerPrivate->SetLoadingWorkerScript(true);
     }
 
     if (!mWorkerPrivate->IsServiceWorker() || IsDebuggerScript()) {
       for (uint32_t index = 0, len = mLoadInfos.Length(); index < len;
            ++index) {
         nsresult rv = LoadScript(index);
         if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -2181,17 +2181,17 @@ ScriptExecutorRunnable::ShutdownScriptLo
                                              WorkerPrivate* aWorkerPrivate,
                                              bool aResult,
                                              bool aMutedError)
 {
   aWorkerPrivate->AssertIsOnWorkerThread();
 
   MOZ_ASSERT(mLastIndex == mScriptLoader.mLoadInfos.Length() - 1);
 
-  if (mIsWorkerScript && aWorkerPrivate->IsServiceWorker()) {
+  if (mIsWorkerScript) {
     aWorkerPrivate->SetLoadingWorkerScript(false);
   }
 
   if (!aResult) {
     // At this point there are two possibilities:
     //
     // 1) mScriptLoader.mRv.Failed().  In that case we just want to leave it
     //    as-is, except if it has a JS exception and we need to mute JS
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -1038,36 +1038,29 @@ public:
 
   // Determine if the SW testing per-window flag is set by devtools
   bool
   ServiceWorkersTestingInWindow() const
   {
     return mLoadInfo.mServiceWorkersTestingInWindow;
   }
 
-  // This is used to handle importScripts(). When the worker is first loaded
-  // and executed, it happens in a sync loop. At this point it sets
-  // mLoadingWorkerScript to true. importScripts() calls that occur during the
-  // execution run in nested sync loops and so this continues to return true,
-  // leading to these scripts being cached offline.
-  // mLoadingWorkerScript is set to false when the top level loop ends.
-  // importScripts() in function calls or event handlers are always fetched
-  // from the network.
+  // Determine if the worker is currently loading its top level script.
   bool
-  LoadScriptAsPartOfLoadingServiceWorkerScript()
+  IsLoadingWorkerScript() const
   {
-    MOZ_ASSERT(IsServiceWorker());
     return mLoadingWorkerScript;
   }
 
+  // Called by ScriptLoader to track when this worker is loading its
+  // top level script.
   void
   SetLoadingWorkerScript(bool aLoadingWorkerScript)
   {
     // any thread
-    MOZ_ASSERT(IsServiceWorker());
     mLoadingWorkerScript = aLoadingWorkerScript;
   }
 
   void
   QueueRunnable(nsIRunnable* aRunnable)
   {
     AssertIsOnParentThread();
     mQueuedRunnables.AppendElement(aRunnable);