diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2017-11-14 15:34:52 +0300 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2017-11-17 14:49:00 +0300 |
commit | 78447666ea2e70b32b082267fd3a6965ac80f6c2 (patch) | |
tree | 1c4f3930d85f4ffc8e02da9e264a2c8af2234261 /src/async_wrap.h | |
parent | a0aff57c5a5e46a2f93fc5bce50191993f98c673 (diff) |
src: rename async-wrap -> async_wrap
This commit renames async-wrap to async_wrap for consitency with other
c++ source files.
PR-URL: https://github.com/nodejs/node/pull/17022
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Diffstat (limited to 'src/async_wrap.h')
-rw-r--r-- | src/async_wrap.h | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/src/async_wrap.h b/src/async_wrap.h new file mode 100644 index 00000000000..222cda1fd7e --- /dev/null +++ b/src/async_wrap.h @@ -0,0 +1,187 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +#ifndef SRC_ASYNC_WRAP_H_ +#define SRC_ASYNC_WRAP_H_ + +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#include "base-object.h" +#include "v8.h" + +#include <stdint.h> + +namespace node { + +#define NODE_ASYNC_ID_OFFSET 0xA1C + +#define NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \ + V(NONE) \ + V(DNSCHANNEL) \ + V(FSEVENTWRAP) \ + V(FSREQWRAP) \ + V(GETADDRINFOREQWRAP) \ + V(GETNAMEINFOREQWRAP) \ + V(HTTP2SESSION) \ + V(HTTP2SESSIONSHUTDOWNWRAP) \ + V(HTTPPARSER) \ + V(JSSTREAM) \ + V(PIPECONNECTWRAP) \ + V(PIPEWRAP) \ + V(PROCESSWRAP) \ + V(PROMISE) \ + V(QUERYWRAP) \ + V(SHUTDOWNWRAP) \ + V(SIGNALWRAP) \ + V(STATWATCHER) \ + V(TCPCONNECTWRAP) \ + V(TCPWRAP) \ + V(TIMERWRAP) \ + V(TTYWRAP) \ + V(UDPSENDWRAP) \ + V(UDPWRAP) \ + V(WRITEWRAP) \ + V(ZLIB) + +#if HAVE_OPENSSL +#define NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) \ + V(SSLCONNECTION) \ + V(PBKDF2REQUEST) \ + V(RANDOMBYTESREQUEST) \ + V(TLSWRAP) +#else +#define NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) +#endif // HAVE_OPENSSL + +#if HAVE_INSPECTOR +#define NODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V) \ + V(INSPECTORJSBINDING) +#else +#define NODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V) +#endif // HAVE_INSPECTOR + +#define NODE_ASYNC_PROVIDER_TYPES(V) \ + NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \ + NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) \ + NODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V) + +class Environment; +class DestroyParam; + +class AsyncWrap : public BaseObject { + public: + enum ProviderType { +#define V(PROVIDER) \ + PROVIDER_ ## PROVIDER, + NODE_ASYNC_PROVIDER_TYPES(V) +#undef V + PROVIDERS_LENGTH, + }; + + enum Flags { + kFlagNone = 0x0, + kFlagHasReset = 0x1 + }; + + AsyncWrap(Environment* env, + v8::Local<v8::Object> object, + ProviderType provider, + double execution_async_id = -1); + + virtual ~AsyncWrap(); + + static void AddWrapMethods(Environment* env, + v8::Local<v8::FunctionTemplate> constructor, + int flags = kFlagNone); + + static void Initialize(v8::Local<v8::Object> target, + v8::Local<v8::Value> unused, + v8::Local<v8::Context> context); + + static void GetAsyncId(const v8::FunctionCallbackInfo<v8::Value>& args); + static void PushAsyncIds(const v8::FunctionCallbackInfo<v8::Value>& args); + static void PopAsyncIds(const v8::FunctionCallbackInfo<v8::Value>& args); + static void AsyncIdStackSize(const v8::FunctionCallbackInfo<v8::Value>& args); + static void ClearAsyncIdStack( + const v8::FunctionCallbackInfo<v8::Value>& args); + static void AsyncReset(const v8::FunctionCallbackInfo<v8::Value>& args); + static void QueueDestroyAsyncId( + const v8::FunctionCallbackInfo<v8::Value>& args); + + static void EmitAsyncInit(Environment* env, + v8::Local<v8::Object> object, + v8::Local<v8::String> type, + double async_id, + double trigger_async_id); + + static void EmitDestroy(Environment* env, double async_id); + static void EmitBefore(Environment* env, double async_id); + static void EmitAfter(Environment* env, double async_id); + static void EmitPromiseResolve(Environment* env, double async_id); + + void EmitTraceEventBefore(); + void EmitTraceEventAfter(); + void EmitTraceEventDestroy(); + + + inline ProviderType provider_type() const; + + inline double get_async_id() const; + + inline double get_trigger_async_id() const; + + void AsyncReset(double execution_async_id = -1, bool silent = false); + + // Only call these within a valid HandleScope. + v8::MaybeLocal<v8::Value> MakeCallback(const v8::Local<v8::Function> cb, + int argc, + v8::Local<v8::Value>* argv); + inline v8::MaybeLocal<v8::Value> MakeCallback( + const v8::Local<v8::String> symbol, + int argc, + v8::Local<v8::Value>* argv); + inline v8::MaybeLocal<v8::Value> MakeCallback(uint32_t index, + int argc, + v8::Local<v8::Value>* argv); + + virtual size_t self_size() const = 0; + + static void WeakCallback(const v8::WeakCallbackInfo<DestroyParam> &info); + + private: + friend class PromiseWrap; + + // This is specifically used by the PromiseWrap constructor. + AsyncWrap(Environment* env, v8::Local<v8::Object> promise, bool silent); + inline AsyncWrap(); + const ProviderType provider_type_; + // Because the values may be Reset(), cannot be made const. + double async_id_; + double trigger_async_id_; +}; + +void LoadAsyncWrapperInfo(Environment* env); + +} // namespace node + +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#endif // SRC_ASYNC_WRAP_H_ |