Bug 1800641 - Part 8: Add LoadContextBase* parameter to ScriptLoadRequest methods which is going to be moved to LoadedScriptDelegate. r=nbp

Depends on D197845

Differential Revision: https://phabricator.services.mozilla.com/D197846
This commit is contained in:
Tooru Fujisawa 2024-01-08 14:57:38 +00:00
parent f135bad3aa
commit 976c794ad0
12 changed files with 25 additions and 16 deletions

View File

@ -225,7 +225,8 @@ nsresult ModuleLoader::CompileFetchedModule(
RefPtr<JS::Stencil> stencil;
if (aRequest->IsTextSource()) {
MaybeSourceText maybeSource;
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource);
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource,
aRequest->mLoadContext.get());
NS_ENSURE_SUCCESS(rv, rv);
auto compile = [&](auto& source) {

View File

@ -321,7 +321,7 @@ nsresult ScriptLoadHandler::EnsureKnownDataType(
NS_ENSURE_SUCCESS(rv, rv);
if (mRequest->mFetchSourceOnly) {
mRequest->SetTextSource();
mRequest->SetTextSource(mRequest->mLoadContext.get());
TRACE_FOR_TEST(mRequest->GetScriptLoadContext()->GetScriptElement(),
"scriptloader_load_source");
return NS_OK;
@ -340,7 +340,7 @@ nsresult ScriptLoadHandler::EnsureKnownDataType(
MOZ_ASSERT(altDataType.IsEmpty());
}
mRequest->SetTextSource();
mRequest->SetTextSource(mRequest->mLoadContext.get());
TRACE_FOR_TEST(mRequest->GetScriptLoadContext()->GetScriptElement(),
"scriptloader_load_source");

View File

@ -1384,7 +1384,7 @@ bool ScriptLoader::ProcessInlineScript(nsIScriptElement* aElement,
request->GetScriptLoadContext()->mColumnNo =
aElement->GetScriptColumnNumber();
request->mFetchSourceOnly = true;
request->SetTextSource();
request->SetTextSource(request->mLoadContext.get());
TRACE_FOR_TEST_BOOL(request->GetScriptLoadContext()->GetScriptElement(),
"scriptloader_load_source");
CollectScriptTelemetry(request);
@ -2043,7 +2043,8 @@ nsresult ScriptLoader::CreateOffThreadTask(
}
MaybeSourceText maybeSource;
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource);
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource,
aRequest->mLoadContext.get());
NS_ENSURE_SUCCESS(rv, rv);
if (ShouldApplyDelazifyStrategy(aRequest)) {
@ -2646,7 +2647,8 @@ nsresult ScriptLoader::CompileOrDecodeClassicScript(
LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest));
MOZ_ASSERT(aRequest->IsTextSource());
MaybeSourceText maybeSource;
rv = aRequest->GetScriptSource(aCx, &maybeSource);
rv = aRequest->GetScriptSource(aCx, &maybeSource,
aRequest->mLoadContext.get());
if (NS_SUCCEEDED(rv)) {
AUTO_PROFILER_MARKER_TEXT("ScriptCompileMainThread", JS,
MarkerInnerWindowIdFromJSContext(aCx),

View File

@ -1225,7 +1225,8 @@ bool WorkerScriptLoader::EvaluateScript(JSContext* aCx,
// Get the source text.
ScriptLoadRequest::MaybeSourceText maybeSource;
rv = aRequest->GetScriptSource(aCx, &maybeSource);
rv = aRequest->GetScriptSource(aCx, &maybeSource,
aRequest->mLoadContext.get());
if (NS_FAILED(rv)) {
mRv.StealExceptionFromJSContext(aCx);
return false;

View File

@ -557,7 +557,7 @@ nsresult CacheLoadHandler::DataReceivedFromCache(
nsresult rv;
// Set the Source type to "text" for decoding.
loadContext->mRequest->SetTextSource();
loadContext->mRequest->SetTextSource(loadContext);
rv = mDecoder->DecodeRawData(loadContext->mRequest, aString, aStringLen,
/* aEndOfStream = */ true);

View File

@ -164,7 +164,7 @@ nsresult NetworkLoadHandler::DataReceivedFromNetwork(nsIStreamLoader* aLoader,
Document* parentDoc = mWorkerRef->Private()->GetDocument();
// Set the Source type to "text" for decoding.
loadContext->mRequest->SetTextSource();
loadContext->mRequest->SetTextSource(loadContext);
// Use the regular ScriptDecoder Decoder for this grunt work! Should be just
// fine because we're running on the main thread.

View File

@ -171,7 +171,8 @@ nsresult WorkerModuleLoader::CompileFetchedModule(
RefPtr<JS::Stencil> stencil;
MOZ_ASSERT(aRequest->IsTextSource());
MaybeSourceText maybeSource;
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource);
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource,
aRequest->mLoadContext.get());
NS_ENSURE_SUCCESS(rv, rv);
auto compile = [&](auto& source) {

View File

@ -209,7 +209,7 @@ NS_IMETHODIMP FetchCompleteRunnable::RunOnWorkletThread() {
MOZ_ASSERT(request);
// Set the Source type to "text" for decoding.
request->SetTextSource();
request->SetTextSource(request->mLoadContext.get());
nsresult rv;
if (mScriptBuffer) {

View File

@ -106,7 +106,8 @@ nsresult WorkletModuleLoader::CompileFetchedModule(
MOZ_ASSERT(aRequest->IsTextSource());
MaybeSourceText maybeSource;
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource);
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource,
aRequest->mLoadContext.get());
NS_ENSURE_SUCCESS(rv, rv);
auto compile = [&](auto& source) {

View File

@ -1301,7 +1301,8 @@ UniquePtr<ImportMap> ModuleLoaderBase::ParseImportMap(
MOZ_ASSERT(aRequest->IsTextSource());
MaybeSourceText maybeSource;
nsresult rv = aRequest->GetScriptSource(jsapi.cx(), &maybeSource);
nsresult rv = aRequest->GetScriptSource(jsapi.cx(), &maybeSource,
aRequest->mLoadContext.get());
if (NS_FAILED(rv)) {
return nullptr;
}

View File

@ -195,7 +195,8 @@ bool ScriptLoadRequest::IsMarkedForBytecodeEncoding() const {
}
nsresult ScriptLoadRequest::GetScriptSource(JSContext* aCx,
MaybeSourceText* aMaybeSource) {
MaybeSourceText* aMaybeSource,
LoadContextBase* aLoadContext) {
// If there's no script text, we try to get it from the element
if (HasScriptLoadContext() && GetScriptLoadContext()->mIsInline) {
nsAutoString inlineData;

View File

@ -180,7 +180,7 @@ class ScriptLoadRequest
mScriptData.reset();
}
void SetTextSource() {
void SetTextSource(LoadContextBase* aMaybeLoadContext) {
MOZ_ASSERT(IsUnknownDataType());
mDataType = DataType::eTextSource;
mScriptData.emplace(VariantType<ScriptTextBuffer<Utf8Unit>>());
@ -218,7 +218,8 @@ class ScriptLoadRequest
// Get source text. On success |aMaybeSource| will contain either UTF-8 or
// UTF-16 source; on failure it will remain in its initial state.
nsresult GetScriptSource(JSContext* aCx, MaybeSourceText* aMaybeSource);
nsresult GetScriptSource(JSContext* aCx, MaybeSourceText* aMaybeSource,
LoadContextBase* aLoadContext);
void ClearScriptText() {
MOZ_ASSERT(IsTextSource());