import from UXP: Issue #618 - (async) Split out function to add async request. (d8c2bc29)

This commit is contained in:
2022-04-15 23:47:45 +08:00
parent 68fc0c9d6f
commit 83c01dc5fe
2 changed files with 31 additions and 23 deletions
+30 -23
View File
@@ -1359,17 +1359,14 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
request->mJSVersion = version;
if (aElement->GetScriptAsync()) {
request->mInAsyncList = true;
AddAsyncRequest(request);
if (request->IsReadyToRun()) {
mLoadedAsyncRequests.AppendElement(request);
// The script is available already. Run it ASAP when the event
// loop gets a chance to spin.
// KVKV TODO: Instead of processing immediately, try off-thread-parsing
// it and only schedule a pending ProcessRequest if that fails.
ProcessPendingRequestsAsync();
} else {
mLoadingAsyncRequests.AppendElement(request);
}
return false;
}
@@ -1470,8 +1467,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
modReq->mBaseURL = mDocument->GetDocBaseURI();
if (aElement->GetScriptAsync()) {
modReq->mInAsyncList = true;
mLoadingAsyncRequests.AppendElement(modReq);
AddAsyncRequest(modReq);
} else {
AddDeferRequest(modReq);
}
@@ -2440,23 +2436,6 @@ ScriptLoader::NumberOfProcessors()
return mNumberOfProcessors;
}
void
ScriptLoader::MaybeMoveToLoadedList(ScriptLoadRequest* aRequest)
{
MOZ_ASSERT(aRequest->IsReadyToRun());
// If it's async, move it to the loaded list. aRequest->mInAsyncList really
// _should_ be in a list, but the consequences if it's not are bad enough we
// want to avoid trying to move it if it's not.
if (aRequest->mInAsyncList) {
MOZ_ASSERT(aRequest->isInList());
if (aRequest->isInList()) {
RefPtr<ScriptLoadRequest> req = mLoadingAsyncRequests.Steal(aRequest);
mLoadedAsyncRequests.AppendElement(req);
}
}
}
nsresult
ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
nsIIncrementalStreamLoader* aLoader,
@@ -2672,6 +2651,34 @@ ScriptLoader::AddDeferRequest(ScriptLoadRequest* aRequest)
}
}
void
ScriptLoader::AddAsyncRequest(ScriptLoadRequest* aRequest)
{
aRequest->mInAsyncList = true;
if (aRequest->IsReadyToRun()) {
mLoadedAsyncRequests.AppendElement(aRequest);
} else {
mLoadingAsyncRequests.AppendElement(aRequest);
}
}
void
ScriptLoader::MaybeMoveToLoadedList(ScriptLoadRequest* aRequest)
{
MOZ_ASSERT(aRequest->IsReadyToRun());
// If it's async, move it to the loaded list. aRequest->mInAsyncList really
// _should_ be in a list, but the consequences if it's not are bad enough we
// want to avoid trying to move it if it's not.
if (aRequest->mInAsyncList) {
MOZ_ASSERT(aRequest->isInList());
if (aRequest->isInList()) {
RefPtr<ScriptLoadRequest> req = mLoadingAsyncRequests.Steal(aRequest);
mLoadedAsyncRequests.AppendElement(req);
}
}
}
bool
ScriptLoader::MaybeRemovedDeferRequests()
{