Bug 1800641 - Part 11: Allocate script in ScriptLoadRequest::NoCacheEntryFound. r=nbp

Depends on D197848

Differential Revision: https://phabricator.services.mozilla.com/D197849
This commit is contained in:
Tooru Fujisawa 2024-01-08 14:57:40 +00:00
parent 17c5cde210
commit d8c07cffa3
6 changed files with 15 additions and 10 deletions

View File

@ -2761,7 +2761,6 @@ nsresult ScriptLoader::EvaluateScript(nsIGlobalObject* aGlobalObject,
aRequest->GetScriptLoadContext()->GetProfilerLabel(profilerLabelString);
// Create a ClassicScript object and associate it with the JSScript.
aRequest->EnsureScript();
MOZ_ASSERT(aRequest->mLoadedScript->IsClassicScript());
MOZ_ASSERT(aRequest->mLoadedScript->GetFetchOptions() ==
aRequest->mFetchOptions);

View File

@ -1250,7 +1250,6 @@ bool WorkerScriptLoader::EvaluateScript(JSContext* aCx,
} else {
requestBaseURI = aRequest->mBaseURL;
}
aRequest->EnsureScript();
MOZ_ASSERT(aRequest->mLoadedScript->IsClassicScript());
MOZ_ASSERT(aRequest->mLoadedScript->GetFetchOptions() ==
aRequest->mFetchOptions);

View File

@ -17,6 +17,8 @@ class nsIURI;
namespace JS::loader {
class ScriptLoadRequest;
void HostAddRefTopLevelScript(const JS::Value& aPrivate);
void HostReleaseTopLevelScript(const JS::Value& aPrivate);
@ -69,9 +71,12 @@ class LoadedScript : public nsISupports {
class ClassicScript final : public LoadedScript {
~ClassicScript() = default;
public:
private:
// Scripts can be created only by ScriptLoadRequest::NoCacheEntryFound.
ClassicScript(mozilla::dom::ReferrerPolicy aReferrerPolicy,
ScriptFetchOptions* aFetchOptions, nsIURI* aURI);
friend class ScriptLoadRequest;
};
class EventScript final : public LoadedScript {
@ -97,9 +102,14 @@ class ModuleScript final : public LoadedScript {
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ModuleScript,
LoadedScript)
private:
// Scripts can be created only by ScriptLoadRequest::NoCacheEntryFound.
ModuleScript(mozilla::dom::ReferrerPolicy aReferrerPolicy,
ScriptFetchOptions* aFetchOptions, nsIURI* aURI);
friend class ScriptLoadRequest;
public:
void SetModuleRecord(JS::Handle<JSObject*> aModuleRecord);
void SetParseError(const JS::Value& aError);
void SetErrorToRethrow(const JS::Value& aError);

View File

@ -638,7 +638,6 @@ nsresult ModuleLoaderBase::CreateModuleScript(ModuleLoadRequest* aRequest) {
}
}
aRequest->EnsureScript();
MOZ_ASSERT(aRequest->mLoadedScript->IsModuleScript());
MOZ_ASSERT(aRequest->mLoadedScript->GetFetchOptions() ==
aRequest->mFetchOptions);

View File

@ -162,10 +162,9 @@ const ModuleLoadRequest* ScriptLoadRequest::AsModuleRequest() const {
void ScriptLoadRequest::NoCacheEntryFound() {
MOZ_ASSERT(IsCheckingCache());
MOZ_ASSERT(mURI);
mState = State::Fetching;
}
void ScriptLoadRequest::EnsureScript() {
// At the time where we check in the cache, the mBaseURL is not set, as this
// is resolved by the network. Thus we use the mURI, for checking the cache
// and later replace the mBaseURL using what the Channel->GetURI will provide.
switch (mKind) {
case ScriptKind::eClassic:
case ScriptKind::eImportMap:
@ -178,6 +177,7 @@ void ScriptLoadRequest::EnsureScript() {
MOZ_ASSERT_UNREACHABLE("EventScripts are not using ScriptLoadRequest");
break;
}
mState = State::Fetching;
}
void ScriptLoadRequest::SetPendingFetchingError() {

View File

@ -258,8 +258,6 @@ class ScriptLoadRequest
void ClearScriptSource();
void EnsureScript();
// Convert a CheckingCache ScriptLoadRequest into a Fetching one, by creating
// a new LoadedScript which is matching the ScriptKind provided when
// constructing this ScriptLoadRequest.