Home | History | Annotate | Download | only in objects
      1 // Copyright 2017 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 #ifndef V8_OBJECTS_MODULE_INFO_H_
      6 #define V8_OBJECTS_MODULE_INFO_H_
      7 
      8 #include "src/objects.h"
      9 
     10 // Has to be the last include (doesn't have include guards):
     11 #include "src/objects/object-macros.h"
     12 
     13 namespace v8 {
     14 namespace internal {
     15 
     16 template <typename T>
     17 class Handle;
     18 class Isolate;
     19 class ModuleDescriptor;
     20 class ModuleInfoEntry;
     21 class String;
     22 class Zone;
     23 
     24 // ModuleInfo is to ModuleDescriptor what ScopeInfo is to Scope.
     25 class ModuleInfo : public FixedArray {
     26  public:
     27   DECLARE_CAST(ModuleInfo)
     28 
     29   static Handle<ModuleInfo> New(Isolate* isolate, Zone* zone,
     30                                 ModuleDescriptor* descr);
     31 
     32   inline FixedArray* module_requests() const {
     33     return FixedArray::cast(get(kModuleRequestsIndex));
     34   }
     35 
     36   inline FixedArray* special_exports() const {
     37     return FixedArray::cast(get(kSpecialExportsIndex));
     38   }
     39 
     40   inline FixedArray* regular_exports() const {
     41     return FixedArray::cast(get(kRegularExportsIndex));
     42   }
     43 
     44   inline FixedArray* regular_imports() const {
     45     return FixedArray::cast(get(kRegularImportsIndex));
     46   }
     47 
     48   inline FixedArray* namespace_imports() const {
     49     return FixedArray::cast(get(kNamespaceImportsIndex));
     50   }
     51 
     52   // Accessors for [regular_exports].
     53   int RegularExportCount() const;
     54   String* RegularExportLocalName(int i) const;
     55   int RegularExportCellIndex(int i) const;
     56   FixedArray* RegularExportExportNames(int i) const;
     57 
     58   static Handle<ModuleInfoEntry> LookupRegularImport(Handle<ModuleInfo> info,
     59                                                      Handle<String> local_name);
     60 
     61 #ifdef DEBUG
     62   inline bool Equals(ModuleInfo* other) const {
     63     return regular_exports() == other->regular_exports() &&
     64            regular_imports() == other->regular_imports() &&
     65            special_exports() == other->special_exports() &&
     66            namespace_imports() == other->namespace_imports();
     67   }
     68 #endif
     69 
     70  private:
     71   friend class Factory;
     72   friend class ModuleDescriptor;
     73   enum {
     74     kModuleRequestsIndex,
     75     kSpecialExportsIndex,
     76     kRegularExportsIndex,
     77     kNamespaceImportsIndex,
     78     kRegularImportsIndex,
     79     kLength
     80   };
     81   enum {
     82     kRegularExportLocalNameOffset,
     83     kRegularExportCellIndexOffset,
     84     kRegularExportExportNamesOffset,
     85     kRegularExportLength
     86   };
     87   DISALLOW_IMPLICIT_CONSTRUCTORS(ModuleInfo);
     88 };
     89 
     90 class ModuleInfoEntry : public Struct {
     91  public:
     92   DECLARE_CAST(ModuleInfoEntry)
     93   DECLARE_PRINTER(ModuleInfoEntry)
     94   DECLARE_VERIFIER(ModuleInfoEntry)
     95 
     96   DECL_ACCESSORS(export_name, Object)
     97   DECL_ACCESSORS(local_name, Object)
     98   DECL_ACCESSORS(import_name, Object)
     99   DECL_INT_ACCESSORS(module_request)
    100   DECL_INT_ACCESSORS(cell_index)
    101   DECL_INT_ACCESSORS(beg_pos)
    102   DECL_INT_ACCESSORS(end_pos)
    103 
    104   static Handle<ModuleInfoEntry> New(Isolate* isolate,
    105                                      Handle<Object> export_name,
    106                                      Handle<Object> local_name,
    107                                      Handle<Object> import_name,
    108                                      int module_request, int cell_index,
    109                                      int beg_pos, int end_pos);
    110 
    111   static const int kExportNameOffset = HeapObject::kHeaderSize;
    112   static const int kLocalNameOffset = kExportNameOffset + kPointerSize;
    113   static const int kImportNameOffset = kLocalNameOffset + kPointerSize;
    114   static const int kModuleRequestOffset = kImportNameOffset + kPointerSize;
    115   static const int kCellIndexOffset = kModuleRequestOffset + kPointerSize;
    116   static const int kBegPosOffset = kCellIndexOffset + kPointerSize;
    117   static const int kEndPosOffset = kBegPosOffset + kPointerSize;
    118   static const int kSize = kEndPosOffset + kPointerSize;
    119 
    120  private:
    121   DISALLOW_IMPLICIT_CONSTRUCTORS(ModuleInfoEntry);
    122 };
    123 
    124 }  // namespace internal
    125 }  // namespace v8
    126 
    127 #include "src/objects/object-macros-undef.h"
    128 
    129 #endif  // V8_OBJECTS_MODULE_INFO_H_
    130