OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 8161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8172 DECLARE_CAST(Module) | 8172 DECLARE_CAST(Module) |
8173 DECLARE_VERIFIER(Module) | 8173 DECLARE_VERIFIER(Module) |
8174 DECLARE_PRINTER(Module) | 8174 DECLARE_PRINTER(Module) |
8175 | 8175 |
8176 // The code representing this Module, or an abstraction thereof. | 8176 // The code representing this Module, or an abstraction thereof. |
8177 // This is either a SharedFunctionInfo or a JSFunction or a ModuleInfo | 8177 // This is either a SharedFunctionInfo or a JSFunction or a ModuleInfo |
8178 // depending on whether the module has been instantiated and evaluated. See | 8178 // depending on whether the module has been instantiated and evaluated. See |
8179 // Module::ModuleVerify() for the precise invariant. | 8179 // Module::ModuleVerify() for the precise invariant. |
8180 DECL_ACCESSORS(code, Object) | 8180 DECL_ACCESSORS(code, Object) |
8181 | 8181 |
8182 // The export table. | 8182 // Arrays of cells corresponding to regular exports and regular imports. |
| 8183 // A cell's position in the array is determined by the cell index of the |
| 8184 // associated module entry (which coincides with the variable index of the |
| 8185 // associated variable). |
| 8186 DECL_ACCESSORS(regular_exports, FixedArray) |
| 8187 DECL_ACCESSORS(regular_imports, FixedArray) |
| 8188 |
| 8189 // The complete export table, mapping an export name to its cell. |
| 8190 // TODO(neis): We may want to remove the regular exports from the table. |
8183 DECL_ACCESSORS(exports, ObjectHashTable) | 8191 DECL_ACCESSORS(exports, ObjectHashTable) |
8184 | 8192 |
8185 // Hash for this object (a random non-zero Smi). | 8193 // Hash for this object (a random non-zero Smi). |
8186 DECL_INT_ACCESSORS(hash) | 8194 DECL_INT_ACCESSORS(hash) |
8187 | 8195 |
8188 // The namespace object (or undefined). | 8196 // The namespace object (or undefined). |
8189 DECL_ACCESSORS(module_namespace, HeapObject) | 8197 DECL_ACCESSORS(module_namespace, HeapObject) |
8190 | 8198 |
8191 // Modules imported or re-exported by this module. | 8199 // Modules imported or re-exported by this module. |
8192 // Corresponds 1-to-1 to the module specifier strings in | 8200 // Corresponds 1-to-1 to the module specifier strings in |
(...skipping 10 matching lines...) Expand all Loading... |
8203 // Implementation of spec operation ModuleDeclarationInstantiation. | 8211 // Implementation of spec operation ModuleDeclarationInstantiation. |
8204 // Returns false if an exception occurred during instantiation, true | 8212 // Returns false if an exception occurred during instantiation, true |
8205 // otherwise. | 8213 // otherwise. |
8206 static MUST_USE_RESULT bool Instantiate(Handle<Module> module, | 8214 static MUST_USE_RESULT bool Instantiate(Handle<Module> module, |
8207 v8::Local<v8::Context> context, | 8215 v8::Local<v8::Context> context, |
8208 v8::Module::ResolveCallback callback); | 8216 v8::Module::ResolveCallback callback); |
8209 | 8217 |
8210 // Implementation of spec operation ModuleEvaluation. | 8218 // Implementation of spec operation ModuleEvaluation. |
8211 static MUST_USE_RESULT MaybeHandle<Object> Evaluate(Handle<Module> module); | 8219 static MUST_USE_RESULT MaybeHandle<Object> Evaluate(Handle<Module> module); |
8212 | 8220 |
8213 static Handle<Object> LoadExport(Handle<Module> module, Handle<String> name); | 8221 static Handle<Object> LoadVariable(Handle<Module> module, int cell_index); |
8214 static void StoreExport(Handle<Module> module, Handle<String> name, | 8222 static void StoreVariable(Handle<Module> module, int cell_index, |
8215 Handle<Object> value); | 8223 Handle<Object> value); |
8216 | |
8217 static Handle<Object> LoadImport(Handle<Module> module, Handle<String> name, | |
8218 int module_request); | |
8219 | 8224 |
8220 // Get the namespace object for [module_request] of [module]. If it doesn't | 8225 // Get the namespace object for [module_request] of [module]. If it doesn't |
8221 // exist yet, it is created. | 8226 // exist yet, it is created. |
8222 static Handle<JSModuleNamespace> GetModuleNamespace(Handle<Module> module, | 8227 static Handle<JSModuleNamespace> GetModuleNamespace(Handle<Module> module, |
8223 int module_request); | 8228 int module_request); |
8224 | 8229 |
8225 static const int kCodeOffset = HeapObject::kHeaderSize; | 8230 static const int kCodeOffset = HeapObject::kHeaderSize; |
8226 static const int kExportsOffset = kCodeOffset + kPointerSize; | 8231 static const int kExportsOffset = kCodeOffset + kPointerSize; |
8227 static const int kHashOffset = kExportsOffset + kPointerSize; | 8232 static const int kRegularExportsOffset = kExportsOffset + kPointerSize; |
| 8233 static const int kRegularImportsOffset = kRegularExportsOffset + kPointerSize; |
| 8234 static const int kHashOffset = kRegularImportsOffset + kPointerSize; |
8228 static const int kModuleNamespaceOffset = kHashOffset + kPointerSize; | 8235 static const int kModuleNamespaceOffset = kHashOffset + kPointerSize; |
8229 static const int kRequestedModulesOffset = | 8236 static const int kRequestedModulesOffset = |
8230 kModuleNamespaceOffset + kPointerSize; | 8237 kModuleNamespaceOffset + kPointerSize; |
8231 static const int kSize = kRequestedModulesOffset + kPointerSize; | 8238 static const int kSize = kRequestedModulesOffset + kPointerSize; |
8232 | 8239 |
8233 private: | 8240 private: |
8234 enum { kEvaluatedBit }; | 8241 enum { kEvaluatedBit }; |
8235 | 8242 |
8236 static void CreateExport(Handle<Module> module, Handle<FixedArray> names); | 8243 static void CreateExport(Handle<Module> module, int cell_index, |
| 8244 Handle<FixedArray> names); |
8237 static void CreateIndirectExport(Handle<Module> module, Handle<String> name, | 8245 static void CreateIndirectExport(Handle<Module> module, Handle<String> name, |
8238 Handle<ModuleInfoEntry> entry); | 8246 Handle<ModuleInfoEntry> entry); |
8239 | 8247 |
8240 // Get the namespace object for [module]. If it doesn't exist yet, it is | 8248 // Get the namespace object for [module]. If it doesn't exist yet, it is |
8241 // created. | 8249 // created. |
8242 static Handle<JSModuleNamespace> GetModuleNamespace(Handle<Module> module); | 8250 static Handle<JSModuleNamespace> GetModuleNamespace(Handle<Module> module); |
8243 | 8251 |
8244 // The [must_resolve] argument indicates whether or not an exception should be | 8252 // The [must_resolve] argument indicates whether or not an exception should be |
8245 // thrown in case the module does not provide an export named [name] | 8253 // thrown in case the module does not provide an export named [name] |
8246 // (including when a cycle is detected). An exception is always thrown in the | 8254 // (including when a cycle is detected). An exception is always thrown in the |
(...skipping 3550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11797 } | 11805 } |
11798 return value; | 11806 return value; |
11799 } | 11807 } |
11800 }; | 11808 }; |
11801 | 11809 |
11802 | 11810 |
11803 } // NOLINT, false-positive due to second-order macros. | 11811 } // NOLINT, false-positive due to second-order macros. |
11804 } // NOLINT, false-positive due to second-order macros. | 11812 } // NOLINT, false-positive due to second-order macros. |
11805 | 11813 |
11806 #endif // V8_OBJECTS_H_ | 11814 #endif // V8_OBJECTS_H_ |
OLD | NEW |