You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.8 KiB

#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_PROVIDER_TYPES(V) \
V(NONE) \
V(CRYPTO) \
V(FSEVENTWRAP) \
V(FSREQWRAP) \
V(GETADDRINFOREQWRAP) \
V(GETNAMEINFOREQWRAP) \
V(HTTPPARSER) \
V(JSSTREAM) \
V(PIPEWRAP) \
V(PIPECONNECTWRAP) \
V(PROCESSWRAP) \
V(QUERYWRAP) \
V(SHUTDOWNWRAP) \
V(SIGNALWRAP) \
V(STATWATCHER) \
V(TCPWRAP) \
V(TCPCONNECTWRAP) \
V(TIMERWRAP) \
V(TLSWRAP) \
V(TTYWRAP) \
V(UDPWRAP) \
V(UDPSENDWRAP) \
V(WRITEWRAP) \
V(ZLIB)
class Environment;
class AsyncWrap : public BaseObject {
public:
enum ProviderType {
#define V(PROVIDER) \
PROVIDER_ ## PROVIDER,
NODE_ASYNC_PROVIDER_TYPES(V)
#undef V
};
inline AsyncWrap(Environment* env,
v8::Local<v8::Object> object,
ProviderType provider,
AsyncWrap* parent = nullptr);
inline virtual ~AsyncWrap();
inline ProviderType provider_type() const;
inline int64_t get_uid() const;
// Only call these within a valid HandleScope.
v8::Local<v8::Value> MakeCallback(const v8::Local<v8::Function> cb,
int argc,
v8::Local<v8::Value>* argv);
inline v8::Local<v8::Value> MakeCallback(const v8::Local<v8::String> symbol,
int argc,
v8::Local<v8::Value>* argv);
inline v8::Local<v8::Value> MakeCallback(uint32_t index,
int argc,
v8::Local<v8::Value>* argv);
virtual size_t self_size() const = 0;
private:
inline AsyncWrap();
inline bool ran_init_callback() const;
async-wrap: add event hooks Call a user-defined callback at specific points in the lifetime of an asynchronous event. Which are on instantiation, just before/after the callback has been run. **If any of these callbacks throws an exception, there is no forgiveness or recovery. A message will be displayed and a core file dumped.** Currently these only tie into AsyncWrap, meaning no call to a hook callback will be made for timers or process.nextTick() events. Though those will be added in a future commit. Here are a few notes on how to make the hooks work: - The &#34;this&#34; of all event hook callbacks is the request object. - The zero field (kCallInitHook) of the flags object passed to setupHooks() must be set != 0 before the init callback will be called. - kCallInitHook only affects the calling of the init callback. If the request object has been run through the create callback it will always run the before/after callbacks. Regardless of kCallInitHook. - In the init callback the property &#34;_asyncQueue&#34; must be attached to the request object. e.g. function initHook() { this._asyncQueue = {}; } - DO NOT inspect the properties of the object in the init callback. Since the object is in the middle of being instantiated there are some cases when a getter is not complete, and doing so will cause Node to crash. PR-URL: https://github.com/joyent/node/pull/8110 Signed-off-by: Trevor Norris &lt;trev.norris@gmail.com&gt; Reviewed-by: Fedor Indutny &lt;fedor@indutny.com&gt; Reviewed-by: Alexis Campailla &lt;alexis@janeasystems.com&gt; Reviewed-by: Julien Gilli &lt;julien.gilli@joyent.com&gt;
10 years ago
// When the async hooks init JS function is called from the constructor it is
// expected the context object will receive a _asyncQueue object property
// that will be used to call pre/post in MakeCallback.
uint32_t bits_;
const int64_t uid_;
};
void LoadAsyncWrapperInfo(Environment* env);
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_ASYNC_WRAP_H_