| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_AST_SCOPEINFO_H_ | 5 #ifndef V8_AST_SCOPEINFO_H_ |
| 6 #define V8_AST_SCOPEINFO_H_ | 6 #define V8_AST_SCOPEINFO_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast/modules.h" | 9 #include "src/ast/modules.h" |
| 10 #include "src/ast/variables.h" | 10 #include "src/ast/variables.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 Key keys_[kLength]; | 103 Key keys_[kLength]; |
| 104 uint32_t values_[kLength]; | 104 uint32_t values_[kLength]; |
| 105 | 105 |
| 106 friend class Isolate; | 106 friend class Isolate; |
| 107 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); | 107 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 | 110 |
| 111 | |
| 112 | |
| 113 //--------------------------------------------------------------------------- | |
| 114 // Auxiliary class used for the description of module instances. | |
| 115 // Used by Runtime_DeclareModules. | |
| 116 | |
| 117 class ModuleInfo: public FixedArray { | |
| 118 public: | |
| 119 static ModuleInfo* cast(Object* description) { | |
| 120 return static_cast<ModuleInfo*>(FixedArray::cast(description)); | |
| 121 } | |
| 122 | |
| 123 static Handle<ModuleInfo> Create(Isolate* isolate, | |
| 124 ModuleDescriptor* descriptor, Scope* scope); | |
| 125 | |
| 126 // Index of module's context in host context. | |
| 127 int host_index() { return Smi::cast(get(HOST_OFFSET))->value(); } | |
| 128 | |
| 129 // Name, mode, and index of the i-th export, respectively. | |
| 130 // For value exports, the index is the slot of the value in the module | |
| 131 // context, for exported modules it is the slot index of the | |
| 132 // referred module's context in the host context. | |
| 133 // TODO(rossberg): This format cannot yet handle exports of modules declared | |
| 134 // in earlier scripts. | |
| 135 String* name(int i) { return String::cast(get(name_offset(i))); } | |
| 136 VariableMode mode(int i) { | |
| 137 return static_cast<VariableMode>(Smi::cast(get(mode_offset(i)))->value()); | |
| 138 } | |
| 139 int index(int i) { return Smi::cast(get(index_offset(i)))->value(); } | |
| 140 | |
| 141 int length() { return (FixedArray::length() - HEADER_SIZE) / ITEM_SIZE; } | |
| 142 | |
| 143 private: | |
| 144 // The internal format is: Index, (Name, VariableMode, Index)* | |
| 145 enum { | |
| 146 HOST_OFFSET, | |
| 147 NAME_OFFSET, | |
| 148 MODE_OFFSET, | |
| 149 INDEX_OFFSET, | |
| 150 HEADER_SIZE = NAME_OFFSET, | |
| 151 ITEM_SIZE = INDEX_OFFSET - NAME_OFFSET + 1 | |
| 152 }; | |
| 153 inline int name_offset(int i) { return NAME_OFFSET + i * ITEM_SIZE; } | |
| 154 inline int mode_offset(int i) { return MODE_OFFSET + i * ITEM_SIZE; } | |
| 155 inline int index_offset(int i) { return INDEX_OFFSET + i * ITEM_SIZE; } | |
| 156 | |
| 157 static Handle<ModuleInfo> Allocate(Isolate* isolate, int length) { | |
| 158 return Handle<ModuleInfo>::cast( | |
| 159 isolate->factory()->NewFixedArray(HEADER_SIZE + ITEM_SIZE * length)); | |
| 160 } | |
| 161 void set_host_index(int index) { set(HOST_OFFSET, Smi::FromInt(index)); } | |
| 162 void set_name(int i, String* name) { set(name_offset(i), name); } | |
| 163 void set_mode(int i, VariableMode mode) { | |
| 164 set(mode_offset(i), Smi::FromInt(mode)); | |
| 165 } | |
| 166 void set_index(int i, int index) { | |
| 167 set(index_offset(i), Smi::FromInt(index)); | |
| 168 } | |
| 169 }; | |
| 170 | |
| 171 | |
| 172 } // namespace internal | 111 } // namespace internal |
| 173 } // namespace v8 | 112 } // namespace v8 |
| 174 | 113 |
| 175 #endif // V8_AST_SCOPEINFO_H_ | 114 #endif // V8_AST_SCOPEINFO_H_ |
| OLD | NEW |