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();
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 Add(const AstRawString* name, Zone* zone, bool* ok);
33 // Do not allow any further refinements, directly or through unification.
34 void Freeze() { frozen_ = true; }
37 void Allocate(int index) {
38 DCHECK(IsFrozen() && index_ == -1);
42 // ---------------------------------------------------------------------------
45 // Check whether this is closed (i.e. fully determined).
46 bool IsFrozen() { return frozen_; }
50 ZoneHashMap* exports = exports_;
51 return exports ? exports->occupancy() : 0;
54 // The context slot in the hosting script context pointing to this module.
60 // ---------------------------------------------------------------------------
64 // for (auto it = descriptor->iterator(); !it.done(); it.Advance()) {
69 bool done() const { return entry_ == NULL; }
70 const AstRawString* name() const {
72 return static_cast<const AstRawString*>(entry_->key);
74 void Advance() { entry_ = exports_->Next(entry_); }
77 friend class ModuleDescriptor;
78 explicit Iterator(const ZoneHashMap* exports)
79 : exports_(exports), entry_(exports ? exports->Start() : NULL) {}
81 const ZoneHashMap* exports_;
82 ZoneHashMap::Entry* entry_;
85 Iterator iterator() const { return Iterator(this->exports_); }
87 // ---------------------------------------------------------------------------
91 ZoneHashMap* exports_; // Module exports and their types (allocated lazily)
94 ModuleDescriptor() : frozen_(false), exports_(NULL), index_(-1) {}
97 } } // namespace v8::internal
99 #endif // V8_MODULES_H_