#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 { namespace contextify { struct ContextOptions { v8::Local name; v8::Local origin; v8::Local allow_code_gen_strings; v8::Local allow_code_gen_wasm; }; class ContextifyContext { public: ContextifyContext(Environment* env, v8::Local sandbox_obj, const ContextOptions& options); v8::MaybeLocal CreateDataWrapper(Environment* env); v8::MaybeLocal CreateV8Context(Environment* env, v8::Local sandbox_obj, const ContextOptions& options); static void Init(Environment* env, v8::Local target); static ContextifyContext* ContextFromContextifiedSandbox( Environment* env, const v8::Local& sandbox); inline Environment* env() const { return env_; } 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 v8::Local::Cast( context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject)); } template static ContextifyContext* Get(const v8::PropertyCallbackInfo& args); private: 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); Environment* const env_; Persistent context_; }; 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(); static void Init(Environment* env, v8::Local target); 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 RunInThisContext(const v8::FunctionCallbackInfo& args); static void RunInContext(const v8::FunctionCallbackInfo& args); static bool EvalMachine(Environment* env, const int64_t timeout, const bool display_errors, const bool break_on_sigint, const bool break_on_first_line, const v8::FunctionCallbackInfo& args); inline uint32_t id() { return id_; } private: node::Persistent script_; uint32_t id_; }; } // namespace contextify } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_CONTEXTIFY_H_