Backed out changeset d518009bfe70 (bug 1290951) for causing Bug 1357437
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Wed, 19 Apr 2017 11:55:33 +0200
changeset 401893 c0ea5ed7f91a6be996a4a3c5ab25e2cdf6b4377e
parent 401892 6d498f6de1fc48d31415a1c0cd71ec2a975fdf18
child 401894 cf2bd61763cd87385e821916a2f2741656cf1d45
child 401954 cfdb84c6f39ba62ab732619370108ff7a08d894e
child 402035 5c95d81d1487a0cfe99e5ab396fc1293dfb4c429
child 403267 9cdad15bc911aad38b40d5be9a740d4d83fb9b3d
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1290951, 1357437
milestone55.0a1
backs outd518009bfe702ee7991c0d8b0099d221c067f5d2
first release with
nightly linux32
c0ea5ed7f91a / 55.0a1 / 20170419100228 / files
nightly linux64
c0ea5ed7f91a / 55.0a1 / 20170419100228 / files
nightly mac
c0ea5ed7f91a / 55.0a1 / 20170419030223 / files
nightly win32
c0ea5ed7f91a / 55.0a1 / 20170419030223 / files
nightly win64
c0ea5ed7f91a / 55.0a1 / 20170419030223 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset d518009bfe70 (bug 1290951) for causing Bug 1357437
dom/workers/ServiceWorkerScriptCache.cpp
--- a/dom/workers/ServiceWorkerScriptCache.cpp
+++ b/dom/workers/ServiceWorkerScriptCache.cpp
@@ -247,17 +247,55 @@ public:
     , mInCache(false)
   {
     AssertIsOnMainThread();
     MOZ_ASSERT(aRegistration);
   }
 
   nsresult
   Initialize(nsIPrincipal* aPrincipal, const nsAString& aURL,
-             const nsAString& aCacheName, nsILoadGroup* aLoadGroup);
+             const nsAString& aCacheName, nsILoadGroup* aLoadGroup)
+  {
+    AssertIsOnMainThread();
+    MOZ_ASSERT(aPrincipal);
+
+    mURL = aURL;
+
+    // Always create a CacheStorage since we want to write the network entry to
+    // the cache even if there isn't an existing one.
+    AutoJSAPI jsapi;
+    jsapi.Init();
+    ErrorResult result;
+    mSandbox.init(jsapi.cx());
+    mCacheStorage = CreateCacheStorage(jsapi.cx(), aPrincipal, result, &mSandbox);
+    if (NS_WARN_IF(result.Failed())) {
+      MOZ_ASSERT(!result.IsErrorWithMessage());
+      Cleanup();
+      return result.StealNSResult();
+    }
+
+    mCN = new CompareNetwork(this);
+    nsresult rv = mCN->Initialize(aPrincipal, aURL, aLoadGroup);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      Cleanup();
+      return rv;
+    }
+
+    if (!aCacheName.IsEmpty()) {
+      mCC = new CompareCache(this);
+      rv = mCC->Initialize(aPrincipal, aURL, aCacheName);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        mCN->Abort();
+        Cleanup();
+        return rv;
+      }
+    }
+
+    return NS_OK;
+  }
 
   const nsString&
   URL() const
   {
     AssertIsOnMainThread();
     return mURL;
   }
 
@@ -332,21 +370,67 @@ public:
     if (!mCC || !mInCache) {
       ComparisonFinished(NS_OK, false);
       return;
     }
 
     ComparisonFinished(NS_OK, mCC->Buffer().Equals(mCN->Buffer()));
   }
 
+  // This class manages 2 promises: 1 is to retrieve Cache object, and 2 is to
+  // Put the value in the cache. For this reason we have mState to know what
+  // callback we are handling.
   void
-  ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
+  ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
+  {
+    AssertIsOnMainThread();
+    MOZ_ASSERT(mCallback);
+
+    if (mState == WaitingForOpen) {
+      if (NS_WARN_IF(!aValue.isObject())) {
+        Fail(NS_ERROR_FAILURE);
+        return;
+      }
+
+      JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
+      if (NS_WARN_IF(!obj)) {
+        Fail(NS_ERROR_FAILURE);
+        return;
+      }
+
+      Cache* cache = nullptr;
+      nsresult rv = UNWRAP_OBJECT(Cache, obj, cache);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        Fail(rv);
+        return;
+      }
+
+      // Just to be safe.
+      RefPtr<Cache> kungfuDeathGrip = cache;
+      WriteToCache(cache);
+      return;
+    }
+
+    MOZ_ASSERT(mState == WaitingForPut);
+    mCallback->ComparisonResult(NS_OK, false /* aIsEqual */,
+                                mNewCacheName, mMaxScope);
+    Cleanup();
+  }
 
   void
-  RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
+  RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
+  {
+    AssertIsOnMainThread();
+    if (mState == WaitingForOpen) {
+      NS_WARNING("Could not open cache.");
+    } else {
+      NS_WARNING("Could not write to cache.");
+    }
+    Fail(NS_ERROR_FAILURE);
+  }
 
   CacheStorage*
   CacheStorage_()
   {
     AssertIsOnMainThread();
     MOZ_ASSERT(mCacheStorage);
     return mCacheStorage;
   }
