summaryrefslogtreecommitdiffstats
path: root/dom/script
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-08-24 10:15:00 +0000
committerMoonchild <moonchild@palemoon.org>2020-08-30 09:40:15 +0000
commit429a7bdb93e443236f4a4b04afc9a12c78f54247 (patch)
tree2c8f0db4e4aabd7b880207d28ed913fbf4055a79 /dom/script
parent3f14e9ec5ff982424f6ac2cf401037e3f749e6a3 (diff)
downloadUXP-429a7bdb93e443236f4a4b04afc9a12c78f54247.tar
UXP-429a7bdb93e443236f4a4b04afc9a12c78f54247.tar.gz
UXP-429a7bdb93e443236f4a4b04afc9a12c78f54247.tar.lz
UXP-429a7bdb93e443236f4a4b04afc9a12c78f54247.tar.xz
UXP-429a7bdb93e443236f4a4b04afc9a12c78f54247.zip
Issue #618 - (async) Split out function to add async request.
Diffstat (limited to 'dom/script')
-rw-r--r--dom/script/ScriptLoader.cpp53
-rw-r--r--dom/script/ScriptLoader.h1
2 files changed, 31 insertions, 23 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
index 69777c247..58f0c0bbe 100644
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -1358,17 +1358,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;
}
@@ -1469,8 +1466,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
modReq->mBaseURL = mDocument->GetDocBaseURI();
if (aElement->GetScriptAsync()) {
- modReq->mInAsyncList = true;
- mLoadingAsyncRequests.AppendElement(modReq);
+ AddAsyncRequest(modReq);
} else {
AddDeferRequest(modReq);
}
@@ -2418,23 +2414,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,
@@ -2646,6 +2625,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()
{
diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h
index 82a8512c0..61680a3ee 100644
--- a/dom/script/ScriptLoader.h
+++ b/dom/script/ScriptLoader.h
@@ -571,6 +571,7 @@ private:
mozilla::Vector<char16_t> &aString);
void AddDeferRequest(ScriptLoadRequest* aRequest);
+ void AddAsyncRequest(ScriptLoadRequest* aRequest);
bool MaybeRemovedDeferRequests();
void MaybeMoveToLoadedList(ScriptLoadRequest* aRequest);