From 80cac6bbb5a3b3a7658b8c55c12a967843055848 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Fri, 4 Aug 2023 09:40:40 +0000 Subject: [PATCH] Bug 1843838 - Rename ScriptLoadRequest::IsReadyToRun to IsFinished since this returns true for cancelled requests r=smaug Differential Revision: https://phabricator.services.mozilla.com/D183740 --- dom/script/ModuleLoader.cpp | 2 +- dom/script/ScriptLoadContext.cpp | 3 +-- dom/script/ScriptLoader.cpp | 26 +++++++++++++------------- dom/workers/ScriptLoader.cpp | 4 ++-- js/loader/ModuleLoadRequest.cpp | 14 +++++++------- js/loader/ModuleLoadRequest.h | 2 +- js/loader/ModuleLoaderBase.cpp | 2 +- js/loader/ScriptLoadRequest.cpp | 2 +- js/loader/ScriptLoadRequest.h | 7 ++++--- js/xpconnect/loader/mozJSModuleLoader.cpp | 2 +- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/dom/script/ModuleLoader.cpp b/dom/script/ModuleLoader.cpp index e54a63177a66..3e2e53e02470 100644 --- a/dom/script/ModuleLoader.cpp +++ b/dom/script/ModuleLoader.cpp @@ -128,7 +128,7 @@ nsresult ModuleLoader::StartFetch(ModuleLoadRequest* aRequest) { } void ModuleLoader::OnModuleLoadComplete(ModuleLoadRequest* aRequest) { - MOZ_ASSERT(aRequest->IsReadyToRun()); + MOZ_ASSERT(aRequest->IsFinished()); if (aRequest->IsTopLevel()) { if (aRequest->GetScriptLoadContext()->mIsInline && diff --git a/dom/script/ScriptLoadContext.cpp b/dom/script/ScriptLoadContext.cpp index 8bc2275ae3b5..c0f9fea5bf66 100644 --- a/dom/script/ScriptLoadContext.cpp +++ b/dom/script/ScriptLoadContext.cpp @@ -157,8 +157,7 @@ bool ScriptLoadContext::IsPreload() const { } bool ScriptLoadContext::CompileStarted() const { - return mRequest->IsCompiling() || - (mRequest->IsReadyToRun() && mWasCompiledOMT); + return mRequest->IsCompiling() || (mRequest->IsFinished() && mWasCompiledOMT); } nsIScriptElement* ScriptLoadContext::GetScriptElement() const { diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 412cbd0ace6c..ebab1034e1f6 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -1061,7 +1061,7 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement, if (request->GetScriptLoadContext()->IsAsyncScript()) { AddAsyncRequest(request); - if (request->IsReadyToRun()) { + if (request->IsFinished()) { // The script is available already. Run it ASAP when the event // loop gets a chance to spin. @@ -1077,7 +1077,7 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement, // http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html request->GetScriptLoadContext()->mIsNonAsyncScriptInserted = true; mNonAsyncExternalScriptInsertedRequests.AppendElement(request); - if (request->IsReadyToRun()) { + if (request->IsFinished()) { // The script is available already. Run it ASAP when the event // loop gets a chance to spin. ProcessPendingRequestsAsync(); @@ -1107,7 +1107,7 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement, "Parser-blocking scripts and XSLT scripts in the same doc!"); request->GetScriptLoadContext()->mIsXSLT = true; mXSLTRequests.AppendElement(request); - if (request->IsReadyToRun()) { + if (request->IsFinished()) { // The script is available already. Run it ASAP when the event // loop gets a chance to spin. ProcessPendingRequestsAsync(); @@ -1115,7 +1115,7 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement, return true; } - if (request->IsReadyToRun() && ReadyToExecuteParserBlockingScripts()) { + if (request->IsFinished() && ReadyToExecuteParserBlockingScripts()) { // The request has already been loaded and there are no pending style // sheets. If the script comes from the network stream, cheat for // performance reasons and avoid a trip through the event loop. @@ -1515,7 +1515,7 @@ nsresult ScriptLoader::AttemptOffThreadScriptCompile( // If speculative parsing is enabled, the request may not be ready to run if // the element is not yet available. MOZ_ASSERT_IF(!SpeculativeOMTParsingEnabled() && !aRequest->IsModuleRequest(), - aRequest->IsReadyToRun()); + aRequest->IsFinished()); MOZ_ASSERT(!aRequest->GetScriptLoadContext()->mWasCompiledOMT); MOZ_ASSERT(aCouldCompileOut && !*aCouldCompileOut); @@ -1801,7 +1801,7 @@ nsresult ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest) { NS_ASSERTION(nsContentUtils::IsSafeToRunScript(), "Processing requests when running scripts is unsafe."); - NS_ASSERTION(aRequest->IsReadyToRun(), + NS_ASSERTION(aRequest->IsFinished(), "Processing a request that is not ready to run."); NS_ENSURE_ARG(aRequest); @@ -2174,7 +2174,7 @@ static nsresult ExecuteCompiledScript(JSContext* aCx, JSExecutionContext& aExec, nsresult ScriptLoader::EvaluateScriptElement(ScriptLoadRequest* aRequest) { using namespace mozilla::Telemetry; - MOZ_ASSERT(aRequest->IsReadyToRun()); + MOZ_ASSERT(aRequest->IsFinished()); // We need a document to evaluate scripts. if (!mDocument) { @@ -2744,7 +2744,7 @@ void ScriptLoader::ProcessPendingRequestsAsync() { void ScriptLoader::ProcessPendingRequests() { RefPtr request; - if (mParserBlockingRequest && mParserBlockingRequest->IsReadyToRun() && + if (mParserBlockingRequest && mParserBlockingRequest->IsFinished() && ReadyToExecuteParserBlockingScripts()) { request.swap(mParserBlockingRequest); UnblockParser(request); @@ -2753,7 +2753,7 @@ void ScriptLoader::ProcessPendingRequests() { } while (ReadyToExecuteParserBlockingScripts() && !mXSLTRequests.isEmpty() && - mXSLTRequests.getFirst()->IsReadyToRun()) { + mXSLTRequests.getFirst()->IsFinished()) { request = mXSLTRequests.StealFirst(); ProcessRequest(request); } @@ -2769,7 +2769,7 @@ void ScriptLoader::ProcessPendingRequests() { while (ReadyToExecuteScripts() && !mNonAsyncExternalScriptInsertedRequests.isEmpty() && - mNonAsyncExternalScriptInsertedRequests.getFirst()->IsReadyToRun()) { + mNonAsyncExternalScriptInsertedRequests.getFirst()->IsFinished()) { // Violate the HTML5 spec and execute these in the insertion order in // order to make LABjs and the "order" plug-in for RequireJS work with // their Gecko-sniffed code path. See @@ -2780,7 +2780,7 @@ void ScriptLoader::ProcessPendingRequests() { if (mDeferCheckpointReached && mXSLTRequests.isEmpty()) { while (ReadyToExecuteScripts() && !mDeferRequests.isEmpty() && - mDeferRequests.getFirst()->IsReadyToRun()) { + mDeferRequests.getFirst()->IsFinished()) { request = mDeferRequests.StealFirst(); ProcessRequest(request); } @@ -3640,7 +3640,7 @@ void ScriptLoader::AddAsyncRequest(ScriptLoadRequest* aRequest) { MOZ_ASSERT(!aRequest->GetScriptLoadContext()->mInCompilingList); aRequest->GetScriptLoadContext()->mInAsyncList = true; - if (aRequest->IsReadyToRun()) { + if (aRequest->IsFinished()) { mLoadedAsyncRequests.AppendElement(aRequest); } else { mLoadingAsyncRequests.AppendElement(aRequest); @@ -3648,7 +3648,7 @@ void ScriptLoader::AddAsyncRequest(ScriptLoadRequest* aRequest) { } void ScriptLoader::MaybeMoveToLoadedList(ScriptLoadRequest* aRequest) { - MOZ_ASSERT(aRequest->IsReadyToRun()); + MOZ_ASSERT(aRequest->IsFinished()); MOZ_ASSERT(aRequest->IsTopLevel()); // If it's async, move it to the loaded list. diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 7a16bcdf5702..d02f0171b8fd 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -804,7 +804,7 @@ void WorkerScriptLoader::MaybeMoveToLoadedList(ScriptLoadRequest* aRequest) { ScriptLoadRequest* request = mLoadingRequests.getFirst(); // We need to move requests in post order. If prior requests have not // completed, delay execution. - if (!request->IsReadyToRun()) { + if (!request->IsFinished()) { break; } @@ -1116,7 +1116,7 @@ bool WorkerScriptLoader::EvaluateScript(JSContext* aCx, WorkerLoadContext* loadContext = aRequest->GetWorkerLoadContext(); NS_ASSERTION(!loadContext->mChannel, "Should no longer have a channel!"); - NS_ASSERTION(aRequest->IsReadyToRun(), "Should be scheduled!"); + NS_ASSERTION(aRequest->IsFinished(), "Should be scheduled!"); MOZ_ASSERT(!mRv.Failed(), "Who failed it and why?"); mRv.MightThrowJSException(); diff --git a/js/loader/ModuleLoadRequest.cpp b/js/loader/ModuleLoadRequest.cpp index 6e3a1721da57..362cb8d5df66 100644 --- a/js/loader/ModuleLoadRequest.cpp +++ b/js/loader/ModuleLoadRequest.cpp @@ -82,7 +82,7 @@ void ModuleLoadRequest::Cancel() { return; } - if (IsReadyToRun()) { + if (IsFinished()) { return; } @@ -97,13 +97,13 @@ void ModuleLoadRequest::Cancel() { } void ModuleLoadRequest::SetReady() { - MOZ_ASSERT(!IsReadyToRun()); + MOZ_ASSERT(!IsFinished()); // Mark a module as ready to execute. This means that this module and all it // dependencies have had their source loaded, parsed as a module and the // modules instantiated. - AssertAllImportsReady(); + AssertAllImportsFinished(); ScriptLoadRequest::SetReady(); @@ -161,13 +161,13 @@ void ModuleLoadRequest::ModuleErrored() { return; } - MOZ_ASSERT(!IsReadyToRun()); + MOZ_ASSERT(!IsFinished()); CheckModuleDependenciesLoaded(); MOZ_ASSERT(IsErrored()); CancelImports(); - if (IsReadyToRun()) { + if (IsFinished()) { // Cancelling an outstanding import will error this request. return; } @@ -234,10 +234,10 @@ void ModuleLoadRequest::ClearDynamicImport() { mDynamicPromise = nullptr; } -inline void ModuleLoadRequest::AssertAllImportsReady() const { +inline void ModuleLoadRequest::AssertAllImportsFinished() const { #ifdef DEBUG for (const auto& request : mImports) { - MOZ_ASSERT(request->IsReadyToRun()); + MOZ_ASSERT(request->IsFinished()); } #endif } diff --git a/js/loader/ModuleLoadRequest.h b/js/loader/ModuleLoadRequest.h index 26b793379999..643414621275 100644 --- a/js/loader/ModuleLoadRequest.h +++ b/js/loader/ModuleLoadRequest.h @@ -119,7 +119,7 @@ class ModuleLoadRequest final : public ScriptLoadRequest { void CancelImports(); void CheckModuleDependenciesLoaded(); - void AssertAllImportsReady() const; + void AssertAllImportsFinished() const; void AssertAllImportsCancelled() const; public: diff --git a/js/loader/ModuleLoaderBase.cpp b/js/loader/ModuleLoaderBase.cpp index 78fe5cc86863..63bbe1311f47 100644 --- a/js/loader/ModuleLoaderBase.cpp +++ b/js/loader/ModuleLoaderBase.cpp @@ -939,7 +939,7 @@ void ModuleLoadRequest::ChildLoadComplete(bool aSuccess) { mWaitingParentRequest = nullptr; parent->mAwaitingImports--; - if (parent->IsReadyToRun()) { + if (parent->IsFinished()) { MOZ_ASSERT_IF(!aSuccess, parent->IsErrored()); return; } diff --git a/js/loader/ScriptLoadRequest.cpp b/js/loader/ScriptLoadRequest.cpp index 7d33c3ae63e4..f3bab584096b 100644 --- a/js/loader/ScriptLoadRequest.cpp +++ b/js/loader/ScriptLoadRequest.cpp @@ -102,7 +102,7 @@ ScriptLoadRequest::ScriptLoadRequest(ScriptKind aKind, nsIURI* aURI, ScriptLoadRequest::~ScriptLoadRequest() { DropJSObjects(this); } void ScriptLoadRequest::SetReady() { - MOZ_ASSERT(!IsReadyToRun()); + MOZ_ASSERT(!IsFinished()); mState = State::Ready; } diff --git a/js/loader/ScriptLoadRequest.h b/js/loader/ScriptLoadRequest.h index 5844e5957cb6..56a08ecce303 100644 --- a/js/loader/ScriptLoadRequest.h +++ b/js/loader/ScriptLoadRequest.h @@ -222,13 +222,14 @@ class ScriptLoadRequest bool IsFetching() const { return mState == State::Fetching; } bool IsCompiling() const { return mState == State::Compiling; } bool IsLoadingImports() const { return mState == State::LoadingImports; } + bool IsCanceled() const { return mState == State::Canceled; } - bool IsReadyToRun() const { + // Return whether the request has been completed, either successfully or + // otherwise. + bool IsFinished() const { return mState == State::Ready || mState == State::Canceled; } - bool IsCanceled() const { return mState == State::Canceled; } - // Type of data provided by the nsChannel. enum class DataType : uint8_t { eUnknown, eTextSource, eBytecode }; diff --git a/js/xpconnect/loader/mozJSModuleLoader.cpp b/js/xpconnect/loader/mozJSModuleLoader.cpp index 28a1b99d3d98..7ef554940b98 100644 --- a/js/xpconnect/loader/mozJSModuleLoader.cpp +++ b/js/xpconnect/loader/mozJSModuleLoader.cpp @@ -1832,7 +1832,7 @@ nsresult mozJSModuleLoader::ImportESModule( return rv; } - MOZ_ASSERT(request->IsReadyToRun()); + MOZ_ASSERT(request->IsFinished()); if (!request->mModuleScript) { mModuleLoader->MaybeReportLoadError(aCx); return NS_ERROR_FAILURE; -- 2.11.4.GIT