#ifndef SRC_NODE_CONTEXTIFY_H_ #define SRC_NODE_CONTEXTIFY_H_ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "base_object-inl.h" #include "node_context_data.h" #include "node_errors.h" namespace node { class ExternalReferenceRegistry; namespace contextify { struct ContextOptions { v8::Local name; v8::Local origin; v8::Local allow_code_gen_strings; v8::Local allow_code_gen_wasm; std::unique_ptr own_microtask_queue; }; class ContextifyContext : public BaseObject { public: ContextifyContext(Environment* env, v8::Local wrapper, v8::Local v8_context, ContextOptions* options); ~ContextifyContext(); void MemoryInfo(MemoryTracker* tracker) const override; SET_MEMORY_INFO_NAME(ContextifyContext) SET_SELF_SIZE(ContextifyContext) static v8::MaybeLocal CreateV8Context( v8::Isolate* isolate, v8::Local object_template, const SnapshotData* snapshot_data, v8::MicrotaskQueue* queue); static void CreatePerIsolateProperties(IsolateData* isolate_data, v8::Local target); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); static ContextifyContext* ContextFromContextifiedSandbox( Environment* env, const v8::Local& sandbox); inline v8::Local context() const { return PersistentToLocal::Default(env()->isolate(), context_); } inline v8::Local global_proxy() const { return context()->Global(); } inline v8::Local sandbox() const { return context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject) .As(); } inline v8::MicrotaskQueue* microtask_queue() const { return microtask_queue_.get(); } template static ContextifyContext* Get(const v8::PropertyCallbackInfo& args); static ContextifyContext* Get(v8::Local object); static void InitializeGlobalTemplates(IsolateData* isolate_data); private: static BaseObjectPtr New(Environment* env, v8::Local sandbox_obj, ContextOptions* options); // Initialize a context created from CreateV8Context() static BaseObjectPtr New(v8::Local ctx, Environment* env, v8::Local sandbox_obj, ContextOptions* options); static bool IsStillInitializing(const ContextifyContext* ctx); static void MakeContext(const v8::FunctionCallbackInfo& args); static void IsContext(const v8::FunctionCallbackInfo& args); static void CompileFunction( const v8::FunctionCallbackInfo& args); static void WeakCallback( const v8::WeakCallbackInfo& data); static void PropertyGetterCallback( v8::Local property, const v8::PropertyCallbackInfo& args); static void PropertySetterCallback( v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& args); static void PropertyDescriptorCallback( v8::Local property, const v8::PropertyCallbackInfo& args); static void PropertyDefinerCallback( v8::Local property, const v8::PropertyDescriptor& desc, const v8::PropertyCallbackInfo& args); static void PropertyDeleterCallback( v8::Local property, const v8::PropertyCallbackInfo& args); static void PropertyEnumeratorCallback( const v8::PropertyCallbackInfo& args); static void IndexedPropertyGetterCallback( uint32_t index, const v8::PropertyCallbackInfo& args); static void IndexedPropertySetterCallback( uint32_t index, v8::Local value, const v8::PropertyCallbackInfo& args); static void IndexedPropertyDescriptorCallback( uint32_t index, const v8::PropertyCallbackInfo& args); static void IndexedPropertyDefinerCallback( uint32_t index, const v8::PropertyDescriptor& desc, const v8::PropertyCallbackInfo& args); static void IndexedPropertyDeleterCallback( uint32_t index, const v8::PropertyCallbackInfo& args); v8::Global context_; std::unique_ptr microtask_queue_; }; class ContextifyScript : public BaseObject { public: SET_NO_MEMORY_INFO() SET_MEMORY_INFO_NAME(ContextifyScript) SET_SELF_SIZE(ContextifyScript) ContextifyScript(Environment* env, v8::Local object); ~ContextifyScript() override; static void CreatePerIsolateProperties(IsolateData* isolate_data, v8::Local target); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); static void New(const v8::FunctionCallbackInfo& args); static bool InstanceOf(Environment* env, const v8::Local& args); static void CreateCachedData(const v8::FunctionCallbackInfo& args); static void RunInContext(const v8::FunctionCallbackInfo& args); static bool EvalMachine(v8::Local context, Environment* env, const int64_t timeout, const bool display_errors, const bool break_on_sigint, const bool break_on_first_line, v8::MicrotaskQueue* microtask_queue, const v8::FunctionCallbackInfo& args); inline uint32_t id() { return id_; } private: v8::Global script_; uint32_t id_; }; class CompiledFnEntry final : public BaseObject { public: SET_NO_MEMORY_INFO() SET_MEMORY_INFO_NAME(CompiledFnEntry) SET_SELF_SIZE(CompiledFnEntry) CompiledFnEntry(Environment* env, v8::Local object, uint32_t id, v8::Local fn); ~CompiledFnEntry(); bool IsNotIndicativeOfMemoryLeakAtExit() const override { return true; } private: uint32_t id_; v8::Global fn_; static void WeakCallback(const v8::WeakCallbackInfo& data); }; v8::Maybe StoreCodeCacheResult( Environment* env, v8::Local target, v8::ScriptCompiler::CompileOptions compile_options, const v8::ScriptCompiler::Source& source, bool produce_cached_data, std::unique_ptr new_cached_data); v8::MaybeLocal CompileFunction( v8::Local context, v8::Local filename, v8::Local content, std::vector>* parameters); } // namespace contextify } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_CONTEXTIFY_H_