Bug 1335425 Improve ScriptLoader CacheCreator's ability to handle failures and cancelation. r=baku
authorBen Kelly <ben@wanderview.com>
Wed, 01 Feb 2017 06:48:07 -0800
changeset 332014 d38b5eb6394fba7328aa9eca107e82155becae5a
parent 332013 0182967f77035109424d3cd448e7c01445e79267
child 332015 923cece3a29d10dd7a08997a1baf77409a51d843
push id31294
push userkwierso@gmail.com
push dateThu, 02 Feb 2017 00:25:26 +0000
treeherdermozilla-central@ece0e0fd16a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1335425
milestone54.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 1335425 Improve ScriptLoader CacheCreator's ability to handle failures and cancelation. r=baku
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));