@@ -23,32 +23,28 @@ using v8::kExternalUint32Array;
23
23
24
24
namespace node {
25
25
26
+ static void EnableHooksJS (const FunctionCallbackInfo<Value>& args) {
27
+ Environment* env = Environment::GetCurrent (args);
28
+ env->async_hooks ()->set_enable_callbacks (1 );
29
+ }
30
+
31
+
32
+ static void DisableHooksJS (const FunctionCallbackInfo<Value>& args) {
33
+ Environment* env = Environment::GetCurrent (args);
34
+ env->async_hooks ()->set_enable_callbacks (0 );
35
+ }
36
+
37
+
26
38
static void SetupHooks (const FunctionCallbackInfo<Value>& args) {
27
- Environment* env = Environment::GetCurrent (args. GetIsolate () );
39
+ Environment* env = Environment::GetCurrent (args);
28
40
29
- CHECK (args[0 ]->IsObject ());
41
+ CHECK (args[0 ]->IsFunction ());
30
42
CHECK (args[1 ]->IsFunction ());
31
43
CHECK (args[2 ]->IsFunction ());
32
- CHECK (args[3 ]->IsFunction ());
33
-
34
- // Attach Fields enum from Environment::AsyncHooks.
35
- // Flags attached to this object are:
36
- // - kCallInitHook (0): Tells the AsyncWrap constructor whether it should
37
- // make a call to the init JS callback. This is disabled by default, so
38
- // even after setting the callbacks the flag will have to be set to
39
- // non-zero to have those callbacks called. This only affects the init
40
- // callback. If the init callback was called, then the pre/post callbacks
41
- // will automatically be called.
42
- Local<Object> async_hooks_obj = args[0 ].As <Object>();
43
- Environment::AsyncHooks* async_hooks = env->async_hooks ();
44
- async_hooks_obj->SetIndexedPropertiesToExternalArrayData (
45
- async_hooks->fields (),
46
- kExternalUint32Array ,
47
- async_hooks->fields_count ());
48
-
49
- env->set_async_hooks_init_function (args[1 ].As <Function>());
50
- env->set_async_hooks_pre_function (args[2 ].As <Function>());
51
- env->set_async_hooks_post_function (args[3 ].As <Function>());
44
+
45
+ env->set_async_hooks_init_function (args[0 ].As <Function>());
46
+ env->set_async_hooks_pre_function (args[1 ].As <Function>());
47
+ env->set_async_hooks_post_function (args[2 ].As <Function>());
52
48
53
49
env->set_using_asyncwrap (true );
54
50
}
@@ -61,7 +57,9 @@ static void Initialize(Handle<Object> target,
61
57
Isolate* isolate = env->isolate ();
62
58
HandleScope scope (isolate);
63
59
64
- NODE_SET_METHOD (target, " setupHooks" , SetupHooks);
60
+ env->SetMethod (target, " setupHooks" , SetupHooks);
61
+ env->SetMethod (target, " disable" , DisableHooksJS);
62
+ env->SetMethod (target, " enable" , EnableHooksJS);
65
63
66
64
Local<Object> async_providers = Object::New (isolate);
67
65
#define V (PROVIDER ) \
0 commit comments