2015-02-18 18:25:00 +00:00
|
|
|
// 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/modules.h"
|
|
|
|
|
|
|
|
#include "src/ast-value-factory.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2015-02-19 20:14:55 +00:00
|
|
|
void ModuleDescriptor::AddLocalExport(const AstRawString* export_name,
|
|
|
|
const AstRawString* local_name,
|
|
|
|
Zone* zone, bool* ok) {
|
2015-04-13 19:01:15 +00:00
|
|
|
DCHECK(!IsFrozen());
|
2015-02-19 20:14:55 +00:00
|
|
|
void* key = const_cast<AstRawString*>(export_name);
|
2015-02-18 18:25:00 +00:00
|
|
|
|
|
|
|
ZoneAllocationPolicy allocator(zone);
|
|
|
|
|
2015-02-19 20:14:55 +00:00
|
|
|
if (exports_ == nullptr) {
|
2015-04-09 19:38:24 +00:00
|
|
|
exports_ = new (zone->New(sizeof(ZoneHashMap)))
|
|
|
|
ZoneHashMap(ZoneHashMap::PointersMatch,
|
|
|
|
ZoneHashMap::kDefaultHashMapCapacity, allocator);
|
2015-02-18 18:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ZoneHashMap::Entry* p =
|
2015-04-13 19:01:15 +00:00
|
|
|
exports_->LookupOrInsert(key, export_name->hash(), allocator);
|
|
|
|
DCHECK_NOT_NULL(p);
|
|
|
|
if (p->value != nullptr) {
|
|
|
|
// Duplicate export.
|
2015-02-18 18:25:00 +00:00
|
|
|
*ok = false;
|
2015-04-13 19:01:15 +00:00
|
|
|
return;
|
2015-02-18 18:25:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-19 20:14:55 +00:00
|
|
|
p->value = const_cast<AstRawString*>(local_name);
|
2015-02-18 18:25:00 +00:00
|
|
|
}
|
2015-02-27 18:04:46 +00:00
|
|
|
|
|
|
|
|
2015-04-09 22:09:44 +00:00
|
|
|
void ModuleDescriptor::AddModuleRequest(const AstRawString* module_specifier,
|
|
|
|
Zone* zone) {
|
|
|
|
// TODO(adamk): Avoid this O(N) operation on each insert by storing
|
|
|
|
// a HashMap, or by de-duping after parsing.
|
|
|
|
if (requested_modules_.Contains(module_specifier)) return;
|
|
|
|
requested_modules_.Add(module_specifier, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-27 18:04:46 +00:00
|
|
|
const AstRawString* ModuleDescriptor::LookupLocalExport(
|
|
|
|
const AstRawString* export_name, Zone* zone) {
|
|
|
|
if (exports_ == nullptr) return nullptr;
|
2015-04-13 19:01:15 +00:00
|
|
|
ZoneHashMap::Entry* entry = exports_->Lookup(
|
|
|
|
const_cast<AstRawString*>(export_name), export_name->hash());
|
2015-02-27 18:04:46 +00:00
|
|
|
if (entry == nullptr) return nullptr;
|
|
|
|
DCHECK_NOT_NULL(entry->value);
|
|
|
|
return static_cast<const AstRawString*>(entry->value);
|
|
|
|
}
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|