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 8001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8012 }; | 8012 }; |
8013 | 8013 |
8014 // A Module object is a mapping from export names to cells | 8014 // A Module object is a mapping from export names to cells |
8015 // This is still very much in flux. | 8015 // This is still very much in flux. |
8016 class Module : public Struct { | 8016 class Module : public Struct { |
8017 public: | 8017 public: |
8018 DECLARE_CAST(Module) | 8018 DECLARE_CAST(Module) |
8019 DECLARE_VERIFIER(Module) | 8019 DECLARE_VERIFIER(Module) |
8020 DECLARE_PRINTER(Module) | 8020 DECLARE_PRINTER(Module) |
8021 | 8021 |
8022 // The code representing this Module, either a SharedFunctionInfo or a | 8022 // The code representing this Module, or an abstraction thereof. |
8023 // JSFunction depending on whether it's been instantiated. | 8023 // This is either a SharedFunctionInfo or a JSFunction or a ModuleInfo |
| 8024 // depending on whether the module has been instantiated and evaluated. See |
| 8025 // Module::ModuleVerify() for the precise invariant. |
8024 DECL_ACCESSORS(code, Object) | 8026 DECL_ACCESSORS(code, Object) |
8025 | 8027 |
| 8028 // The export table. |
8026 DECL_ACCESSORS(exports, ObjectHashTable) | 8029 DECL_ACCESSORS(exports, ObjectHashTable) |
8027 | 8030 |
| 8031 // Hash for this object (a random non-zero Smi). |
| 8032 DECL_INT_ACCESSORS(hash) |
| 8033 |
8028 // The namespace object (or undefined). | 8034 // The namespace object (or undefined). |
8029 DECL_ACCESSORS(module_namespace, HeapObject) | 8035 DECL_ACCESSORS(module_namespace, HeapObject) |
8030 | 8036 |
8031 // [[RequestedModules]]: Modules imported or re-exported by this module. | 8037 // Modules imported or re-exported by this module. |
8032 // Corresponds 1-to-1 to the module specifier strings in | 8038 // Corresponds 1-to-1 to the module specifier strings in |
8033 // ModuleInfo::module_requests. | 8039 // ModuleInfo::module_requests. |
8034 DECL_ACCESSORS(requested_modules, FixedArray) | 8040 DECL_ACCESSORS(requested_modules, FixedArray) |
8035 | 8041 |
8036 // [[Evaluated]]: Whether this module has been evaluated. Modules | |
8037 // are only evaluated a single time. | |
8038 DECL_BOOLEAN_ACCESSORS(evaluated) | |
8039 | |
8040 // Storage for [[Evaluated]]. | |
8041 DECL_INT_ACCESSORS(flags) | |
8042 | |
8043 // Hash for this object (a random non-zero Smi). | |
8044 DECL_INT_ACCESSORS(hash) | |
8045 | |
8046 // Get the SharedFunctionInfo associated with the code. | |
8047 inline SharedFunctionInfo* shared() const; | |
8048 | |
8049 // Get the ModuleInfo associated with the code. | 8042 // Get the ModuleInfo associated with the code. |
8050 inline ModuleInfo* info() const; | 8043 inline ModuleInfo* info() const; |
8051 | 8044 |
| 8045 inline bool instantiated() const; |
| 8046 inline bool evaluated() const; |
| 8047 inline void set_evaluated(); |
| 8048 |
8052 // Implementation of spec operation ModuleDeclarationInstantiation. | 8049 // Implementation of spec operation ModuleDeclarationInstantiation. |
8053 // Returns false if an exception occurred during instantiation, true | 8050 // Returns false if an exception occurred during instantiation, true |
8054 // otherwise. | 8051 // otherwise. |
8055 static MUST_USE_RESULT bool Instantiate(Handle<Module> module, | 8052 static MUST_USE_RESULT bool Instantiate(Handle<Module> module, |
8056 v8::Local<v8::Context> context, | 8053 v8::Local<v8::Context> context, |
8057 v8::Module::ResolveCallback callback); | 8054 v8::Module::ResolveCallback callback); |
8058 | 8055 |
8059 // Implementation of spec operation ModuleEvaluation. | 8056 // Implementation of spec operation ModuleEvaluation. |
8060 static MUST_USE_RESULT MaybeHandle<Object> Evaluate(Handle<Module> module); | 8057 static MUST_USE_RESULT MaybeHandle<Object> Evaluate(Handle<Module> module); |
8061 | 8058 |
8062 static Handle<Object> LoadExport(Handle<Module> module, Handle<String> name); | 8059 static Handle<Object> LoadExport(Handle<Module> module, Handle<String> name); |
8063 static void StoreExport(Handle<Module> module, Handle<String> name, | 8060 static void StoreExport(Handle<Module> module, Handle<String> name, |
8064 Handle<Object> value); | 8061 Handle<Object> value); |
8065 | 8062 |
8066 static Handle<Object> LoadImport(Handle<Module> module, Handle<String> name, | 8063 static Handle<Object> LoadImport(Handle<Module> module, Handle<String> name, |
8067 int module_request); | 8064 int module_request); |
8068 | 8065 |
8069 // Get the namespace object for [module_request] of [module]. If it doesn't | 8066 // Get the namespace object for [module_request] of [module]. If it doesn't |
8070 // exist yet, it is created. | 8067 // exist yet, it is created. |
8071 static Handle<JSModuleNamespace> GetModuleNamespace(Handle<Module> module, | 8068 static Handle<JSModuleNamespace> GetModuleNamespace(Handle<Module> module, |
8072 int module_request); | 8069 int module_request); |
8073 | 8070 |
8074 static const int kCodeOffset = HeapObject::kHeaderSize; | 8071 static const int kCodeOffset = HeapObject::kHeaderSize; |
8075 static const int kExportsOffset = kCodeOffset + kPointerSize; | 8072 static const int kExportsOffset = kCodeOffset + kPointerSize; |
8076 static const int kRequestedModulesOffset = kExportsOffset + kPointerSize; | 8073 static const int kHashOffset = kExportsOffset + kPointerSize; |
8077 static const int kFlagsOffset = kRequestedModulesOffset + kPointerSize; | 8074 static const int kModuleNamespaceOffset = kHashOffset + kPointerSize; |
8078 static const int kEmbedderDataOffset = kFlagsOffset + kPointerSize; | 8075 static const int kRequestedModulesOffset = |
8079 static const int kModuleNamespaceOffset = kEmbedderDataOffset + kPointerSize; | 8076 kModuleNamespaceOffset + kPointerSize; |
8080 static const int kHashOffset = kModuleNamespaceOffset + kPointerSize; | 8077 static const int kSize = kRequestedModulesOffset + kPointerSize; |
8081 static const int kSize = kHashOffset + kPointerSize; | |
8082 | 8078 |
8083 private: | 8079 private: |
8084 enum { kEvaluatedBit }; | 8080 enum { kEvaluatedBit }; |
8085 | 8081 |
8086 static void CreateExport(Handle<Module> module, Handle<FixedArray> names); | 8082 static void CreateExport(Handle<Module> module, Handle<FixedArray> names); |
8087 static void CreateIndirectExport(Handle<Module> module, Handle<String> name, | 8083 static void CreateIndirectExport(Handle<Module> module, Handle<String> name, |
8088 Handle<ModuleInfoEntry> entry); | 8084 Handle<ModuleInfoEntry> entry); |
8089 | 8085 |
8090 // Get the namespace object for [module]. If it doesn't exist yet, it is | 8086 // Get the namespace object for [module]. If it doesn't exist yet, it is |
8091 // created. | 8087 // created. |
(...skipping 3515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11607 } | 11603 } |
11608 return value; | 11604 return value; |
11609 } | 11605 } |
11610 }; | 11606 }; |
11611 | 11607 |
11612 | 11608 |
11613 } // NOLINT, false-positive due to second-order macros. | 11609 } // NOLINT, false-positive due to second-order macros. |
11614 } // NOLINT, false-positive due to second-order macros. | 11610 } // NOLINT, false-positive due to second-order macros. |
11615 | 11611 |
11616 #endif // V8_OBJECTS_H_ | 11612 #endif // V8_OBJECTS_H_ |
OLD | NEW |