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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/modules.h" | 7 #include "src/modules.h" |
8 | 8 |
9 #include "src/ast-value-factory.h" | 9 #include "src/ast-value-factory.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 | 14 |
15 void ModuleDescriptor::AddLocalExport(const AstRawString* export_name, | 15 void ModuleDescriptor::AddLocalExport(const AstRawString* export_name, |
16 const AstRawString* local_name, | 16 const AstRawString* local_name, |
17 Zone* zone, bool* ok) { | 17 Zone* zone, bool* ok) { |
| 18 DCHECK(!IsFrozen()); |
18 void* key = const_cast<AstRawString*>(export_name); | 19 void* key = const_cast<AstRawString*>(export_name); |
19 | 20 |
20 ZoneAllocationPolicy allocator(zone); | 21 ZoneAllocationPolicy allocator(zone); |
21 | 22 |
22 if (exports_ == nullptr) { | 23 if (exports_ == nullptr) { |
23 exports_ = new (zone->New(sizeof(ZoneHashMap))) ZoneHashMap( | 24 exports_ = new (zone->New(sizeof(ZoneHashMap))) ZoneHashMap( |
24 AstRawString::Compare, ZoneHashMap::kDefaultHashMapCapacity, allocator); | 25 AstRawString::Compare, ZoneHashMap::kDefaultHashMapCapacity, allocator); |
25 } | 26 } |
26 | 27 |
27 ZoneHashMap::Entry* p = | 28 ZoneHashMap::Entry* p = |
28 exports_->Lookup(key, export_name->hash(), !IsFrozen(), allocator); | 29 exports_->LookupOrInsert(key, export_name->hash(), allocator); |
29 if (p == nullptr || p->value != nullptr) { | 30 DCHECK_NOT_NULL(p); |
| 31 if (p->value != nullptr) { |
| 32 // Duplicate export. |
30 *ok = false; | 33 *ok = false; |
| 34 return; |
31 } | 35 } |
32 | 36 |
33 p->value = const_cast<AstRawString*>(local_name); | 37 p->value = const_cast<AstRawString*>(local_name); |
34 } | 38 } |
35 | 39 |
36 | 40 |
37 const AstRawString* ModuleDescriptor::LookupLocalExport( | 41 const AstRawString* ModuleDescriptor::LookupLocalExport( |
38 const AstRawString* export_name, Zone* zone) { | 42 const AstRawString* export_name, Zone* zone) { |
39 if (exports_ == nullptr) return nullptr; | 43 if (exports_ == nullptr) return nullptr; |
40 ZoneAllocationPolicy allocator(zone); | 44 ZoneHashMap::Entry* entry = exports_->Lookup( |
41 ZoneHashMap::Entry* entry = | 45 const_cast<AstRawString*>(export_name), export_name->hash()); |
42 exports_->Lookup(const_cast<AstRawString*>(export_name), | |
43 export_name->hash(), false, allocator); | |
44 if (entry == nullptr) return nullptr; | 46 if (entry == nullptr) return nullptr; |
45 DCHECK_NOT_NULL(entry->value); | 47 DCHECK_NOT_NULL(entry->value); |
46 return static_cast<const AstRawString*>(entry->value); | 48 return static_cast<const AstRawString*>(entry->value); |
47 } | 49 } |
48 } | 50 } |
49 } // namespace v8::internal | 51 } // namespace v8::internal |
OLD | NEW |