Created
June 15, 2019 23:46
-
-
Save deepal/62826f6cecd1071426b040aa2093adee to your computer and use it in GitHub Desktop.
Triggering JS init() hooks from c++ async_hooks_init_function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void AsyncWrap::EmitAsyncInit(Environment* env, | |
| Local<Object> object, | |
| Local<String> type, | |
| double async_id, | |
| double trigger_async_id) { | |
| CHECK(!object.IsEmpty()); | |
| CHECK(!type.IsEmpty()); | |
| AsyncHooks* async_hooks = env->async_hooks(); | |
| // Nothing to execute, so can continue normally. | |
| if (async_hooks->fields()[AsyncHooks::kInit] == 0) { | |
| return; | |
| } | |
| HandleScope scope(env->isolate()); | |
| Local<Function> init_fn = env->async_hooks_init_function(); | |
| Local<Value> argv[] = { | |
| Number::New(env->isolate(), async_id), | |
| type, | |
| Number::New(env->isolate(), trigger_async_id), | |
| object, | |
| }; | |
| TryCatchScope try_catch(env, TryCatchScope::CatchMode::kFatal); | |
| USE(init_fn->Call(env->context(), object, arraysize(argv), argv)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment