#ifndef SRC_MODULE_WRAP_H_ #define SRC_MODULE_WRAP_H_ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include #include #include #include #include "base_object.h" #include "v8-script.h" namespace node { class IsolateData; class Environment; class ExternalReferenceRegistry; namespace contextify { class ContextifyContext; } namespace loader { enum ScriptType : int { kScript, kModule, kFunction, }; enum HostDefinedOptions : int { kID = 8, kLength = 9, }; class ModuleWrap : public BaseObject { public: enum InternalFields { kModuleSlot = BaseObject::kInternalFieldCount, kURLSlot, kSyntheticEvaluationStepsSlot, kContextObjectSlot, // Object whose creation context is the target Context kInternalFieldCount }; static void CreatePerIsolateProperties(IsolateData* isolate_data, v8::Local target); static void CreatePerContextProperties(v8::Local target, v8::Local unused, v8::Local context, void* priv); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); static void HostInitializeImportMetaObjectCallback( v8::Local context, v8::Local module, v8::Local meta); void MemoryInfo(MemoryTracker* tracker) const override { tracker->TrackField("resolve_cache", resolve_cache_); } static void HasTopLevelAwait(const v8::FunctionCallbackInfo& args); v8::Local context() const; v8::Maybe CheckUnsettledTopLevelAwait(); SET_MEMORY_INFO_NAME(ModuleWrap) SET_SELF_SIZE(ModuleWrap) bool IsNotIndicativeOfMemoryLeakAtExit() const override { // XXX: The garbage collection rules for ModuleWrap are *super* unclear. // Do these objects ever get GC'd? Are we just okay with leaking them? return true; } static v8::Local GetHostDefinedOptions( v8::Isolate* isolate, v8::Local symbol); // When user_cached_data is not std::nullopt, use the code cache if it's not // nullptr, otherwise don't use code cache. // TODO(joyeecheung): when it is std::nullopt, use on-disk cache // See: https://github.com/nodejs/node/issues/47472 static v8::MaybeLocal CompileSourceTextModule( Realm* realm, v8::Local source_text, v8::Local url, int line_offset, int column_offset, v8::Local host_defined_options, std::optional user_cached_data, bool* cache_rejected); static void CreateRequiredModuleFacade( const v8::FunctionCallbackInfo& args); private: ModuleWrap(Realm* realm, v8::Local object, v8::Local module, v8::Local url, v8::Local context_object, v8::Local synthetic_evaluation_step); ~ModuleWrap() override; static void New(const v8::FunctionCallbackInfo& args); static void GetModuleRequests( const v8::FunctionCallbackInfo& args); static void InstantiateSync(const v8::FunctionCallbackInfo& args); static void EvaluateSync(const v8::FunctionCallbackInfo& args); static void GetNamespaceSync(const v8::FunctionCallbackInfo& args); static void Link(const v8::FunctionCallbackInfo& args); static void Instantiate(const v8::FunctionCallbackInfo& args); static void Evaluate(const v8::FunctionCallbackInfo& args); static void GetNamespace(const v8::FunctionCallbackInfo& args); static void IsGraphAsync(const v8::FunctionCallbackInfo& args); static void GetStatus(const v8::FunctionCallbackInfo& args); static void GetError(const v8::FunctionCallbackInfo& args); static void SetImportModuleDynamicallyCallback( const v8::FunctionCallbackInfo& args); static void SetInitializeImportMetaObjectCallback( const v8::FunctionCallbackInfo& args); static v8::MaybeLocal SyntheticModuleEvaluationStepsCallback( v8::Local context, v8::Local module); static void SetSyntheticExport( const v8::FunctionCallbackInfo& args); static void CreateCachedData(const v8::FunctionCallbackInfo& args); static v8::MaybeLocal ResolveModuleCallback( v8::Local context, v8::Local specifier, v8::Local import_attributes, v8::Local referrer); static ModuleWrap* GetFromModule(node::Environment*, v8::Local); v8::Global module_; std::unordered_map> resolve_cache_; contextify::ContextifyContext* contextify_context_ = nullptr; bool synthetic_ = false; int module_hash_; }; } // namespace loader } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_MODULE_WRAP_H_