Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/src/async_wrap.h
1 // Copyright Joyent, Inc. and other Node contributors. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a 4 // copy of this software and associated documentation files (the 5 // "Software"), to deal in the Software without restriction, including 6 // without limitation the rights to use, copy, modify, merge, publish, 7 // distribute, sublicense, and/or sell copies of the Software, and to permit 8 // persons to whom the Software is furnished to do so, subject to the 9 // following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included 12 // in all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22 #ifndef SRC_ASYNC_WRAP_H_ 23 #define SRC_ASYNC_WRAP_H_ 24 25 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 26 27 #include "base_object.h" 28 #include "v8.h" 29 30 #include <cstdint> 31 32 namespace node { 33 34 #define NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \ 35 V(NONE) \ 36 V(DIRHANDLE) \ 37 V(DNSCHANNEL) \ 38 V(ELDHISTOGRAM) \ 39 V(FILEHANDLE) \ 40 V(FILEHANDLECLOSEREQ) \ 41 V(BLOBREADER) \ 42 V(FSEVENTWRAP) \ 43 V(FSREQCALLBACK) \ 44 V(FSREQPROMISE) \ 45 V(GETADDRINFOREQWRAP) \ 46 V(GETNAMEINFOREQWRAP) \ 47 V(HEAPSNAPSHOT) \ 48 V(HTTP2SESSION) \ 49 V(HTTP2STREAM) \ 50 V(HTTP2PING) \ 51 V(HTTP2SETTINGS) \ 52 V(HTTPINCOMINGMESSAGE) \ 53 V(HTTPCLIENTREQUEST) \ 54 V(JSSTREAM) \ 55 V(JSUDPWRAP) \ 56 V(MESSAGEPORT) \ 57 V(PIPECONNECTWRAP) \ 58 V(PIPESERVERWRAP) \ 59 V(PIPEWRAP) \ 60 V(PROCESSWRAP) \ 61 V(PROMISE) \ 62 V(QUERYWRAP) \ 63 V(QUIC_ENDPOINT) \ 64 V(QUIC_LOGSTREAM) \ 65 V(QUIC_PACKET) \ 66 V(QUIC_SESSION) \ 67 V(QUIC_STREAM) \ 68 V(QUIC_UDP) \ 69 V(SHUTDOWNWRAP) \ 70 V(SIGNALWRAP) \ 71 V(STATWATCHER) \ 72 V(STREAMPIPE) \ 73 V(TCPCONNECTWRAP) \ 74 V(TCPSERVERWRAP) \ 75 V(TCPWRAP) \ 76 V(TTYWRAP) \ 77 V(UDPSENDWRAP) \ 78 V(UDPWRAP) \ 79 V(SIGINTWATCHDOG) \ 80 V(WORKER) \ 81 V(WORKERCPUPROFILE) \ 82 V(WORKERCPUUSAGE) \ 83 V(WORKERHEAPSNAPSHOT) \ 84 V(WORKERHEAPSTATISTICS) \ 85 V(WRITEWRAP) \ 86 V(ZLIB) 87 88 #if HAVE_OPENSSL 89 #define NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) \ 90 V(CHECKPRIMEREQUEST) \ 91 V(PBKDF2REQUEST) \ 92 V(KEYPAIRGENREQUEST) \ 93 V(KEYGENREQUEST) \ 94 V(KEYEXPORTREQUEST) \ 95 V(CIPHERREQUEST) \ 96 V(DERIVEBITSREQUEST) \ 97 V(HASHREQUEST) \ 98 V(RANDOMBYTESREQUEST) \ 99 V(RANDOMPRIMEREQUEST) \ 100 V(SCRYPTREQUEST) \ 101 V(SIGNREQUEST) \ 102 V(TLSWRAP) \ 103 V(VERIFYREQUEST) 104 #else 105 #define NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) 106 #endif // HAVE_OPENSSL 107 108 #define NODE_ASYNC_PROVIDER_TYPES(V) \ 109 NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \ 110 NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) 111 112 class Environment; 113 class DestroyParam; 114 class ExternalReferenceRegistry; 115 116 class AsyncWrap : public BaseObject { 117 public: 118 enum ProviderType { 119 #define V(PROVIDER) \ 120 PROVIDER_ ## PROVIDER, 121 NODE_ASYNC_PROVIDER_TYPES(V) 122 #undef V 123 PROVIDERS_LENGTH, 124 }; 125 126 AsyncWrap(Environment* env, 127 v8::Local<v8::Object> object, 128 ProviderType provider, 129 double execution_async_id = kInvalidAsyncId); 130 131 // This constructor creates a reusable instance where user is responsible 132 // to call set_provider_type() and AsyncReset() before use. 133 AsyncWrap(Environment* env, v8::Local<v8::Object> object); 134 135 ~AsyncWrap() override; 136 137 AsyncWrap() = delete; 138 139 static constexpr double kInvalidAsyncId = -1; 140 141 static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( 142 IsolateData* isolate_data); 143 inline static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( 144 Environment* env); 145 146 static void RegisterExternalReferences(ExternalReferenceRegistry* registry); 147 static void CreatePerContextProperties(v8::Local<v8::Object> target, 148 v8::Local<v8::Value> unused, 149 v8::Local<v8::Context> context, 150 void* priv); 151 static void CreatePerIsolateProperties(IsolateData* isolate_data, 152 v8::Local<v8::ObjectTemplate> target); 153 154 static void GetAsyncId(const v8::FunctionCallbackInfo<v8::Value>& args); 155 static void PushAsyncContext(const v8::FunctionCallbackInfo<v8::Value>& args); 156 static void PopAsyncContext(const v8::FunctionCallbackInfo<v8::Value>& args); 157 static void ExecutionAsyncResource( 158 const v8::FunctionCallbackInfo<v8::Value>& args); 159 static void ClearAsyncIdStack( 160 const v8::FunctionCallbackInfo<v8::Value>& args); 161 static void AsyncReset(const v8::FunctionCallbackInfo<v8::Value>& args); 162 static void GetProviderType(const v8::FunctionCallbackInfo<v8::Value>& args); 163 static void QueueDestroyAsyncId( 164 const v8::FunctionCallbackInfo<v8::Value>& args); 165 static void SetCallbackTrampoline( 166 const v8::FunctionCallbackInfo<v8::Value>& args); 167 168 static void EmitAsyncInit(Environment* env, 169 v8::Local<v8::Object> object, 170 v8::Local<v8::String> type, 171 double async_id, 172 double trigger_async_id); 173 174 static void EmitDestroy(Environment* env, double async_id); 175 static void EmitBefore(Environment* env, double async_id); 176 static void EmitAfter(Environment* env, double async_id); 177 static void EmitPromiseResolve(Environment* env, double async_id); 178 179 void EmitDestroy(bool from_gc = false); 180 181 void EmitTraceAsyncStart() const; 182 void EmitTraceEventBefore(); 183 static void EmitTraceEventAfter(ProviderType type, double async_id); 184 void EmitTraceEventDestroy(); 185 186 static void DestroyAsyncIdsCallback(Environment* env); 187 188 inline ProviderType provider_type() const; 189 inline ProviderType set_provider_type(ProviderType provider); 190 191 inline double get_async_id() const; 192 inline double get_trigger_async_id() const; 193 194 inline v8::Local<v8::Value> context_frame() const; 195 196 void AsyncReset(v8::Local<v8::Object> resource, 197 double execution_async_id = kInvalidAsyncId); 198 199 // Only call these within a valid HandleScope. 200 v8::MaybeLocal<v8::Value> MakeCallback(const v8::Local<v8::Function> cb, 201 int argc, 202 v8::Local<v8::Value>* argv); 203 inline v8::MaybeLocal<v8::Value> MakeCallback( 204 const v8::Local<v8::Symbol> symbol, 205 int argc, 206 v8::Local<v8::Value>* argv); 207 inline v8::MaybeLocal<v8::Value> MakeCallback( 208 const v8::Local<v8::String> symbol, 209 int argc, 210 v8::Local<v8::Value>* argv); 211 inline v8::MaybeLocal<v8::Value> MakeCallback( 212 const v8::Local<v8::Name> symbol, 213 int argc, 214 v8::Local<v8::Value>* argv); 215 216 virtual std::string diagnostic_name() const; 217 const char* MemoryInfoName() const override; 218 219 static void WeakCallback(const v8::WeakCallbackInfo<DestroyParam> &info); 220 221 // Returns the object that 'owns' an async wrap. For example, for a 222 // TCP connection handle, this is the corresponding net.Socket. 223 v8::Local<v8::Object> GetOwner(); 224 static v8::Local<v8::Object> GetOwner(Environment* env, 225 v8::Local<v8::Object> obj); 226 227 bool IsDoneInitializing() const override; 228 229 private: 230 ProviderType provider_type_ = PROVIDER_NONE; 231 bool init_hook_ran_ = false; 232 // Because the values may be Reset(), cannot be made const. 233 double async_id_ = kInvalidAsyncId; 234 double trigger_async_id_ = kInvalidAsyncId; 235 236 v8::Global<v8::Value> context_frame_; 237 }; 238 239 } // namespace node 240 241 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 242 243 #endif // SRC_ASYNC_WRAP_H_