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
3 // found in the LICENSE file.
7 #include "src/modules.h"
9 #include "src/ast-value-factory.h"
15 void ModuleDescriptor::AddLocalExport(const AstRawString* export_name,
16 const AstRawString* local_name,
17 Zone* zone, bool* ok) {
18 void* key = const_cast<AstRawString*>(export_name);
20 ZoneAllocationPolicy allocator(zone);
22 if (exports_ == nullptr) {
23 exports_ = new (zone->New(sizeof(ZoneHashMap))) ZoneHashMap(
24 AstRawString::Compare, ZoneHashMap::kDefaultHashMapCapacity, allocator);
27 ZoneHashMap::Entry* p =
28 exports_->Lookup(key, export_name->hash(), !IsFrozen(), allocator);
29 if (p == nullptr || p->value != nullptr) {
33 p->value = const_cast<AstRawString*>(local_name);
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);
49 } // namespace v8::internal