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.
17 class ModuleDescriptor : public ZoneObject {
19 // ---------------------------------------------------------------------------
22 static ModuleDescriptor* New(Zone* zone) {
23 return new (zone) ModuleDescriptor(zone);
26 // ---------------------------------------------------------------------------
29 // Add a name to the list of exports. If it already exists, or this descriptor
30 // is frozen, that's an error.
31 void AddLocalExport(const AstRawString* export_name,
32 const AstRawString* local_name, Zone* zone, bool* ok);
34 // Add module_specifier to the list of requested modules,
35 // if not already present.
36 void AddModuleRequest(const AstRawString* module_specifier, Zone* zone);
38 // Do not allow any further refinements, directly or through unification.
39 void Freeze() { frozen_ = true; }
42 void Allocate(int index) {
43 DCHECK(IsFrozen() && index_ == -1);
47 // ---------------------------------------------------------------------------
50 // Check whether this is closed (i.e. fully determined).
51 bool IsFrozen() { return frozen_; }
55 ZoneHashMap* exports = exports_;
56 return exports ? exports->occupancy() : 0;
59 // The context slot in the hosting script context pointing to this module.
65 const AstRawString* LookupLocalExport(const AstRawString* export_name,
68 const ZoneList<const AstRawString*>& requested_modules() const {
69 return requested_modules_;
72 // ---------------------------------------------------------------------------
76 // for (auto it = descriptor->iterator(); !it.done(); it.Advance()) {
81 bool done() const { return entry_ == NULL; }
82 const AstRawString* export_name() const {
84 return static_cast<const AstRawString*>(entry_->key);
86 const AstRawString* local_name() const {
88 return static_cast<const AstRawString*>(entry_->value);
90 void Advance() { entry_ = exports_->Next(entry_); }
93 friend class ModuleDescriptor;
94 explicit Iterator(const ZoneHashMap* exports)
95 : exports_(exports), entry_(exports ? exports->Start() : NULL) {}
97 const ZoneHashMap* exports_;
98 ZoneHashMap::Entry* entry_;
101 Iterator iterator() const { return Iterator(this->exports_); }
103 // ---------------------------------------------------------------------------
106 explicit ModuleDescriptor(Zone* zone)
109 requested_modules_(1, zone),
113 ZoneHashMap* exports_; // Module exports and their types (allocated lazily)
114 ZoneList<const AstRawString*> requested_modules_;
118 } // namespace internal
121 #endif // V8_MODULES_H_