Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: src/ast/modules.cc

Issue 2340953002: Reland of "[modules] Make duplicate export error deterministic." (Closed)
Patch Set: The bug fix. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/modules.h ('k') | test/message/export-duplicate.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/modules.cc
diff --git a/src/ast/modules.cc b/src/ast/modules.cc
index 6d8f35f39048057944beb600d472ec64e296053f..70772997b5890cc5ed0c961fe41d35e7f6086019 100644
--- a/src/ast/modules.cc
+++ b/src/ast/modules.cc
@@ -134,19 +134,40 @@ void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) {
}
}
+namespace {
+
+const ModuleDescriptor::Entry* BetterDuplicate(
+ const ModuleDescriptor::Entry* candidate,
+ ZoneMap<const AstRawString*, const ModuleDescriptor::Entry*>& export_names,
+ const ModuleDescriptor::Entry* current_duplicate) {
+ DCHECK_NOT_NULL(candidate->export_name);
+ DCHECK(candidate->location.IsValid());
+ auto insert_result =
+ export_names.insert(std::make_pair(candidate->export_name, candidate));
+ if (insert_result.second) return current_duplicate;
+ if (current_duplicate == nullptr) {
+ current_duplicate = insert_result.first->second;
+ }
+ return (candidate->location.beg_pos > current_duplicate->location.beg_pos)
+ ? candidate
+ : current_duplicate;
+}
+
+} // namespace
+
const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport(
Zone* zone) const {
- ZoneSet<const AstRawString*> export_names(zone);
+ const ModuleDescriptor::Entry* duplicate = nullptr;
+ ZoneMap<const AstRawString*, const ModuleDescriptor::Entry*> export_names(
+ zone);
for (const auto& it : regular_exports_) {
- const Entry* entry = it.second;
- DCHECK_NOT_NULL(entry->export_name);
- if (!export_names.insert(entry->export_name).second) return entry;
+ duplicate = BetterDuplicate(it.second, export_names, duplicate);
}
for (auto entry : special_exports_) {
if (entry->export_name == nullptr) continue; // Star export.
- if (!export_names.insert(entry->export_name).second) return entry;
+ duplicate = BetterDuplicate(entry, export_names, duplicate);
}
- return nullptr;
+ return duplicate;
}
bool ModuleDescriptor::Validate(ModuleScope* module_scope,
« no previous file with comments | « src/ast/modules.h ('k') | test/message/export-duplicate.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698