Bug 1335425 Improve ScriptLoader CacheCreator's ability to handle failures and cancelation. r=baku a=jcristau
authorBen Kelly <ben@wanderview.com>
Wed, 01 Feb 2017 06:48:07 -0800
changeset 375849 ebaae8442fa17cbae09d2168e36f79dc5ef39b35
parent 375848 6ad72b5a43e15125e1baf4a88183b467c042894e
child 375850 d1569ed822af8f33141533522e7ea3b3ab6f2eea
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, jcristau
bugs1335425
milestone53.0a2
Bug 1335425 Improve ScriptLoader CacheCreator's ability to handle failures and cancelation. r=baku a=jcristau
dom/workers/ScriptLoader.cpp
--- a/dom/workers/ScriptLoader.cpp
+++ b/dom/workers/ScriptLoader.cpp
@@ -1552,53 +1552,58 @@ CacheCreator::RejectedCallback(JSContext
   AssertIsOnMainThread();
   FailLoaders(NS_ERROR_FAILURE);
 }
 
 void
 CacheCreator::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
 {
   AssertIsOnMainThread();
-  MOZ_ASSERT(aValue.isObject());
+
+  if (!aValue.isObject()) {
+    FailLoaders(NS_ERROR_FAILURE);
+    return;
+  }
 
   JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
   Cache* cache = nullptr;
   nsresult rv = UNWRAP_OBJECT(Cache, obj, cache);
-  MOZ_ALWAYS_SUCCEEDS(rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    FailLoaders(NS_ERROR_FAILURE);
+    return;
+  }
 
   mCache = cache;
-  MOZ_ASSERT(mCache);
+  MOZ_DIAGNOSTIC_ASSERT(mCache);
 
   // If the worker is canceled, CancelMainThread() will have cleared the
-  // loaders.
+  // loaders via DeleteCache().
   for (uint32_t i = 0, len = mLoaders.Length(); i < len; ++i) {
+    MOZ_DIAGNOSTIC_ASSERT(mLoaders[i]);
     mLoaders[i]->Load(cache);
   }
 }
 
 void
 CacheCreator::DeleteCache()
 {
   AssertIsOnMainThread();
 
   // This is called when the load is canceled which can occur before
   // mCacheStorage is initialized.
-  if (!mCacheStorage) {
-    return;
+  if (mCacheStorage) {
+    // It's safe to do this while Cache::Match() and Cache::Put() calls are
+    // running.
+    IgnoredErrorResult rv;
+    RefPtr<Promise> promise = mCacheStorage->Delete(mCacheName, rv);
+
+    // We don't care to know the result of the promise object.
   }
 
-  // It's safe to do this while Cache::Match() and Cache::Put() calls are
-  // running.
-  IgnoredErrorResult rv;
-  RefPtr<Promise> promise = mCacheStorage->Delete(mCacheName, rv);
-  if (NS_WARN_IF(rv.Failed())) {
-    return;
-  }
-
-  // We don't care to know the result of the promise object.
+  // Always call this here to ensure the loaders array is cleared.
   FailLoaders(NS_ERROR_FAILURE);
 }
 
 void
 CacheScriptLoader::Fail(nsresult aRv)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(NS_FAILED(aRv));