Bug 1761432 - Part 2: Split out script load request state for when we require loading from source r=smaug

This is used when we explicitly don't want to load cached bytecode. It is
better served by a separate flag in the request than a state.

Differential Revision: https://phabricator.services.mozilla.com/D142042
This commit is contained in:
Jon Coppeard 2022-03-25 10:54:16 +00:00
Родитель 880347ab90
Коммит 0d945e360c
4 изменённых файлов: 11 добавлений и 17 удалений

Просмотреть файл

@ -294,7 +294,7 @@ nsresult ScriptLoadHandler::EnsureKnownDataType(
MOZ_ASSERT(req, "StreamLoader's request went away prematurely");
NS_ENSURE_SUCCESS(rv, rv);
if (mRequest->IsLoadingSource()) {
if (mRequest->mFetchSourceOnly) {
mRequest->SetTextSource();
TRACE_FOR_TEST(mRequest->mLoadContext->GetScriptElement(),
"scriptloader_load_source");

Просмотреть файл

@ -255,6 +255,8 @@ ScriptLoader::~ScriptLoader() {
static void CollectScriptTelemetry(ScriptLoadRequest* aRequest) {
using namespace mozilla::Telemetry;
MOZ_ASSERT(aRequest->IsLoading());
// Skip this function if we are not running telemetry.
if (!CanRecordExtended()) {
return;
@ -270,14 +272,13 @@ static void CollectScriptTelemetry(ScriptLoadRequest* aRequest) {
// Report the type of source. This is used to monitor the status of the
// JavaScript Start-up Bytecode Cache, with the expectation of an almost zero
// source-fallback and alternate-data being roughtly equal to source loads.
if (aRequest->IsLoadingSource()) {
if (aRequest->mFetchSourceOnly) {
if (aRequest->GetLoadContext()->mIsInline) {
AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::Inline);
} else if (aRequest->IsTextSource()) {
AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::SourceFallback);
}
} else {
MOZ_ASSERT(aRequest->IsLoading());
if (aRequest->IsTextSource()) {
AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::Source);
} else if (aRequest->IsBytecode()) {
@ -486,7 +487,7 @@ nsresult ScriptLoader::RestartLoad(ScriptLoadRequest* aRequest) {
// Start a new channel from which we explicitly request to stream the source
// instead of the bytecode.
aRequest->mState = ScriptLoadRequest::State::FetchingSource;
aRequest->mFetchSourceOnly = true;
nsresult rv;
if (aRequest->IsModuleRequest()) {
rv = mModuleLoader->RestartModuleLoad(aRequest);
@ -596,7 +597,7 @@ nsresult ScriptLoader::StartLoadInternal(ScriptLoadRequest* aRequest,
if (cic && StaticPrefs::dom_script_loader_bytecode_cache_enabled()) {
MOZ_ASSERT(!aRequest->GetLoadContext()->GetWebExtGlobal(),
"Can not bytecode cache WebExt code");
if (!aRequest->IsLoadingSource()) {
if (!aRequest->mFetchSourceOnly) {
// Inform the HTTP cache that we prefer to have information coming from
// the bytecode cache instead of the sources, if such entry is already
// registered.
@ -1078,7 +1079,7 @@ bool ScriptLoader::ProcessInlineScript(nsIScriptElement* aElement,
referrerPolicy);
request->GetLoadContext()->mIsInline = true;
request->GetLoadContext()->mLineNo = aElement->GetScriptLineNumber();
request->mState = ScriptLoadRequest::State::FetchingSource;
request->mFetchSourceOnly = true;
request->SetTextSource();
TRACE_FOR_TEST_BOOL(request->GetLoadContext()->GetScriptElement(),
"scriptloader_load_source");

Просмотреть файл

@ -84,6 +84,7 @@ ScriptLoadRequest::ScriptLoadRequest(ScriptKind aKind, nsIURI* aURI,
: mKind(aKind),
mIsCanceled(false),
mState(State::Fetching),
mFetchSourceOnly(false),
mDataType(DataType::eUnknown),
mFetchOptions(aFetchOptions),
mIntegrity(aIntegrity),

Просмотреть файл

@ -184,20 +184,11 @@ class ScriptLoadRequest
virtual void SetReady();
enum class State : uint8_t {
Fetching, // Request either source or bytecode
FetchingSource, // Explicitly request source stream
Compiling,
LoadingImports,
Ready
};
enum class State : uint8_t { Fetching, Compiling, LoadingImports, Ready };
bool IsReadyToRun() const { return mState == State::Ready; }
bool IsLoading() const {
return mState == State::Fetching || mState == State::FetchingSource;
}
bool IsLoadingSource() const { return mState == State::FetchingSource; }
bool IsLoading() const { return mState == State::Fetching; }
bool InCompilingStage() const { return mState == State::Compiling; }
@ -297,6 +288,7 @@ class ScriptLoadRequest
bool mIsCanceled; // True if we have been explicitly canceled.
State mState; // Are we still waiting for a load to complete?
bool mFetchSourceOnly; // Request source, not cached bytecode.
DataType mDataType; // Does this contain Source or Bytecode?
RefPtr<ScriptFetchOptions> mFetchOptions;
const SRIMetadata mIntegrity;