Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 828fcd896a0607ecd52aacfa7f9a0e49080c15bd..92f24391f8d40d1d904df6eac2651b45ad9d4ec3 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -19707,22 +19707,25 @@ MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, |
return Handle<Cell>::cast(object); |
} |
- // Must be an indirect export of some sort, so we need to detect cycles. |
+ // Check for cycle before recursing. |
{ |
// Attempt insertion with a null string set. |
auto result = resolve_set->insert({module, nullptr}); |
UnorderedStringSet*& name_set = result.first->second; |
- bool did_insert = result.second; |
- if (did_insert) { |
+ if (result.second) { |
// |module| wasn't in the map previously, so allocate a new name set. |
Zone* zone = resolve_set->zone(); |
name_set = |
new (zone->New(sizeof(UnorderedStringSet))) UnorderedStringSet(zone); |
} else if (name_set->count(name)) { |
- // TODO(adamk): Throwing here is incorrect in the case of star exports. |
- THROW_NEW_ERROR( |
- isolate, |
- NewSyntaxError(MessageTemplate::kCyclicModuleDependency, name), Cell); |
+ // Cycle detected. |
+ if (must_resolve) { |
+ THROW_NEW_ERROR( |
+ isolate, |
+ NewSyntaxError(MessageTemplate::kCyclicModuleDependency, name), |
+ Cell); |
+ } |
+ return MaybeHandle<Cell>(); |
} |
name_set->insert(name); |
} |