Skip to content
Permalink
Browse files

Bug 931249 - Patch 12 - Call LoadingFinished even if channel is not p…

…resent. r=khuey

If the failure was due to inability to create a channel (csp, other restrictions) we still want to mark the load as finished
  • Loading branch information...
rmottola committed Jul 1, 2019
1 parent 33bf983 commit 2a868e45a7d6d628e7da07d6bb621a93e192971d
Showing with 25 additions and 6 deletions.
  1. +25 −6 dom/workers/ScriptLoader.cpp
@@ -531,7 +531,7 @@ class ScriptLoaderRunnable final : public WorkerFeature,

// We execute the last step if we don't have a pending operation with the
// cache and the loading is completed.
if (!mCanceledMainThread && loadInfo.Finished()) {
if (loadInfo.Finished()) {
ExecuteFinishedScripts();
}
}
@@ -607,15 +607,26 @@ class ScriptLoaderRunnable final : public WorkerFeature,
for (uint32_t index = 0; index < mLoadInfos.Length(); index++) {
ScriptLoadInfo& loadInfo = mLoadInfos[index];

// If promise or channel is non-null, there failures will lead to
// LoadingFinished being called.
bool callLoadingFinished = true;

if (loadInfo.mCachePromise) {
MOZ_ASSERT(mWorkerPrivate->IsServiceWorker());
loadInfo.mCachePromise->MaybeReject(NS_BINDING_ABORTED);
loadInfo.mCachePromise = nullptr;
callLoadingFinished = false;
}

if (loadInfo.mChannel &&
NS_FAILED(loadInfo.mChannel->Cancel(NS_BINDING_ABORTED))) {
NS_WARNING("Failed to cancel channel!");
if (loadInfo.mChannel) {
if (NS_SUCCEEDED(loadInfo.mChannel->Cancel(NS_BINDING_ABORTED))) {
callLoadingFinished = false;
} else {
NS_WARNING("Failed to cancel channel!");
}
}

if (callLoadingFinished && !loadInfo.Finished()) {
LoadingFinished(index, NS_BINDING_ABORTED);
}
}
@@ -1080,8 +1091,10 @@ CachePromiseHandler::ResolvedCallback(JSContext* aCx,
MOZ_ASSERT(mLoadInfo.mCacheStatus == ScriptLoadInfo::WritingToCache);
mLoadInfo.mCacheStatus = ScriptLoadInfo::Cached;

mLoadInfo.mCachePromise = nullptr;
mRunnable->MaybeExecuteFinishedScripts(mIndex);
if (mLoadInfo.mCachePromise) {
mLoadInfo.mCachePromise = nullptr;
mRunnable->MaybeExecuteFinishedScripts(mIndex);
}
}

void
@@ -1232,6 +1245,12 @@ CacheScriptLoader::Fail(nsresult aRv)
}

mLoadInfo.mCacheStatus = ScriptLoadInfo::Cancel;

// Stop if the load was aborted on the main thread.
if (mLoadInfo.Finished()) {
return;
}

mRunnable->LoadingFinished(mIndex, aRv);
}

0 comments on commit 2a868e4

Please sign in to comment.
You can’t perform that action at this time.