@@ -392,20 +476,33 @@ private:
   ~CompareManager()
   {
     AssertIsOnMainThread();
     MOZ_ASSERT(!mCC);
     MOZ_ASSERT(!mCN);
   }
 
   void
-  Fail(nsresult aStatus);
+  Fail(nsresult aStatus)
+  {
+    AssertIsOnMainThread();
+    mCallback->ComparisonResult(aStatus, false /* aIsEqual */,
+                                EmptyString(), EmptyCString());
+    Cleanup();
+  }
 
   void
-  Cleanup();
+  Cleanup()
+  {
+    AssertIsOnMainThread();
+    MOZ_ASSERT(mCallback);
+    mCallback = nullptr;
+    mCN = nullptr;
+    mCC = nullptr;
+  }
 
   void
   ComparisonFinished(nsresult aStatus, bool aIsEqual)
   {
     AssertIsOnMainThread();
     MOZ_ASSERT(mCallback);
 
     if (NS_WARN_IF(NS_FAILED(aStatus))) {
@@ -909,131 +1006,16 @@ CompareCache::ManageValueResult(JSContex
     if (NS_WARN_IF(NS_FAILED(rv))) {
       mPump = nullptr;
       mManager->CacheFinished(rv, false);
       return;
     }
   }
 }
 
-nsresult
-CompareManager::Initialize(nsIPrincipal* aPrincipal,
-                           const nsAString& aURL,
-                           const nsAString& aCacheName,
-                           nsILoadGroup* aLoadGroup)
-{
-  AssertIsOnMainThread();
-  MOZ_ASSERT(aPrincipal);
-
-  mURL = aURL;
-
-  // Always create a CacheStorage since we want to write the network entry to
-  // the cache even if there isn't an existing one.
-  AutoJSAPI jsapi;
-  jsapi.Init();
-  ErrorResult result;
-  mSandbox.init(jsapi.cx());
-  mCacheStorage = CreateCacheStorage(jsapi.cx(), aPrincipal, result, &mSandbox);
-  if (NS_WARN_IF(result.Failed())) {
-    MOZ_ASSERT(!result.IsErrorWithMessage());
-    Cleanup();
-    return result.StealNSResult();
-  }
-
-  mCN = new CompareNetwork(this);
-  nsresult rv = mCN->Initialize(aPrincipal, aURL, aLoadGroup);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    Cleanup();
-    return rv;
-  }
-
-  if (!aCacheName.IsEmpty()) {
-    mCC = new CompareCache(this);
-    rv = mCC->Initialize(aPrincipal, aURL, aCacheName);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      mCN->Abort();
-      Cleanup();
-      return rv;
-    }
-  }
-
-  return NS_OK;
-}
-
-// This class manages 2 promises: 1 is to retrieve Cache object, and 2 is to
-// Put the value in the cache. For this reason we have mState to know what
-// callback we are handling.
-void
-CompareManager::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
-{
-  AssertIsOnMainThread();
-  MOZ_ASSERT(mCallback);
-
-  if (mState == WaitingForOpen) {
-    if (NS_WARN_IF(!aValue.isObject())) {
-      Fail(NS_ERROR_FAILURE);
-      return;
-    }
-
-    JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
-    if (NS_WARN_IF(!obj)) {
-      Fail(NS_ERROR_FAILURE);
-      return;
-    }
-
-    Cache* cache = nullptr;
-    nsresult rv = UNWRAP_OBJECT(Cache, obj, cache);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      Fail(rv);
-      return;
-    }
-
-    // Just to be safe.
-    RefPtr<Cache> kungfuDeathGrip = cache;
-    WriteToCache(cache);
-    return;
-  }
-
-  MOZ_ASSERT(mState == WaitingForPut);
-  mCallback->ComparisonResult(NS_OK, false /* aIsEqual */,
-                              mNewCacheName, mMaxScope);
-  Cleanup();
-}
-
-void
-CompareManager::RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
-{
-  AssertIsOnMainThread();
-  if (mState == WaitingForOpen) {
-    NS_WARNING("Could not open cache.");
-  } else {
-    NS_WARNING("Could not write to cache.");
-  }
-  Fail(NS_ERROR_FAILURE);
-}
-
-void
-CompareManager::Fail(nsresult aStatus)
-{
-  AssertIsOnMainThread();
-  mCallback->ComparisonResult(aStatus, false /* aIsEqual */,
-                              EmptyString(), EmptyCString());
-  Cleanup();
-}
-
-void
-CompareManager::Cleanup()
-{
-  AssertIsOnMainThread();
-  MOZ_ASSERT(mCallback);
-  mCallback = nullptr;
-  mCN = nullptr;
-  mCC = nullptr;
-}
-
 } // namespace
 
 nsresult
 PurgeCache(nsIPrincipal* aPrincipal, const nsAString& aCacheName)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(aPrincipal);