Bug 1742438 - Part 11: Replace Finished() check with IsAwaitingPromise() and move state change to worker thread; r=asuth,jonco

We don't need the mExecutionScheduled state, as the mLoadingFinished state was only used to
determine if the promise for a given request had resolved. In fact -- we already know that it is in
a possibly resolved state when we call MaybeExecuteFinishedScripts. So, we can remove this state,
and only have the meaningful check (whether or not a promise on the service worker case hasn't
resolved yet) instead.

Differential Revision: https://phabricator.services.mozilla.com/D146183
This commit is contained in:
Yulia Startsev 2022-07-14 17:07:28 +00:00
Родитель 5552f1227e
Коммит 68fc4d0318
2 изменённых файлов: 5 добавлений и 10 удалений

Просмотреть файл

@ -530,7 +530,6 @@ void WorkerScriptLoader::LoadingFinished(ScriptLoadRequest* aRequest,
WorkerLoadContext* loadContext = aRequest->GetWorkerLoadContext();
loadContext->mLoadResult = aRv;
aRequest->SetReady();
if (IsMainWorkerScript() && NS_SUCCEEDED(aRv)) {
MOZ_DIAGNOSTIC_ASSERT(mWorkerPrivate->PrincipalURIMatchesScriptURL());
@ -546,7 +545,7 @@ void WorkerScriptLoader::MaybeExecuteFinishedScripts(
// We execute the last step if we don't have a pending operation with the
// cache and the loading is completed.
WorkerLoadContext* loadContext = aRequest->GetWorkerLoadContext();
if (loadContext->Finished()) {
if (!loadContext->IsAwaitingPromise()) {
loadContext->ClearCacheCreator();
DispatchMaybeMoveToLoadedList(aRequest);
}
@ -554,13 +553,11 @@ void WorkerScriptLoader::MaybeExecuteFinishedScripts(
void WorkerScriptLoader::MaybeMoveToLoadedList(ScriptLoadRequest* aRequest) {
mWorkerPrivate->AssertIsOnWorkerThread();
WorkerLoadContext* loadContext = aRequest->GetWorkerLoadContext();
MOZ_ASSERT(!loadContext->mExecutionScheduled);
loadContext->mExecutionScheduled = true;
aRequest->SetReady();
while (!mLoadingRequests.isEmpty()) {
ScriptLoadRequest* request = mLoadingRequests.getFirst();
if (!request->GetWorkerLoadContext()->mExecutionScheduled) {
if (!request->IsReadyToRun()) {
break;
}
@ -898,7 +895,7 @@ bool WorkerScriptLoader::EvaluateScript(JSContext* aCx,
WorkerLoadContext* loadContext = aRequest->GetWorkerLoadContext();
NS_ASSERTION(loadContext->mExecutionScheduled, "Should be scheduled!");
NS_ASSERTION(aRequest->IsReadyToRun(), "Should be scheduled!");
MOZ_ASSERT(!mRv.Failed(), "Who failed it and why?");
mRv.MightThrowJSException();

Просмотреть файл

@ -60,8 +60,6 @@ class WorkerLoadContext : public JS::loader::LoadContextBase {
RefPtr<workerinternals::loader::CacheCreator> GetCacheCreator();
bool mExecutionScheduled = false;
Maybe<nsString> mSourceMapURL;
enum CacheStatus {
@ -88,7 +86,7 @@ class WorkerLoadContext : public JS::loader::LoadContextBase {
Maybe<bool> mMutedErrorFlag;
bool Finished() const { return mRequest->IsReadyToRun() && !mCachePromise; }
bool IsAwaitingPromise() const { return bool(mCachePromise); }
};
} // namespace mozilla::dom