mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
Bug 1813494 - Part 1: Common up code to cancel and remove all load requests r=smaug
Cancellation happend in ParsingComplete() and Destroy() but was inconsistent in which kinds of requests were cancelled and which were cancelled and removed. This makes one method that cancels and removes everything and uses it in both places. Differential Revision: https://phabricator.services.mozilla.com/D168231
This commit is contained in:
parent
840cce01a4
commit
08b9729ccf
@ -1384,43 +1384,33 @@ ReferrerPolicy ScriptLoader::GetReferrerPolicy(nsIScriptElement* aElement) {
|
||||
return mDocument->GetReferrerPolicy();
|
||||
}
|
||||
|
||||
void ScriptLoader::CancelScriptLoadRequests() {
|
||||
// Cancel all requests that have not been executed.
|
||||
void ScriptLoader::CancelAndClearScriptLoadRequests() {
|
||||
// Cancel all requests that have not been executed and remove them.
|
||||
|
||||
if (mParserBlockingRequest) {
|
||||
mParserBlockingRequest->Cancel();
|
||||
mParserBlockingRequest = nullptr;
|
||||
}
|
||||
|
||||
for (ScriptLoadRequest* req = mXSLTRequests.getFirst(); req;
|
||||
req = req->getNext()) {
|
||||
req->Cancel();
|
||||
mDeferRequests.CancelRequestsAndClear();
|
||||
mLoadingAsyncRequests.CancelRequestsAndClear();
|
||||
mLoadedAsyncRequests.CancelRequestsAndClear();
|
||||
mNonAsyncExternalScriptInsertedRequests.CancelRequestsAndClear();
|
||||
mXSLTRequests.CancelRequestsAndClear();
|
||||
mOffThreadCompilingRequests.CancelRequestsAndClear();
|
||||
|
||||
for (ModuleLoader* loader : mWebExtModuleLoaders) {
|
||||
loader->CancelAndClearDynamicImports();
|
||||
}
|
||||
|
||||
for (ScriptLoadRequest* req = mDeferRequests.getFirst(); req;
|
||||
req = req->getNext()) {
|
||||
req->Cancel();
|
||||
}
|
||||
|
||||
for (ScriptLoadRequest* req = mLoadingAsyncRequests.getFirst(); req;
|
||||
req = req->getNext()) {
|
||||
req->Cancel();
|
||||
}
|
||||
|
||||
for (ScriptLoadRequest* req = mLoadedAsyncRequests.getFirst(); req;
|
||||
req = req->getNext()) {
|
||||
req->Cancel();
|
||||
}
|
||||
|
||||
for (ScriptLoadRequest* req =
|
||||
mNonAsyncExternalScriptInsertedRequests.getFirst();
|
||||
req; req = req->getNext()) {
|
||||
req->Cancel();
|
||||
for (ModuleLoader* loader : mShadowRealmModuleLoaders) {
|
||||
loader->CancelAndClearDynamicImports();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < mPreloads.Length(); i++) {
|
||||
mPreloads[i].mRequest->Cancel();
|
||||
}
|
||||
|
||||
mOffThreadCompilingRequests.CancelRequestsAndClear();
|
||||
mPreloads.Clear();
|
||||
}
|
||||
|
||||
nsresult ScriptLoader::CompileOffThreadOrProcessRequest(
|
||||
@ -2455,7 +2445,7 @@ void ScriptLoader::Destroy() {
|
||||
mShutdownObserver = nullptr;
|
||||
}
|
||||
|
||||
CancelScriptLoadRequests();
|
||||
CancelAndClearScriptLoadRequests();
|
||||
GiveUpBytecodeEncoding();
|
||||
}
|
||||
|
||||
@ -3162,8 +3152,9 @@ void ScriptLoader::HandleLoadError(ScriptLoadRequest* aRequest,
|
||||
aRequest->Cancel();
|
||||
}
|
||||
if (aRequest->IsTopLevel()) {
|
||||
MOZ_ALWAYS_TRUE(
|
||||
mPreloads.RemoveElement(aRequest, PreloadRequestComparator()));
|
||||
// Request may already have been removed by
|
||||
// CancelAndClearScriptLoadRequests.
|
||||
mPreloads.RemoveElement(aRequest, PreloadRequestComparator());
|
||||
}
|
||||
MOZ_ASSERT(!aRequest->isInList());
|
||||
AccumulateCategorical(LABELS_DOM_SCRIPT_PRELOAD_RESULT::LoadError);
|
||||
@ -3494,40 +3485,12 @@ void ScriptLoader::DeferCheckpointReached() {
|
||||
}
|
||||
|
||||
void ScriptLoader::ParsingComplete(bool aTerminated) {
|
||||
if (!aTerminated) {
|
||||
return;
|
||||
}
|
||||
mDeferRequests.CancelRequestsAndClear();
|
||||
mLoadingAsyncRequests.CancelRequestsAndClear();
|
||||
mLoadedAsyncRequests.CancelRequestsAndClear();
|
||||
mNonAsyncExternalScriptInsertedRequests.CancelRequestsAndClear();
|
||||
mXSLTRequests.CancelRequestsAndClear();
|
||||
if (aTerminated) {
|
||||
CancelAndClearScriptLoadRequests();
|
||||
|
||||
if (mModuleLoader) {
|
||||
mModuleLoader->CancelAndClearDynamicImports();
|
||||
// Have to call this even if aTerminated so we'll correctly unblock onload.
|
||||
DeferCheckpointReached();
|
||||
}
|
||||
|
||||
for (ModuleLoader* loader : mWebExtModuleLoaders) {
|
||||
loader->CancelAndClearDynamicImports();
|
||||
}
|
||||
|
||||
for (ModuleLoader* loader : mShadowRealmModuleLoaders) {
|
||||
loader->CancelAndClearDynamicImports();
|
||||
}
|
||||
|
||||
if (mParserBlockingRequest) {
|
||||
mParserBlockingRequest->Cancel();
|
||||
mParserBlockingRequest = nullptr;
|
||||
}
|
||||
|
||||
// Cancel any unused scripts that were compiled speculatively
|
||||
for (size_t i = 0; i < mPreloads.Length(); i++) {
|
||||
mPreloads[i].mRequest->GetScriptLoadContext()->MaybeCancelOffThreadScript();
|
||||
}
|
||||
|
||||
// Have to call this even if aTerminated so we'll correctly unblock
|
||||
// onload and all.
|
||||
DeferCheckpointReached();
|
||||
}
|
||||
|
||||
void ScriptLoader::PreloadURI(nsIURI* aURI, const nsAString& aCharset,
|
||||
|
@ -698,10 +698,10 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
||||
void RunScriptWhenSafe(ScriptLoadRequest* aRequest);
|
||||
|
||||
/**
|
||||
* Wait for any unused off thread compilations to finish and then
|
||||
* cancel them.
|
||||
* Cancel and remove all outstanding load requests, including waiting for any
|
||||
* off thread compilations to finish.
|
||||
*/
|
||||
void CancelScriptLoadRequests();
|
||||
void CancelAndClearScriptLoadRequests();
|
||||
|
||||
Document* mDocument; // [WEAK]
|
||||
nsCOMArray<nsIScriptLoaderObserver> mObservers;
|
||||
|
Loading…
Reference in New Issue
Block a user