Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/src/node_contextify.h
1 #ifndef SRC_NODE_CONTEXTIFY_H_ 2 #define SRC_NODE_CONTEXTIFY_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "base_object-inl.h" 7 #include "node_context_data.h" 8 #include "node_errors.h" 9 10 namespace node { 11 class ExternalReferenceRegistry; 12 13 namespace contextify { 14 15 struct ContextOptions { 16 v8::Local<v8::String> name; 17 v8::Local<v8::String> origin; 18 v8::Local<v8::Boolean> allow_code_gen_strings; 19 v8::Local<v8::Boolean> allow_code_gen_wasm; 20 std::unique_ptr<v8::MicrotaskQueue> own_microtask_queue; 21 v8::Local<v8::Symbol> host_defined_options_id; 22 bool vanilla = false; 23 }; 24 25 class ContextifyContext : public BaseObject { 26 public: 27 ContextifyContext(Environment* env, 28 v8::Local<v8::Object> wrapper, 29 v8::Local<v8::Context> v8_context, 30 ContextOptions* options); 31 ~ContextifyContext(); 32 33 void MemoryInfo(MemoryTracker* tracker) const override; 34 SET_MEMORY_INFO_NAME(ContextifyContext) 35 SET_SELF_SIZE(ContextifyContext) 36 37 static v8::MaybeLocal<v8::Context> CreateV8Context( 38 v8::Isolate* isolate, 39 v8::Local<v8::ObjectTemplate> object_template, 40 const SnapshotData* snapshot_data, 41 v8::MicrotaskQueue* queue); 42 static void CreatePerIsolateProperties(IsolateData* isolate_data, 43 v8::Local<v8::ObjectTemplate> target); 44 static void RegisterExternalReferences(ExternalReferenceRegistry* registry); 45 46 static ContextifyContext* ContextFromContextifiedSandbox( 47 Environment* env, const v8::Local<v8::Object>& wrapper_holder); 48 49 inline v8::Local<v8::Context> context() const { 50 return PersistentToLocal::Default(env()->isolate(), context_); 51 } 52 53 inline v8::Local<v8::Object> global_proxy() const { 54 return context()->Global(); 55 } 56 57 inline v8::Local<v8::Object> sandbox() const { 58 // Only vanilla contexts have undefined sandboxes. sandbox() is only used by 59 // interceptors who are not supposed to be called on vanilla contexts. 60 v8::Local<v8::Value> result = 61 context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject); 62 CHECK(!result->IsUndefined()); 63 return result.As<v8::Object>(); 64 } 65 66 inline v8::MicrotaskQueue* microtask_queue() const { 67 return microtask_queue_.get(); 68 } 69 70 template <typename T> 71 static ContextifyContext* Get(const v8::PropertyCallbackInfo<T>& args); 72 static ContextifyContext* Get(v8::Local<v8::Object> object); 73 74 static void InitializeGlobalTemplates(IsolateData* isolate_data); 75 76 private: 77 static BaseObjectPtr<ContextifyContext> New(Environment* env, 78 v8::Local<v8::Object> sandbox_obj, 79 ContextOptions* options); 80 // Initialize a context created from CreateV8Context() 81 static BaseObjectPtr<ContextifyContext> New(v8::Local<v8::Context> ctx, 82 Environment* env, 83 v8::Local<v8::Object> sandbox_obj, 84 ContextOptions* options); 85 86 static bool IsStillInitializing(const ContextifyContext* ctx); 87 static void MakeContext(const v8::FunctionCallbackInfo<v8::Value>& args); 88 static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args); 89 static v8::Intercepted PropertyQueryCallback( 90 v8::Local<v8::Name> property, 91 const v8::PropertyCallbackInfo<v8::Integer>& args); 92 static v8::Intercepted PropertyGetterCallback( 93 v8::Local<v8::Name> property, 94 const v8::PropertyCallbackInfo<v8::Value>& args); 95 static v8::Intercepted PropertySetterCallback( 96 v8::Local<v8::Name> property, 97 v8::Local<v8::Value> value, 98 const v8::PropertyCallbackInfo<void>& args); 99 static v8::Intercepted PropertyDescriptorCallback( 100 v8::Local<v8::Name> property, 101 const v8::PropertyCallbackInfo<v8::Value>& args); 102 static v8::Intercepted PropertyDefinerCallback( 103 v8::Local<v8::Name> property, 104 const v8::PropertyDescriptor& desc, 105 const v8::PropertyCallbackInfo<void>& args); 106 static v8::Intercepted PropertyDeleterCallback( 107 v8::Local<v8::Name> property, 108 const v8::PropertyCallbackInfo<v8::Boolean>& args); 109 static void PropertyEnumeratorCallback( 110 const v8::PropertyCallbackInfo<v8::Array>& args); 111 static v8::Intercepted IndexedPropertyQueryCallback( 112 uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& args); 113 static v8::Intercepted IndexedPropertyGetterCallback( 114 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args); 115 static v8::Intercepted IndexedPropertySetterCallback( 116 uint32_t index, 117 v8::Local<v8::Value> value, 118 const v8::PropertyCallbackInfo<void>& args); 119 static v8::Intercepted IndexedPropertyDescriptorCallback( 120 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args); 121 static v8::Intercepted IndexedPropertyDefinerCallback( 122 uint32_t index, 123 const v8::PropertyDescriptor& desc, 124 const v8::PropertyCallbackInfo<void>& args); 125 static v8::Intercepted IndexedPropertyDeleterCallback( 126 uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& args); 127 static void IndexedPropertyEnumeratorCallback( 128 const v8::PropertyCallbackInfo<v8::Array>& args); 129 130 v8::Global<v8::Context> context_; 131 std::unique_ptr<v8::MicrotaskQueue> microtask_queue_; 132 }; 133 134 class ContextifyScript : public BaseObject { 135 public: 136 enum InternalFields { 137 kUnboundScriptSlot = BaseObject::kInternalFieldCount, 138 kInternalFieldCount 139 }; 140 141 SET_NO_MEMORY_INFO() 142 SET_MEMORY_INFO_NAME(ContextifyScript) 143 SET_SELF_SIZE(ContextifyScript) 144 145 ContextifyScript(Environment* env, v8::Local<v8::Object> object); 146 ~ContextifyScript() override; 147 148 static void CreatePerIsolateProperties(IsolateData* isolate_data, 149 v8::Local<v8::ObjectTemplate> target); 150 static void RegisterExternalReferences(ExternalReferenceRegistry* registry); 151 static void New(const v8::FunctionCallbackInfo<v8::Value>& args); 152 static bool InstanceOf(Environment* env, const v8::Local<v8::Value>& args); 153 static void CreateCachedData(const v8::FunctionCallbackInfo<v8::Value>& args); 154 static void RunInContext(const v8::FunctionCallbackInfo<v8::Value>& args); 155 static bool EvalMachine(v8::Local<v8::Context> context, 156 Environment* env, 157 const int64_t timeout, 158 const bool display_errors, 159 const bool break_on_sigint, 160 const bool break_on_first_line, 161 v8::MicrotaskQueue* microtask_queue, 162 const v8::FunctionCallbackInfo<v8::Value>& args); 163 164 private: 165 v8::Global<v8::UnboundScript> script_; 166 }; 167 168 class ContextifyFunction final { 169 public: 170 static void RegisterExternalReferences(ExternalReferenceRegistry* registry); 171 static void CreatePerIsolateProperties(IsolateData* isolate_data, 172 v8::Local<v8::ObjectTemplate> target); 173 174 static void CompileFunction(const v8::FunctionCallbackInfo<v8::Value>& args); 175 static v8::MaybeLocal<v8::Object> CompileFunctionAndCacheResult( 176 Environment* env, 177 v8::Local<v8::Context> parsing_context, 178 v8::ScriptCompiler::Source* source, 179 v8::LocalVector<v8::String> params, 180 v8::LocalVector<v8::Object> context_extensions, 181 v8::ScriptCompiler::CompileOptions options, 182 bool produce_cached_data, 183 v8::Local<v8::Symbol> id_symbol, 184 const errors::TryCatchScope& try_catch); 185 186 private: 187 ContextifyFunction() = delete; 188 ~ContextifyFunction() = delete; 189 }; 190 191 v8::Maybe<void> StoreCodeCacheResult( 192 Environment* env, 193 v8::Local<v8::Object> target, 194 v8::ScriptCompiler::CompileOptions compile_options, 195 const v8::ScriptCompiler::Source& source, 196 bool produce_cached_data, 197 std::unique_ptr<v8::ScriptCompiler::CachedData> new_cached_data); 198 199 } // namespace contextify 200 } // namespace node 201 202 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 203 204 #endif // SRC_NODE_CONTEXTIFY_H_