1 // Copyright 2019 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_SYNTHETIC_MODULE_H_ 6 #define V8_OBJECTS_SYNTHETIC_MODULE_H_ 7 8 #include "src/objects/module.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 #include "torque-generated/src/objects/synthetic-module-tq.inc" 17 18 // The runtime representation of a Synthetic Module Record, a module that can be 19 // instantiated by an embedder with embedder-defined exports and evaluation 20 // steps. 21 // https://heycam.github.io/webidl/#synthetic-module-records 22 class SyntheticModule 23 : public TorqueGeneratedSyntheticModule<SyntheticModule, Module> { 24 public: 25 NEVER_READ_ONLY_SPACE 26 DECL_VERIFIER(SyntheticModule) 27 28 // Set module's exported value for the specified export_name to the specified 29 // export_value. An error will be thrown if export_name is not one 30 // of the export_names that were supplied during module construction. 31 // Returns Just(true) on success, Nothing<bool>() if an error was thrown. 32 static Maybe<bool> SetExport(Isolate* isolate, Handle<SyntheticModule> module, 33 Handle<String> export_name, 34 Handle<Object> export_value); 35 // The following redundant method should be deleted when the deprecated 36 // version of v8::SetSyntheticModuleExport is removed. It differs from 37 // SetExport in that it crashes rather than throwing an error if the caller 38 // attempts to set an export_name that was not present during construction of 39 // the module. 40 static void SetExportStrict(Isolate* isolate, Handle<SyntheticModule> module, 41 Handle<String> export_name, 42 Handle<Object> export_value); 43 44 using BodyDescriptor = 45 SubclassBodyDescriptor<Module::BodyDescriptor, 46 FixedBodyDescriptor<kNameOffset, kSize, kSize>>; 47 48 private: 49 friend class Module; 50 51 static V8_WARN_UNUSED_RESULT MaybeHandle<Cell> ResolveExport( 52 Isolate* isolate, Handle<SyntheticModule> module, 53 Handle<String> module_specifier, Handle<String> export_name, 54 MessageLocation loc, bool must_resolve); 55 56 static V8_WARN_UNUSED_RESULT bool PrepareInstantiate( 57 Isolate* isolate, Handle<SyntheticModule> module, 58 v8::Local<v8::Context> context); 59 static V8_WARN_UNUSED_RESULT bool FinishInstantiate( 60 Isolate* isolate, Handle<SyntheticModule> module); 61 62 static V8_WARN_UNUSED_RESULT MaybeHandle<Object> Evaluate( 63 Isolate* isolate, Handle<SyntheticModule> module); 64 65 TQ_OBJECT_CONSTRUCTORS(SyntheticModule) 66 }; 67 68 } // namespace internal 69 } // namespace v8 70 71 #include "src/objects/object-macros-undef.h" 72 73 #endif // V8_OBJECTS_SYNTHETIC_MODULE_H_ 74