OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ast/modules.h" | 5 #include "src/ast/modules.h" |
6 #include "src/ast/ast-value-factory.h" | 6 #include "src/ast/ast-value-factory.h" |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 entry->module_request = import->second->module_request; | 127 entry->module_request = import->second->module_request; |
128 entry->local_name = nullptr; | 128 entry->local_name = nullptr; |
129 special_exports_.Add(entry, zone); | 129 special_exports_.Add(entry, zone); |
130 it = regular_exports_.erase(it); | 130 it = regular_exports_.erase(it); |
131 } else { | 131 } else { |
132 it++; | 132 it++; |
133 } | 133 } |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
| 137 namespace { |
| 138 |
| 139 const ModuleDescriptor::Entry* BetterDuplicate( |
| 140 const ModuleDescriptor::Entry* candidate, |
| 141 ZoneMap<const AstRawString*, const ModuleDescriptor::Entry*>& export_names, |
| 142 const ModuleDescriptor::Entry* current_duplicate) { |
| 143 DCHECK_NOT_NULL(candidate->export_name); |
| 144 DCHECK(candidate->location.IsValid()); |
| 145 auto insert_result = |
| 146 export_names.insert(std::make_pair(candidate->export_name, candidate)); |
| 147 if (insert_result.second) return current_duplicate; |
| 148 if (current_duplicate == nullptr) { |
| 149 current_duplicate = insert_result.first->second; |
| 150 } |
| 151 return (candidate->location.beg_pos > current_duplicate->location.beg_pos) |
| 152 ? candidate |
| 153 : current_duplicate; |
| 154 } |
| 155 |
| 156 } // namespace |
| 157 |
137 const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport( | 158 const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport( |
138 Zone* zone) const { | 159 Zone* zone) const { |
139 ZoneSet<const AstRawString*> export_names(zone); | 160 const ModuleDescriptor::Entry* duplicate = nullptr; |
| 161 ZoneMap<const AstRawString*, const ModuleDescriptor::Entry*> export_names( |
| 162 zone); |
140 for (const auto& it : regular_exports_) { | 163 for (const auto& it : regular_exports_) { |
141 const Entry* entry = it.second; | 164 duplicate = BetterDuplicate(it.second, export_names, duplicate); |
142 DCHECK_NOT_NULL(entry->export_name); | |
143 if (!export_names.insert(entry->export_name).second) return entry; | |
144 } | 165 } |
145 for (auto entry : special_exports_) { | 166 for (auto entry : special_exports_) { |
146 if (entry->export_name == nullptr) continue; // Star export. | 167 if (entry->export_name == nullptr) continue; // Star export. |
147 if (!export_names.insert(entry->export_name).second) return entry; | 168 duplicate = BetterDuplicate(entry, export_names, duplicate); |
148 } | 169 } |
149 return nullptr; | 170 return duplicate; |
150 } | 171 } |
151 | 172 |
152 bool ModuleDescriptor::Validate(ModuleScope* module_scope, | 173 bool ModuleDescriptor::Validate(ModuleScope* module_scope, |
153 PendingCompilationErrorHandler* error_handler, | 174 PendingCompilationErrorHandler* error_handler, |
154 Zone* zone) { | 175 Zone* zone) { |
155 DCHECK_EQ(this, module_scope->module()); | 176 DCHECK_EQ(this, module_scope->module()); |
156 DCHECK_NOT_NULL(error_handler); | 177 DCHECK_NOT_NULL(error_handler); |
157 | 178 |
158 // Report error iff there are duplicate exports. | 179 // Report error iff there are duplicate exports. |
159 { | 180 { |
(...skipping 17 matching lines...) Expand all Loading... |
177 return false; | 198 return false; |
178 } | 199 } |
179 } | 200 } |
180 | 201 |
181 MakeIndirectExportsExplicit(zone); | 202 MakeIndirectExportsExplicit(zone); |
182 return true; | 203 return true; |
183 } | 204 } |
184 | 205 |
185 } // namespace internal | 206 } // namespace internal |
186 } // namespace v8 | 207 } // namespace v8 |
OLD | NEW |