зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1877792 - Part 9: Add module type to ModuleLoaderBase::{CreateStaticImport,CreateDynamicImport} r=spidermonkey-reviewers,dom-worker-reviewers,dom-core,asuth,jonco,mccr8
This patch adds a module type parameter to `ModuleLoaderBase::{CreateStaticImport,CreateDynamicImport},` and gets rid of a bunch of hard-coded `JS::ModuleType::JavaScript.` However, the module type is still hard-coded when we call `CreateDynamicImport` and `CreateStaticImport`. Differential Revision: https://phabricator.services.mozilla.com/D218556
This commit is contained in:
Родитель
db231924a1
Коммит
90ce482d33
|
@ -297,7 +297,7 @@ already_AddRefed<ModuleLoadRequest> ModuleLoader::CreateTopLevel(
|
|||
}
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> ModuleLoader::CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) {
|
||||
nsIURI* aURI, JS::ModuleType aModuleType, ModuleLoadRequest* aParent) {
|
||||
RefPtr<ScriptLoadContext> newContext = new ScriptLoadContext();
|
||||
newContext->mIsInline = false;
|
||||
// Propagated Parent values. TODO: allow child modules to use root module's
|
||||
|
@ -305,10 +305,9 @@ already_AddRefed<ModuleLoadRequest> ModuleLoader::CreateStaticImport(
|
|||
newContext->mScriptMode = aParent->GetScriptLoadContext()->mScriptMode;
|
||||
|
||||
RefPtr<ModuleLoadRequest> request = new ModuleLoadRequest(
|
||||
aURI, JS::ModuleType::JavaScript, aParent->ReferrerPolicy(),
|
||||
aParent->mFetchOptions, SRIMetadata(), aParent->mURI, newContext,
|
||||
false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
aURI, aModuleType, aParent->ReferrerPolicy(), aParent->mFetchOptions,
|
||||
SRIMetadata(), aParent->mURI, newContext, false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
aParent->mLoader, aParent->mVisitedSet, aParent->GetRootModule());
|
||||
|
||||
request->NoCacheEntryFound();
|
||||
|
@ -316,8 +315,9 @@ already_AddRefed<ModuleLoadRequest> ModuleLoader::CreateStaticImport(
|
|||
}
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> ModuleLoader::CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier, JS::Handle<JSObject*> aPromise) {
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) {
|
||||
MOZ_ASSERT(aSpecifier);
|
||||
MOZ_ASSERT(aPromise);
|
||||
|
||||
|
@ -365,12 +365,11 @@ already_AddRefed<ModuleLoadRequest> ModuleLoader::CreateDynamicImport(
|
|||
context->mScriptMode = ScriptLoadContext::ScriptMode::eAsync;
|
||||
|
||||
RefPtr<VisitedURLSet> visitedSet =
|
||||
ModuleLoadRequest::NewVisitedSetForTopLevelImport(
|
||||
aURI, JS::ModuleType::JavaScript);
|
||||
ModuleLoadRequest::NewVisitedSetForTopLevelImport(aURI, aModuleType);
|
||||
|
||||
RefPtr<ModuleLoadRequest> request =
|
||||
new ModuleLoadRequest(aURI, JS::ModuleType::JavaScript, referrerPolicy,
|
||||
options, SRIMetadata(), baseURL, context, true,
|
||||
new ModuleLoadRequest(aURI, aModuleType, referrerPolicy, options,
|
||||
SRIMetadata(), baseURL, context, true,
|
||||
/* is top level */ true, /* is dynamic import */
|
||||
this, visitedSet, nullptr);
|
||||
|
||||
|
|
|
@ -67,12 +67,13 @@ class ModuleLoader final : public JS::loader::ModuleLoaderBase {
|
|||
|
||||
// Create a module load request for a static module import.
|
||||
already_AddRefed<ModuleLoadRequest> CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) override;
|
||||
nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
ModuleLoadRequest* aParent) override;
|
||||
|
||||
// Create a module load request for a dynamic module import.
|
||||
already_AddRefed<ModuleLoadRequest> CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier,
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) override;
|
||||
|
||||
static ModuleLoader* From(ModuleLoaderBase* aLoader) {
|
||||
|
|
|
@ -40,7 +40,7 @@ nsIURI* WorkerModuleLoader::GetBaseURI() const {
|
|||
}
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> WorkerModuleLoader::CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) {
|
||||
nsIURI* aURI, JS::ModuleType aModuleType, ModuleLoadRequest* aParent) {
|
||||
// We are intentionally deviating from the specification here and using the
|
||||
// worker's CSP rather than the document CSP. The spec otherwise requires our
|
||||
// service worker integration to be changed, and additionally the decision
|
||||
|
@ -54,10 +54,9 @@ already_AddRefed<ModuleLoadRequest> WorkerModuleLoader::CreateStaticImport(
|
|||
aParent->GetWorkerLoadContext()->mScriptLoader,
|
||||
aParent->GetWorkerLoadContext()->mOnlyExistingCachedResourcesAllowed);
|
||||
RefPtr<ModuleLoadRequest> request = new ModuleLoadRequest(
|
||||
aURI, JS::ModuleType::JavaScript, aParent->ReferrerPolicy(),
|
||||
aParent->mFetchOptions, SRIMetadata(), aParent->mURI, loadContext,
|
||||
false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
aURI, aModuleType, aParent->ReferrerPolicy(), aParent->mFetchOptions,
|
||||
SRIMetadata(), aParent->mURI, loadContext, false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
this, aParent->mVisitedSet, aParent->GetRootModule());
|
||||
|
||||
request->mURL = request->mURI->GetSpecOrDefault();
|
||||
|
@ -82,8 +81,9 @@ bool WorkerModuleLoader::CreateDynamicImportLoader() {
|
|||
}
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> WorkerModuleLoader::CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier, JS::Handle<JSObject*> aPromise) {
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) {
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
|
||||
if (!CreateDynamicImportLoader()) {
|
||||
|
@ -137,13 +137,12 @@ already_AddRefed<ModuleLoadRequest> WorkerModuleLoader::CreateDynamicImport(
|
|||
true);
|
||||
|
||||
RefPtr<JS::loader::VisitedURLSet> visitedSet =
|
||||
ModuleLoadRequest::NewVisitedSetForTopLevelImport(
|
||||
aURI, JS::ModuleType::JavaScript);
|
||||
ModuleLoadRequest::NewVisitedSetForTopLevelImport(aURI, aModuleType);
|
||||
|
||||
ReferrerPolicy referrerPolicy = workerPrivate->GetReferrerPolicy();
|
||||
RefPtr<ModuleLoadRequest> request =
|
||||
new ModuleLoadRequest(aURI, JS::ModuleType::JavaScript, referrerPolicy,
|
||||
options, SRIMetadata(), baseURL, context, true,
|
||||
new ModuleLoadRequest(aURI, aModuleType, referrerPolicy, options,
|
||||
SRIMetadata(), baseURL, context, true,
|
||||
/* is top level */ true, /* is dynamic import */
|
||||
this, visitedSet, nullptr);
|
||||
|
||||
|
|
|
@ -56,11 +56,12 @@ class WorkerModuleLoader : public JS::loader::ModuleLoaderBase {
|
|||
nsIURI* GetBaseURI() const override;
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) override;
|
||||
nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
ModuleLoadRequest* aParent) override;
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier,
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) override;
|
||||
|
||||
bool IsDynamicImportSupported() override;
|
||||
|
|
|
@ -54,7 +54,7 @@ WorkletModuleLoader::WorkletModuleLoader(WorkletScriptLoader* aScriptLoader,
|
|||
}
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> WorkletModuleLoader::CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) {
|
||||
nsIURI* aURI, JS::ModuleType aModuleType, ModuleLoadRequest* aParent) {
|
||||
const nsMainThreadPtrHandle<WorkletFetchHandler>& handlerRef =
|
||||
aParent->GetWorkletLoadContext()->GetHandlerRef();
|
||||
RefPtr<WorkletLoadContext> loadContext = new WorkletLoadContext(handlerRef);
|
||||
|
@ -67,10 +67,9 @@ already_AddRefed<ModuleLoadRequest> WorkletModuleLoader::CreateStaticImport(
|
|||
// base URL,
|
||||
nsIURI* referrer = aParent->mURI;
|
||||
RefPtr<ModuleLoadRequest> request = new ModuleLoadRequest(
|
||||
aURI, JS::ModuleType::JavaScript, aParent->ReferrerPolicy(),
|
||||
aParent->mFetchOptions, SRIMetadata(), referrer, loadContext,
|
||||
false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
aURI, aModuleType, aParent->ReferrerPolicy(), aParent->mFetchOptions,
|
||||
SRIMetadata(), referrer, loadContext, false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
this, aParent->mVisitedSet, aParent->GetRootModule());
|
||||
|
||||
request->mURL = request->mURI->GetSpecOrDefault();
|
||||
|
@ -79,8 +78,9 @@ already_AddRefed<ModuleLoadRequest> WorkletModuleLoader::CreateStaticImport(
|
|||
}
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> WorkletModuleLoader::CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier, JS::Handle<JSObject*> aPromise) {
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,11 +64,12 @@ class WorkletModuleLoader : public JS::loader::ModuleLoaderBase {
|
|||
~WorkletModuleLoader() = default;
|
||||
|
||||
already_AddRefed<JS::loader::ModuleLoadRequest> CreateStaticImport(
|
||||
nsIURI* aURI, JS::loader::ModuleLoadRequest* aParent) override;
|
||||
nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
JS::loader::ModuleLoadRequest* aParent) override;
|
||||
|
||||
already_AddRefed<JS::loader::ModuleLoadRequest> CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier,
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) override;
|
||||
|
||||
bool CanStartLoad(JS::loader::ModuleLoadRequest* aRequest,
|
||||
|
|
|
@ -332,8 +332,8 @@ bool ModuleLoaderBase::HostImportModuleDynamically(
|
|||
|
||||
// Create a new top-level load request.
|
||||
nsCOMPtr<nsIURI> uri = result.unwrap();
|
||||
RefPtr<ModuleLoadRequest> request =
|
||||
loader->CreateDynamicImport(aCx, uri, script, specifierString, aPromise);
|
||||
RefPtr<ModuleLoadRequest> request = loader->CreateDynamicImport(
|
||||
aCx, uri, JS::ModuleType::JavaScript, script, specifierString, aPromise);
|
||||
|
||||
if (!request) {
|
||||
// Throws TypeError if CreateDynamicImport returns nullptr.
|
||||
|
@ -917,8 +917,8 @@ void ModuleLoaderBase::StartFetchingModuleDependencies(
|
|||
|
||||
void ModuleLoaderBase::StartFetchingModuleAndDependencies(
|
||||
ModuleLoadRequest* aParent, const ModuleMapKey& aRequestedModule) {
|
||||
RefPtr<ModuleLoadRequest> childRequest =
|
||||
CreateStaticImport(aRequestedModule.mUri, aParent);
|
||||
RefPtr<ModuleLoadRequest> childRequest = CreateStaticImport(
|
||||
aRequestedModule.mUri, aRequestedModule.mModuleType, aParent);
|
||||
|
||||
aParent->mImports.AppendElement(childRequest);
|
||||
|
||||
|
|
|
@ -296,12 +296,13 @@ class ModuleLoaderBase : public nsISupports {
|
|||
private:
|
||||
// Create a module load request for a static module import.
|
||||
virtual already_AddRefed<ModuleLoadRequest> CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) = 0;
|
||||
nsIURI* aURI, JS::ModuleType aModuleType, ModuleLoadRequest* aParent) = 0;
|
||||
|
||||
// Called by HostImportModuleDynamically hook.
|
||||
virtual already_AddRefed<ModuleLoadRequest> CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier, JS::Handle<JSObject*> aPromise) = 0;
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) = 0;
|
||||
|
||||
virtual bool IsDynamicImportSupported() { return true; }
|
||||
|
||||
|
|
|
@ -60,27 +60,26 @@ SyncModuleLoader::SyncModuleLoader(SyncScriptLoader* aScriptLoader,
|
|||
SyncModuleLoader::~SyncModuleLoader() { MOZ_ASSERT(mLoadRequests.isEmpty()); }
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> SyncModuleLoader::CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) {
|
||||
nsIURI* aURI, JS::ModuleType aModuleType, ModuleLoadRequest* aParent) {
|
||||
RefPtr<SyncLoadContext> context = new SyncLoadContext();
|
||||
RefPtr<ModuleLoadRequest> request = new ModuleLoadRequest(
|
||||
aURI, JS::ModuleType::JavaScript, aParent->ReferrerPolicy(),
|
||||
aParent->mFetchOptions, dom::SRIMetadata(), aParent->mURI, context,
|
||||
false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
aURI, aModuleType, aParent->ReferrerPolicy(), aParent->mFetchOptions,
|
||||
dom::SRIMetadata(), aParent->mURI, context, false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
this, aParent->mVisitedSet, aParent->GetRootModule());
|
||||
request->NoCacheEntryFound();
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> SyncModuleLoader::CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier, JS::Handle<JSObject*> aPromise) {
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) {
|
||||
RefPtr<SyncLoadContext> context = new SyncLoadContext();
|
||||
RefPtr<VisitedURLSet> visitedSet =
|
||||
ModuleLoadRequest::NewVisitedSetForTopLevelImport(
|
||||
aURI, JS::ModuleType::JavaScript);
|
||||
ModuleLoadRequest::NewVisitedSetForTopLevelImport(aURI, aModuleType);
|
||||
RefPtr<ModuleLoadRequest> request = new ModuleLoadRequest(
|
||||
aURI, JS::ModuleType::JavaScript, aMaybeActiveScript->ReferrerPolicy(),
|
||||
aURI, aModuleType, aMaybeActiveScript->ReferrerPolicy(),
|
||||
aMaybeActiveScript->GetFetchOptions(), dom::SRIMetadata(),
|
||||
aMaybeActiveScript->BaseURL(), context,
|
||||
/* aIsTopLevel = */ true, /* aIsDynamicImport = */ true, this,
|
||||
|
|
|
@ -55,11 +55,12 @@ class SyncModuleLoader : public JS::loader::ModuleLoaderBase {
|
|||
~SyncModuleLoader();
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) override;
|
||||
nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
ModuleLoadRequest* aParent) override;
|
||||
|
||||
already_AddRefed<ModuleLoadRequest> CreateDynamicImport(
|
||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||
JS::Handle<JSString*> aSpecifier,
|
||||
JSContext* aCx, nsIURI* aURI, JS::ModuleType aModuleType,
|
||||
LoadedScript* aMaybeActiveScript, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) override;
|
||||
|
||||
void OnDynamicImportStarted(ModuleLoadRequest* aRequest) override;
|
||||
|
|
Загрузка…
Ссылка в новой задаче