diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /dom/script/ScriptLoader.cpp | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/script/ScriptLoader.cpp')
-rw-r--r-- | dom/script/ScriptLoader.cpp | 140 |
1 files changed, 48 insertions, 92 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 43f718ab64..4fa08e074d 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -12,21 +12,16 @@ #include "mozilla/Assertions.h" #include "mozilla/dom/FetchPriority.h" +#include "mozilla/glean/GleanMetrics.h" #include "mozilla/dom/RequestBinding.h" -#include "nsIChildChannel.h" -#include "zlib.h" #include "prsystem.h" -#include "jsapi.h" -#include "jsfriendapi.h" -#include "js/Array.h" // JS::GetArrayLength #include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin #include "js/CompilationAndEvaluation.h" #include "js/CompileOptions.h" // JS::CompileOptions, JS::OwningCompileOptions, JS::DecodeOptions, JS::OwningDecodeOptions, JS::DelazificationOption #include "js/ContextOptions.h" // JS::ContextOptionsRef #include "js/experimental/JSStencil.h" // JS::Stencil, JS::InstantiationStorage #include "js/experimental/CompileScript.h" // JS::FrontendContext, JS::NewFrontendContext, JS::DestroyFrontendContext, JS::SetNativeStackQuota, JS::ThreadStackQuotaForSize, JS::CompilationStorage, JS::CompileGlobalScriptToStencil, JS::CompileModuleScriptToStencil, JS::DecodeStencil, JS::PrepareForInstantiate -#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_* #include "js/loader/ScriptLoadRequest.h" #include "ScriptCompression.h" #include "js/loader/LoadedScript.h" @@ -34,8 +29,6 @@ #include "js/MemoryFunctions.h" #include "js/Modules.h" #include "js/PropertyAndElement.h" // JS_DefineProperty -#include "js/Realm.h" -#include "js/SourceText.h" #include "js/Transcoding.h" // JS::TranscodeRange, JS::TranscodeResult, JS::IsTranscodeFailureResult #include "js/Utility.h" #include "xpcpublic.h" @@ -54,7 +47,6 @@ #include "mozilla/dom/WindowContext.h" #include "mozilla/Mutex.h" // mozilla::Mutex #include "mozilla/net/UrlClassifierFeatureFactory.h" -#include "mozilla/Preferences.h" #include "mozilla/StaticPrefs_dom.h" #include "mozilla/StaticPrefs_javascript.h" #include "mozilla/StaticPrefs_network.h" @@ -80,16 +72,12 @@ #include "nsUnicharUtils.h" #include "nsError.h" #include "nsThreadUtils.h" -#include "nsDocShellCID.h" #include "nsIContentSecurityPolicy.h" #include "mozilla/Logging.h" #include "nsCRT.h" #include "nsContentCreatorFunctions.h" #include "nsProxyRelease.h" -#include "nsSandboxFlags.h" -#include "nsContentTypeParser.h" #include "nsINetworkPredictor.h" -#include "nsMimeTypes.h" #include "mozilla/ConsoleReportCollector.h" #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/EventQueue.h" @@ -103,14 +91,12 @@ #include "mozilla/Telemetry.h" #include "mozilla/TimeStamp.h" #include "mozilla/UniquePtr.h" -#include "mozilla/Unused.h" #include "mozilla/Utf8.h" // mozilla::Utf8Unit #include "nsIScriptError.h" #include "nsIAsyncOutputStream.h" #include "js/loader/ModuleLoaderBase.h" #include "mozilla/Maybe.h" -using JS::SourceText; using namespace JS::loader; using mozilla::Telemetry::LABELS_DOM_SCRIPT_PRELOAD_RESULT; @@ -668,53 +654,35 @@ static void AdjustPriorityAndClassOfServiceForLinkPreloadScripts( nsIChannel* aChannel, ScriptLoadRequest* aRequest) { MOZ_ASSERT(aRequest->GetScriptLoadContext()->IsLinkPreloadScript()); + // Put it to the group that is not blocked by leaders and doesn't block + // follower at the same time. + // Giving it a much higher priority will make this request be processed + // ahead of other Unblocked requests, but with the same weight as + // Leaders. This will make us behave similar way for both http2 and http1. + ScriptLoadContext::PrioritizeAsPreload(aChannel); + if (!StaticPrefs::network_fetchpriority_enabled()) { - // Put it to the group that is not blocked by leaders and doesn't block - // follower at the same time. - // Giving it a much higher priority will make this request be processed - // ahead of other Unblocked requests, but with the same weight as - // Leaders. This will make us behave similar way for both http2 and http1. - ScriptLoadContext::PrioritizeAsPreload(aChannel); return; } - if (nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(aChannel)) { - cos->AddClassFlags(nsIClassOfService::Unblocked); - } - if (nsCOMPtr<nsISupportsPriority> supportsPriority = do_QueryInterface(aChannel)) { LOG(("Is <link rel=[module]preload")); - const RequestPriority fetchPriority = aRequest->FetchPriority(); + const auto fetchPriority = ToFetchPriority(aRequest->FetchPriority()); // The spec defines the priority to be set in an implementation defined // manner (<https://fetch.spec.whatwg.org/#concept-fetch>, step 15 and // <https://html.spec.whatwg.org/#concept-script-fetch-options-fetch-priority>). - // For web-compatibility, the fetch priority mapping from - // <https://web.dev/articles/fetch-priority#browser_priority_and_fetchpriority> - // is taken. - const int32_t supportsPriorityValue = [&]() { - switch (fetchPriority) { - case RequestPriority::Auto: { - return nsISupportsPriority::PRIORITY_HIGH; - } - case RequestPriority::High: { - return nsISupportsPriority::PRIORITY_HIGH; - } - case RequestPriority::Low: { - return nsISupportsPriority::PRIORITY_LOW; - } - default: { - MOZ_ASSERT_UNREACHABLE(); - return nsISupportsPriority::PRIORITY_NORMAL; - } - } - }(); - - LogPriorityMapping(ScriptLoader::gScriptLoaderLog, - ToFetchPriority(fetchPriority), supportsPriorityValue); - - supportsPriority->SetPriority(supportsPriorityValue); + // See corresponding preferences in StaticPrefList.yaml for more context. + const int32_t supportsPriorityDelta = + FETCH_PRIORITY_ADJUSTMENT_FOR(link_preload_script, fetchPriority); + supportsPriority->AdjustPriority(supportsPriorityDelta); +#ifdef DEBUG + int32_t adjustedPriority; + supportsPriority->GetPriority(&adjustedPriority); + LogPriorityMapping(ScriptLoader::gScriptLoaderLog, fetchPriority, + adjustedPriority); +#endif } } @@ -729,50 +697,40 @@ void AdjustPriorityForNonLinkPreloadScripts(nsIChannel* aChannel, if (nsCOMPtr<nsISupportsPriority> supportsPriority = do_QueryInterface(aChannel)) { LOG(("Is not <link rel=[module]preload")); - const RequestPriority fetchPriority = aRequest->FetchPriority(); + const auto fetchPriority = ToFetchPriority(aRequest->FetchPriority()); // The spec defines the priority to be set in an implementation defined // manner (<https://fetch.spec.whatwg.org/#concept-fetch>, step 15 and // <https://html.spec.whatwg.org/#concept-script-fetch-options-fetch-priority>). - // <testing/web-platform/mozilla/tests/fetch/fetchpriority/support/script-tests-data.js> - // provides more context for the priority mapping. - const int32_t supportsPriorityValue = [&]() { - switch (fetchPriority) { - case RequestPriority::Auto: { - if (aRequest->IsModuleRequest()) { - return nsISupportsPriority::PRIORITY_HIGH; - } - - const ScriptLoadContext* scriptLoadContext = - aRequest->GetScriptLoadContext(); - if (scriptLoadContext->IsAsyncScript() || - scriptLoadContext->IsDeferredScript()) { - return nsISupportsPriority::PRIORITY_LOW; - } - - if (scriptLoadContext->mScriptFromHead) { - return nsISupportsPriority::PRIORITY_HIGH; - } - - return nsISupportsPriority::PRIORITY_NORMAL; - } - case RequestPriority::Low: { - return nsISupportsPriority::PRIORITY_LOW; - } - case RequestPriority::High: { - return nsISupportsPriority::PRIORITY_HIGH; - } - default: { - MOZ_ASSERT_UNREACHABLE(); - return nsISupportsPriority::PRIORITY_NORMAL; - } + // See corresponding preferences in StaticPrefList.yaml for more context. + const int32_t supportsPriorityDelta = [&]() { + const ScriptLoadContext* scriptLoadContext = + aRequest->GetScriptLoadContext(); + if (aRequest->IsModuleRequest()) { + return FETCH_PRIORITY_ADJUSTMENT_FOR(module_script, fetchPriority); + } + + if (scriptLoadContext->IsAsyncScript() || + scriptLoadContext->IsDeferredScript()) { + return FETCH_PRIORITY_ADJUSTMENT_FOR(async_or_defer_script, + fetchPriority); + } + + if (scriptLoadContext->mScriptFromHead) { + return FETCH_PRIORITY_ADJUSTMENT_FOR(script_in_head, fetchPriority); } + + return FETCH_PRIORITY_ADJUSTMENT_FOR(other_script, fetchPriority); }(); - if (supportsPriorityValue) { - LogPriorityMapping(ScriptLoader::gScriptLoaderLog, - ToFetchPriority(fetchPriority), supportsPriorityValue); - supportsPriority->SetPriority(supportsPriorityValue); + if (supportsPriorityDelta) { + supportsPriority->AdjustPriority(supportsPriorityDelta); +#ifdef DEBUG + int32_t adjustedPriority; + supportsPriority->GetPriority(&adjustedPriority); + LogPriorityMapping(ScriptLoader::gScriptLoaderLog, fetchPriority, + adjustedPriority); +#endif } } } @@ -1933,14 +1891,13 @@ class ScriptOrModuleCompileTask final : public CompileOrDecodeTask { JS::SetNativeStackQuota(mFrontendContext, JS::ThreadStackQuotaForSize(stackSize)); - JS::CompilationStorage compileStorage; auto compile = [&](auto& source) { if constexpr (target == CompilationTarget::Script) { return JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions, - source, compileStorage); + source); } return JS::CompileModuleScriptToStencil(mFrontendContext, mOptions, - source, compileStorage); + source); }; return mMaybeSource.mapNonEmpty(compile); } @@ -2004,7 +1961,6 @@ class ScriptDecodeTask final : public CompileOrDecodeTask { already_AddRefed<JS::Stencil> Decode() { // NOTE: JS::DecodeStencil doesn't need the stack quota. - JS::CompilationStorage compileStorage; RefPtr<JS::Stencil> stencil; mResult = JS::DecodeStencil(mFrontendContext, mDecodeOptions, mRange, getter_AddRefs(stencil)); |