summaryrefslogtreecommitdiffstats
path: root/dom/script
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-08-22 09:27:12 +0000
committerMoonchild <moonchild@palemoon.org>2020-08-30 09:39:03 +0000
commit767b637c838731f880adc92fb1e4b92bb5b591fd (patch)
tree9b41d082175fb2fc865743673c2ad3d7e63ad05a /dom/script
parent702ad218b0279227000a5ca4e729260ba29bad6b (diff)
downloadUXP-767b637c838731f880adc92fb1e4b92bb5b591fd.tar
UXP-767b637c838731f880adc92fb1e4b92bb5b591fd.tar.gz
UXP-767b637c838731f880adc92fb1e4b92bb5b591fd.tar.lz
UXP-767b637c838731f880adc92fb1e4b92bb5b591fd.tar.xz
UXP-767b637c838731f880adc92fb1e4b92bb5b591fd.zip
Issue #618 - Split handling of load errors out from OnStreamComplete.
Diffstat (limited to 'dom/script')
-rw-r--r--dom/script/ScriptLoader.cpp124
-rw-r--r--dom/script/ScriptLoader.h2
2 files changed, 67 insertions, 59 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
index f90381390..cd0db629f 100644
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -2292,65 +2292,7 @@ ScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
}
if (NS_FAILED(rv)) {
- /*
- * Handle script not loading error because source was a tracking URL.
- * We make a note of this script node by including it in a dedicated
- * array of blocked tracking nodes under its parent document.
- */
- if (rv == NS_ERROR_TRACKING_URI) {
- nsCOMPtr<nsIContent> cont = do_QueryInterface(request->mElement);
- mDocument->AddBlockedTrackingNode(cont);
- }
-
- if (request->mIsDefer) {
- MOZ_ASSERT_IF(request->IsModuleRequest(),
- request->AsModuleRequest()->IsTopLevel());
- if (request->isInList()) {
- RefPtr<ScriptLoadRequest> req = mDeferRequests.Steal(request);
- FireScriptAvailable(rv, req);
- }
- } else if (request->mIsAsync) {
- MOZ_ASSERT_IF(request->IsModuleRequest(),
- request->AsModuleRequest()->IsTopLevel());
- if (request->isInList()) {
- RefPtr<ScriptLoadRequest> req = mLoadingAsyncRequests.Steal(request);
- FireScriptAvailable(rv, req);
- }
- } else if (request->mIsNonAsyncScriptInserted) {
- if (request->isInList()) {
- RefPtr<ScriptLoadRequest> req =
- mNonAsyncExternalScriptInsertedRequests.Steal(request);
- FireScriptAvailable(rv, req);
- }
- } else if (request->mIsXSLT) {
- if (request->isInList()) {
- RefPtr<ScriptLoadRequest> req = mXSLTRequests.Steal(request);
- FireScriptAvailable(rv, req);
- }
- } else if (request->IsModuleRequest()) {
- ModuleLoadRequest* modReq = request->AsModuleRequest();
- MOZ_ASSERT(!modReq->IsTopLevel());
- MOZ_ASSERT(!modReq->isInList());
- modReq->Cancel();
- // A single error is fired for the top level module, so don't use
- // FireScriptAvailable here.
- } else if (mParserBlockingRequest == request) {
- MOZ_ASSERT(!request->isInList());
- mParserBlockingRequest = nullptr;
- UnblockParser(request);
-
- // Ensure that we treat request->mElement as our current parser-inserted
- // script while firing onerror on it.
- MOZ_ASSERT(request->mElement->GetParserCreated());
- nsCOMPtr<nsIScriptElement> oldParserInsertedScript =
- mCurrentParserInsertedScript;
- mCurrentParserInsertedScript = request->mElement;
- FireScriptAvailable(rv, request);
- ContinueParserAsync(request);
- mCurrentParserInsertedScript = oldParserInsertedScript;
- } else {
- mPreloads.RemoveElement(request, PreloadRequestComparator());
- }
+ HandleLoadError(request, rv);
}
// Process our request and/or any pending ones
@@ -2360,6 +2302,70 @@ ScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
}
void
+ScriptLoader::HandleLoadError(ScriptLoadRequest *aRequest, nsresult aResult) {
+ /*
+ * Handle script not loading error because source was a tracking URL.
+ * We make a note of this script node by including it in a dedicated
+ * array of blocked tracking nodes under its parent document.
+ */
+ if (aResult == NS_ERROR_TRACKING_URI) {
+ nsCOMPtr<nsIContent> cont = do_QueryInterface(aRequest->mElement);
+ mDocument->AddBlockedTrackingNode(cont);
+ }
+
+ if (aRequest->mIsDefer) {
+ MOZ_ASSERT_IF(aRequest->IsModuleRequest(),
+ aRequest->AsModuleRequest()->IsTopLevel());
+ if (aRequest->isInList()) {
+ RefPtr<ScriptLoadRequest> req = mDeferRequests.Steal(aRequest);
+ FireScriptAvailable(aResult, req);
+ }
+ } else if (aRequest->mIsAsync) {
+ MOZ_ASSERT_IF(aRequest->IsModuleRequest(),
+ aRequest->AsModuleRequest()->IsTopLevel());
+ if (aRequest->isInList()) {
+ RefPtr<ScriptLoadRequest> req = mLoadingAsyncRequests.Steal(aRequest);
+ FireScriptAvailable(aResult, req);
+ }
+ } else if (aRequest->mIsNonAsyncScriptInserted) {
+ if (aRequest->isInList()) {
+ RefPtr<ScriptLoadRequest> req =
+ mNonAsyncExternalScriptInsertedRequests.Steal(aRequest);
+ FireScriptAvailable(aResult, req);
+ }
+ } else if (aRequest->mIsXSLT) {
+ if (aRequest->isInList()) {
+ RefPtr<ScriptLoadRequest> req = mXSLTRequests.Steal(aRequest);
+ FireScriptAvailable(aResult, req);
+ }
+ } else if (aRequest->IsModuleRequest()) {
+ ModuleLoadRequest* modReq = aRequest->AsModuleRequest();
+ MOZ_ASSERT(!modReq->IsTopLevel());
+ MOZ_ASSERT(!modReq->isInList());
+ modReq->Cancel();
+ // A single error is fired for the top level module, so don't use
+ // FireScriptAvailable here.
+ } else if (mParserBlockingRequest == aRequest) {
+ MOZ_ASSERT(!aRequest->isInList());
+ mParserBlockingRequest = nullptr;
+ UnblockParser(aRequest);
+
+ // Ensure that we treat request->mElement as our current parser-inserted
+ // script while firing onerror on it.
+ MOZ_ASSERT(aRequest->mElement->GetParserCreated());
+ nsCOMPtr<nsIScriptElement> oldParserInsertedScript =
+ mCurrentParserInsertedScript;
+ mCurrentParserInsertedScript = aRequest->mElement;
+ FireScriptAvailable(aResult, aRequest);
+ ContinueParserAsync(aRequest);
+ mCurrentParserInsertedScript = oldParserInsertedScript;
+ } else {
+ mPreloads.RemoveElement(aRequest, PreloadRequestComparator());
+ }
+}
+
+
+void
ScriptLoader::UnblockParser(ScriptLoadRequest* aParserBlockingRequest)
{
aParserBlockingRequest->mElement->UnblockParser();
diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h
index 121636e91..ed57de7c8 100644
--- a/dom/script/ScriptLoader.h
+++ b/dom/script/ScriptLoader.h
@@ -407,6 +407,8 @@ public:
mozilla::Vector<char16_t> &aString,
mozilla::dom::SRICheckDataVerifier* aSRIDataVerifier);
+ void HandleLoadError(ScriptLoadRequest *aRequest, nsresult aResult);
+
/**
* Processes any pending requests that are ready for processing.
*/