summaryrefslogtreecommitdiff
path: root/deps/v8/src/modules.cc
blob: eb01cf08e49bc9e6714f5a3ce725fce108f8d3f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/v8.h"

#include "src/modules.h"

#include "src/ast-value-factory.h"

namespace v8 {
namespace internal {

// ---------------------------------------------------------------------------
// Addition.

void ModuleDescriptor::Add(const AstRawString* name, Zone* zone, bool* ok) {
  void* key = const_cast<AstRawString*>(name);

  ZoneHashMap** map = &exports_;
  ZoneAllocationPolicy allocator(zone);

  if (*map == nullptr) {
    *map = new (zone->New(sizeof(ZoneHashMap)))
        ZoneHashMap(ZoneHashMap::PointersMatch,
                    ZoneHashMap::kDefaultHashMapCapacity, allocator);
  }

  ZoneHashMap::Entry* p =
      (*map)->Lookup(key, name->hash(), !IsFrozen(), allocator);
  if (p == nullptr || p->value != nullptr) {
    *ok = false;
  }

  p->value = key;
}
}
}  // namespace v8::internal