зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1877792 - Part 10: Get the module type from the module request r=spidermonkey-reviewers,jonco
Differential Revision: https://phabricator.services.mozilla.com/D218557
This commit is contained in:
Родитель
3144c8595c
Коммит
daa92e2070
|
@ -147,10 +147,13 @@ JSObject* ModuleLoaderBase::HostResolveImportedModule(
|
|||
nsCOMPtr<nsIURI> uri = result.unwrap();
|
||||
MOZ_ASSERT(uri, "Failed to resolve previously-resolved module specifier");
|
||||
|
||||
// Let moduleType be the result of running the module type from module
|
||||
// request steps given moduleRequest.
|
||||
JS::ModuleType moduleType = JS::GetModuleRequestType(aCx, aModuleRequest);
|
||||
|
||||
// Let resolved module script be moduleMap[url]. (This entry must exist for
|
||||
// us to have gotten to this point.)
|
||||
ModuleScript* ms =
|
||||
loader->GetFetchedModule(ModuleMapKey(uri, ModuleType::JavaScript));
|
||||
ModuleScript* ms = loader->GetFetchedModule(ModuleMapKey(uri, moduleType));
|
||||
MOZ_ASSERT(ms, "Resolved module not found in module map");
|
||||
MOZ_ASSERT(!ms->HasParseError());
|
||||
MOZ_ASSERT(ms->ModuleRecord());
|
||||
|
@ -330,10 +333,14 @@ bool ModuleLoaderBase::HostImportModuleDynamically(
|
|||
return false;
|
||||
}
|
||||
|
||||
// Let moduleType be the result of running the module type from module
|
||||
// request steps given moduleRequest.
|
||||
JS::ModuleType moduleType = JS::GetModuleRequestType(aCx, aModuleRequest);
|
||||
|
||||
// Create a new top-level load request.
|
||||
nsCOMPtr<nsIURI> uri = result.unwrap();
|
||||
RefPtr<ModuleLoadRequest> request = loader->CreateDynamicImport(
|
||||
aCx, uri, JS::ModuleType::JavaScript, script, specifierString, aPromise);
|
||||
aCx, uri, moduleType, script, specifierString, aPromise);
|
||||
|
||||
if (!request) {
|
||||
// Throws TypeError if CreateDynamicImport returns nullptr.
|
||||
|
@ -852,8 +859,12 @@ nsresult ModuleLoaderBase::ResolveRequestedModules(
|
|||
|
||||
nsCOMPtr<nsIURI> uri = result.unwrap();
|
||||
if (aRequestedModulesOut) {
|
||||
aRequestedModulesOut->AppendElement(
|
||||
ModuleMapKey(uri, JS::ModuleType::JavaScript));
|
||||
// Let moduleType be the result of running the module type from module
|
||||
// request steps given moduleRequest.
|
||||
JS::ModuleType moduleType =
|
||||
JS::GetRequestedModuleType(cx, moduleRecord, i);
|
||||
|
||||
aRequestedModulesOut->AppendElement(ModuleMapKey(uri, moduleType));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1040,8 +1051,8 @@ void ModuleLoaderBase::FinishDynamicImport(
|
|||
JS::Rooted<JSString*> specifier(aCx, aRequest->mDynamicSpecifier);
|
||||
JS::Rooted<JSObject*> promise(aCx, aRequest->mDynamicPromise);
|
||||
|
||||
JS::Rooted<JSObject*> moduleRequest(aCx,
|
||||
JS::CreateModuleRequest(aCx, specifier));
|
||||
JS::Rooted<JSObject*> moduleRequest(
|
||||
aCx, JS::CreateModuleRequest(aCx, specifier, aRequest->mModuleType));
|
||||
|
||||
JS::FinishDynamicModuleImport(aCx, aEvaluationPromise, referencingScript,
|
||||
moduleRequest, promise);
|
||||
|
|
|
@ -284,16 +284,28 @@ extern JS_PUBLIC_API void GetRequestedModuleSourcePos(
|
|||
JSContext* cx, Handle<JSObject*> moduleRecord, uint32_t index,
|
||||
uint32_t* lineNumber, JS::ColumnNumberOneOrigin* columnNumber);
|
||||
|
||||
/*
|
||||
* Get the module type of a requested module.
|
||||
*/
|
||||
extern JS_PUBLIC_API ModuleType GetRequestedModuleType(
|
||||
JSContext* cx, Handle<JSObject*> moduleRecord, uint32_t index);
|
||||
|
||||
/*
|
||||
* Get the top-level script for a module which has not yet been executed.
|
||||
*/
|
||||
extern JS_PUBLIC_API JSScript* GetModuleScript(Handle<JSObject*> moduleRecord);
|
||||
|
||||
extern JS_PUBLIC_API JSObject* CreateModuleRequest(
|
||||
JSContext* cx, Handle<JSString*> specifierArg);
|
||||
JSContext* cx, Handle<JSString*> specifierArg, ModuleType moduleType);
|
||||
extern JS_PUBLIC_API JSString* GetModuleRequestSpecifier(
|
||||
JSContext* cx, Handle<JSObject*> moduleRequestArg);
|
||||
|
||||
/*
|
||||
* Get the module type of the specified module request.
|
||||
*/
|
||||
extern JS_PUBLIC_API ModuleType
|
||||
GetModuleRequestType(JSContext* cx, Handle<JSObject*> moduleRequestArg);
|
||||
|
||||
/*
|
||||
* Get the module record for a module script.
|
||||
*/
|
||||
|
|
|
@ -285,6 +285,16 @@ JS_PUBLIC_API void JS::GetRequestedModuleSourcePos(
|
|||
*columnNumber = module.requestedModules()[index].columnNumber();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API JS::ModuleType JS::GetRequestedModuleType(
|
||||
JSContext* cx, Handle<JSObject*> moduleRecord, uint32_t index) {
|
||||
AssertHeapIsIdle();
|
||||
CHECK_THREAD(cx);
|
||||
cx->check(moduleRecord);
|
||||
|
||||
auto& module = moduleRecord->as<ModuleObject>();
|
||||
return module.requestedModules()[index].moduleRequest()->moduleType();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API JSScript* JS::GetModuleScript(JS::HandleObject moduleRecord) {
|
||||
AssertHeapIsIdle();
|
||||
|
||||
|
@ -328,8 +338,9 @@ JS_PUBLIC_API JSObject* JS::GetModuleEnvironment(JSContext* cx,
|
|||
return moduleObj->as<ModuleObject>().environment();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API JSObject* JS::CreateModuleRequest(
|
||||
JSContext* cx, Handle<JSString*> specifierArg) {
|
||||
JS_PUBLIC_API JSObject* JS::CreateModuleRequest(JSContext* cx,
|
||||
Handle<JSString*> specifierArg,
|
||||
JS::ModuleType moduleType) {
|
||||
AssertHeapIsIdle();
|
||||
CHECK_THREAD(cx);
|
||||
|
||||
|
@ -338,9 +349,7 @@ JS_PUBLIC_API JSObject* JS::CreateModuleRequest(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Rooted<ImportAttributeVector> attributes(cx);
|
||||
|
||||
return ModuleRequestObject::create(cx, specifierAtom, attributes);
|
||||
return ModuleRequestObject::create(cx, specifierAtom, moduleType);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API JSString* JS::GetModuleRequestSpecifier(
|
||||
|
@ -352,6 +361,15 @@ JS_PUBLIC_API JSString* JS::GetModuleRequestSpecifier(
|
|||
return moduleRequestArg->as<ModuleRequestObject>().specifier();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API JS::ModuleType JS::GetModuleRequestType(
|
||||
JSContext* cx, Handle<JSObject*> moduleRequestArg) {
|
||||
AssertHeapIsIdle();
|
||||
CHECK_THREAD(cx);
|
||||
cx->check(moduleRequestArg);
|
||||
|
||||
return moduleRequestArg->as<ModuleRequestObject>().moduleType();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API void JS::ClearModuleEnvironment(JSObject* moduleObj) {
|
||||
MOZ_ASSERT(moduleObj);
|
||||
AssertHeapIsIdle();
|
||||
|
|
Загрузка…
Ссылка в новой задаче