Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void SetupHooks(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args);
- CHECK(args[0]->IsObject());
- // All of init, before, after, destroy are supplied by async_hooks
- // internally, so this should every only be called once. At which time all
- // the functions should be set. Detect this by checking if init !IsEmpty().
- CHECK(env->async_hooks_init_function().IsEmpty());
- Local<Object> fn_obj = args[0].As<Object>();
- #define SET_HOOK_FN(name) \
- do { \
- Local<Value> v = \
- fn_obj->Get(env->context(), \
- FIXED_ONE_BYTE_STRING(env->isolate(), #name)) \
- .ToLocalChecked(); \
- CHECK(v->IsFunction()); \
- env->set_async_hooks_##name##_function(v.As<Function>()); \
- } while (0)
- SET_HOOK_FN(init);
- SET_HOOK_FN(before);
- SET_HOOK_FN(after);
- SET_HOOK_FN(destroy);
- SET_HOOK_FN(promise_resolve);
- #undef SET_HOOK_FN
- {
- Local<FunctionTemplate> ctor =
- FunctionTemplate::New(env->isolate());
- ctor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "PromiseWrap"));
- Local<ObjectTemplate> promise_wrap_template = ctor->InstanceTemplate();
- promise_wrap_template->SetInternalFieldCount(
- PromiseWrap::kInternalFieldCount);
- promise_wrap_template->SetAccessor(
- FIXED_ONE_BYTE_STRING(env->isolate(), "isChainedPromise"),
- PromiseWrap::getIsChainedPromise);
- env->set_promise_wrap_template(promise_wrap_template);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement