Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Source/JavaScriptCore/runtime/JSModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,17 @@ void JSModuleLoader::finishLoadingImportedModule(JSGlobalObject* globalObject, c
auto scope = DECLARE_THROW_SCOPE(vm);

// 1. If result is a normal completion, then
#if USE(BUN_JSC_ADDITIONS)
// hostLoadImportedModule() relies on the realm's [[LoadedModules]] holding only what the registry holds. removeEntry()
// and clearAll() take a module out of both, and a load of it that was in flight then must not put it back into one.
auto isRegistered = [&](AbstractModuleRecord* record) {
ModuleRegistryEntry* entry = getRegisteredMayBeNull(record->moduleKey(), moduleRequest.type());
return entry && entry->record() == record;
};
if (auto* resultRecord = std::get_if<AbstractModuleRecord*>(&result); resultRecord && (!referrer.isRealm() || isRegistered(*resultRecord))) {
Comment thread
dylan-conway marked this conversation as resolved.
Comment thread
dylan-conway marked this conversation as resolved.
#else
if (auto* resultRecord = std::get_if<AbstractModuleRecord*>(&result)) {
#endif
JSCell* owner = nullptr;

auto& loadedModules = [&] -> ModuleMap<AbstractModuleRecord::LoadedModuleRequest> & {
Expand Down
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/runtime/JSModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ class JSModuleLoader final : public JSCell {
auto* impl = key.impl();
Locker locker { cellLock() }; // visitChildren iterates these
forgetPrelinkedRecordsWithKey(impl);
m_loadedModules.removeIf([&](auto& entry) { return entry.key.first == impl; });
// Keyed by the specifier that was asked for, which resolve() may have turned into another key.
m_loadedModules.removeIf([&](auto& entry) { return entry.key.first == impl || entry.value.m_module->moduleKey().impl() == impl; });
m_resolutionFailures.removeIf([&](auto& entry) { return entry.key.first == impl || entry.key.second == impl; });
return m_moduleMap.removeIf([&](auto& entry) {
if (entry.key.first != impl)
Expand Down
Loading