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 void* key = const_cast<AstRawString*>(export_name); | 18 void* key = const_cast<AstRawString*>(export_name); |
19 | 19 |
20 ZoneAllocationPolicy allocator(zone); | 20 ZoneAllocationPolicy allocator(zone); |
21 | 21 |
22 if (exports_ == nullptr) { | 22 if (exports_ == nullptr) { |
23 exports_ = new (zone->New(sizeof(ZoneHashMap))) | 23 exports_ = new (zone->New(sizeof(ZoneHashMap))) ZoneHashMap( |
24 ZoneHashMap(ZoneHashMap::PointersMatch, | 24 AstRawString::Compare, ZoneHashMap::kDefaultHashMapCapacity, allocator); |
25 ZoneHashMap::kDefaultHashMapCapacity, allocator); | |
26 } | 25 } |
27 | 26 |
28 ZoneHashMap::Entry* p = | 27 ZoneHashMap::Entry* p = |
29 exports_->Lookup(key, export_name->hash(), !IsFrozen(), allocator); | 28 exports_->Lookup(key, export_name->hash(), !IsFrozen(), allocator); |
30 if (p == nullptr || p->value != nullptr) { | 29 if (p == nullptr || p->value != nullptr) { |
31 *ok = false; | 30 *ok = false; |
32 } | 31 } |
33 | 32 |
34 p->value = const_cast<AstRawString*>(local_name); | 33 p->value = const_cast<AstRawString*>(local_name); |
35 } | 34 } |
| 35 |
| 36 |
| 37 const AstRawString* ModuleDescriptor::LookupLocalExport( |
| 38 const AstRawString* export_name, Zone* zone) { |
| 39 if (exports_ == nullptr) return nullptr; |
| 40 ZoneAllocationPolicy allocator(zone); |
| 41 ZoneHashMap::Entry* entry = |
| 42 exports_->Lookup(const_cast<AstRawString*>(export_name), |
| 43 export_name->hash(), false, allocator); |
| 44 if (entry == nullptr) return nullptr; |
| 45 DCHECK_NOT_NULL(entry->value); |
| 46 return static_cast<const AstRawString*>(entry->value); |
| 47 } |
36 } | 48 } |
37 } // namespace v8::internal | 49 } // namespace v8::internal |
OLD | NEW |