• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INL_H_
6 #define V8_OBJECTS_MODULE_INL_H_
7 
8 #include "src/objects/module.h"
9 
10 #include "src/objects-inl.h"  // Needed for write barriers
11 #include "src/objects/scope-info.h"
12 
13 // Has to be the last include (doesn't have include guards):
14 #include "src/objects/object-macros.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 CAST_ACCESSOR(Module)
ACCESSORS(Module,code,Object,kCodeOffset)20 ACCESSORS(Module, code, Object, kCodeOffset)
21 ACCESSORS(Module, exports, ObjectHashTable, kExportsOffset)
22 ACCESSORS(Module, regular_exports, FixedArray, kRegularExportsOffset)
23 ACCESSORS(Module, regular_imports, FixedArray, kRegularImportsOffset)
24 ACCESSORS(Module, module_namespace, HeapObject, kModuleNamespaceOffset)
25 ACCESSORS(Module, requested_modules, FixedArray, kRequestedModulesOffset)
26 ACCESSORS(Module, script, Script, kScriptOffset)
27 ACCESSORS(Module, exception, Object, kExceptionOffset)
28 ACCESSORS(Module, import_meta, Object, kImportMetaOffset)
29 SMI_ACCESSORS(Module, status, kStatusOffset)
30 SMI_ACCESSORS(Module, dfs_index, kDfsIndexOffset)
31 SMI_ACCESSORS(Module, dfs_ancestor_index, kDfsAncestorIndexOffset)
32 SMI_ACCESSORS(Module, hash, kHashOffset)
33 
34 ModuleInfo* Module::info() const {
35   return (status() >= kEvaluating)
36              ? ModuleInfo::cast(code())
37              : GetSharedFunctionInfo()->scope_info()->ModuleDescriptorInfo();
38 }
39 
40 CAST_ACCESSOR(JSModuleNamespace)
ACCESSORS(JSModuleNamespace,module,Module,kModuleOffset)41 ACCESSORS(JSModuleNamespace, module, Module, kModuleOffset)
42 
43 CAST_ACCESSOR(ModuleInfoEntry)
44 ACCESSORS(ModuleInfoEntry, export_name, Object, kExportNameOffset)
45 ACCESSORS(ModuleInfoEntry, local_name, Object, kLocalNameOffset)
46 ACCESSORS(ModuleInfoEntry, import_name, Object, kImportNameOffset)
47 SMI_ACCESSORS(ModuleInfoEntry, module_request, kModuleRequestOffset)
48 SMI_ACCESSORS(ModuleInfoEntry, cell_index, kCellIndexOffset)
49 SMI_ACCESSORS(ModuleInfoEntry, beg_pos, kBegPosOffset)
50 SMI_ACCESSORS(ModuleInfoEntry, end_pos, kEndPosOffset)
51 
52 CAST_ACCESSOR(ModuleInfo)
53 
54 FixedArray* ModuleInfo::module_requests() const {
55   return FixedArray::cast(get(kModuleRequestsIndex));
56 }
57 
special_exports()58 FixedArray* ModuleInfo::special_exports() const {
59   return FixedArray::cast(get(kSpecialExportsIndex));
60 }
61 
regular_exports()62 FixedArray* ModuleInfo::regular_exports() const {
63   return FixedArray::cast(get(kRegularExportsIndex));
64 }
65 
regular_imports()66 FixedArray* ModuleInfo::regular_imports() const {
67   return FixedArray::cast(get(kRegularImportsIndex));
68 }
69 
namespace_imports()70 FixedArray* ModuleInfo::namespace_imports() const {
71   return FixedArray::cast(get(kNamespaceImportsIndex));
72 }
73 
module_request_positions()74 FixedArray* ModuleInfo::module_request_positions() const {
75   return FixedArray::cast(get(kModuleRequestPositionsIndex));
76 }
77 
78 #ifdef DEBUG
Equals(ModuleInfo * other)79 bool ModuleInfo::Equals(ModuleInfo* other) const {
80   return regular_exports() == other->regular_exports() &&
81          regular_imports() == other->regular_imports() &&
82          special_exports() == other->special_exports() &&
83          namespace_imports() == other->namespace_imports() &&
84          module_requests() == other->module_requests() &&
85          module_request_positions() == other->module_request_positions();
86 }
87 #endif
88 
89 }  // namespace internal
90 }  // namespace v8
91 
92 #include "src/objects/object-macros-undef.h"
93 
94 #endif  // V8_OBJECTS_MODULE_INL_H_
95