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 DECL_PRINTER(SyntheticModule) 28 29 // Set module's exported value for the specified export_name to the specified 30 // export_value. An error will be thrown if export_name is not one 31 // of the export_names that were supplied during module construction. 32 // Returns Just(true) on success, Nothing<bool>() if an error was thrown. 33 static Maybe<bool> SetExport(Isolate* isolate, Handle<SyntheticModule> module, 34 Handle<String> export_name, 35 Handle<Object> export_value); 36 // The following redundant method should be deleted when the deprecated 37 // version of v8::SetSyntheticModuleExport is removed. It differs from 38 // SetExport in that it crashes rather than throwing an error if the caller 39 // attempts to set an export_name that was not present during construction of 40 // the module. 41 static void SetExportStrict(Isolate* isolate, Handle<SyntheticModule> module, 42 Handle<String> export_name, 43 Handle<Object> export_value); 44 45 using BodyDescriptor = 46 SubclassBodyDescriptor<Module::BodyDescriptor, 47 FixedBodyDescriptor<kNameOffset, kSize, kSize>>; 48 49 private: 50 friend class Module; 51 52 static V8_WARN_UNUSED_RESULT MaybeHandle<Cell> ResolveExport( 53 Isolate* isolate, Handle<SyntheticModule> module, 54 Handle<String> module_specifier, Handle<String> export_name, 55 MessageLocation loc, bool must_resolve); 56 57 static V8_WARN_UNUSED_RESULT bool PrepareInstantiate( 58 Isolate* isolate, Handle<SyntheticModule> module, 59 v8::Local<v8::Context> context, v8::Module::ResolveCallback callback); 60 static V8_WARN_UNUSED_RESULT bool FinishInstantiate( 61 Isolate* isolate, Handle<SyntheticModule> module); 62 63 static V8_WARN_UNUSED_RESULT MaybeHandle<Object> Evaluate( 64 Isolate* isolate, Handle<SyntheticModule> module); 65 66 TQ_OBJECT_CONSTRUCTORS(SyntheticModule) 67 }; 68 69 } // namespace internal 70 } // namespace v8 71 72 #include "src/objects/object-macros-undef.h" 73 74 #endif // V8_OBJECTS_SYNTHETIC_MODULE_H_ 75