deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / modules.cc
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.
4
5 #include "src/v8.h"
6
7 #include "src/modules.h"
8
9 #include "src/ast-value-factory.h"
10
11 namespace v8 {
12 namespace internal {
13
14
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);
19
20   ZoneAllocationPolicy allocator(zone);
21
22   if (exports_ == nullptr) {
23     exports_ = new (zone->New(sizeof(ZoneHashMap))) ZoneHashMap(
24         AstRawString::Compare, ZoneHashMap::kDefaultHashMapCapacity, allocator);
25   }
26
27   ZoneHashMap::Entry* p =
28       exports_->Lookup(key, export_name->hash(), !IsFrozen(), allocator);
29   if (p == nullptr || p->value != nullptr) {
30     *ok = false;
31   }
32
33   p->value = const_cast<AstRawString*>(local_name);
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 }
48 }
49 }  // namespace v8::internal