Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. static void SetupHooks(const FunctionCallbackInfo<Value>& args) {
  2. Environment* env = Environment::GetCurrent(args);
  3.  
  4. CHECK(args[0]->IsObject());
  5.  
  6. // All of init, before, after, destroy are supplied by async_hooks
  7. // internally, so this should every only be called once. At which time all
  8. // the functions should be set. Detect this by checking if init !IsEmpty().
  9. CHECK(env->async_hooks_init_function().IsEmpty());
  10.  
  11. Local<Object> fn_obj = args[0].As<Object>();
  12.  
  13. #define SET_HOOK_FN(name) \
  14. do { \
  15. Local<Value> v = \
  16. fn_obj->Get(env->context(), \
  17. FIXED_ONE_BYTE_STRING(env->isolate(), #name)) \
  18. .ToLocalChecked(); \
  19. CHECK(v->IsFunction()); \
  20. env->set_async_hooks_##name##_function(v.As<Function>()); \
  21. } while (0)
  22.  
  23. SET_HOOK_FN(init);
  24. SET_HOOK_FN(before);
  25. SET_HOOK_FN(after);
  26. SET_HOOK_FN(destroy);
  27. SET_HOOK_FN(promise_resolve);
  28. #undef SET_HOOK_FN
  29.  
  30. {
  31. Local<FunctionTemplate> ctor =
  32. FunctionTemplate::New(env->isolate());
  33. ctor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "PromiseWrap"));
  34. Local<ObjectTemplate> promise_wrap_template = ctor->InstanceTemplate();
  35. promise_wrap_template->SetInternalFieldCount(
  36. PromiseWrap::kInternalFieldCount);
  37. promise_wrap_template->SetAccessor(
  38. FIXED_ONE_BYTE_STRING(env->isolate(), "isChainedPromise"),
  39. PromiseWrap::getIsChainedPromise);
  40. env->set_promise_wrap_template(promise_wrap_template);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement