Bug 1877792 - Part 14: Return early in ModuleLoaderBase::ResolveRequestedModules for synthetic modules r=spidermonkey-reviewers,jonco

Synthetic modules do not have any dependencies, so calling
`GetRequestedModulesCount` results in cash. This patch fixes this by making
`ResolveRequestedModules` return early for synthetic modules.

Differential Revision: https://phabricator.services.mozilla.com/D218561
This commit is contained in:
Jonatan Klemets 2024-09-03 08:10:53 +00:00
parent 8abf56a6f1
commit e31a8b4afd

View File

@ -816,6 +816,8 @@ ResolveResult ModuleLoaderBase::ResolveModuleSpecifier(
nsresult ModuleLoaderBase::ResolveRequestedModules(
ModuleLoadRequest* aRequest, nsTArray<ModuleMapKey>* aRequestedModulesOut) {
MOZ_ASSERT_IF(aRequestedModulesOut, aRequestedModulesOut->IsEmpty());
ModuleScript* ms = aRequest->mModuleScript;
AutoJSAPI jsapi;
@ -825,6 +827,11 @@ nsresult ModuleLoaderBase::ResolveRequestedModules(
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> moduleRecord(cx, ms->ModuleRecord());
if (!JS::IsCyclicModule(moduleRecord)) {
return NS_OK;
}
uint32_t length = JS::GetRequestedModulesCount(cx, moduleRecord);
for (uint32_t i = 0; i < length; i++) {