diff options
author | Trevor Norris <trev.norris@gmail.com> | 2016-02-22 16:34:35 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2016-03-28 11:32:37 -0600 |
commit | f9938b61418a448a8ef835c1016233e41ed5948e (patch) | |
tree | 33a00ba26059994a56ecc12297a9cde11324428b /src | |
parent | 2dadd8901a85a3e100e8a907b1b64c45dd59eb5a (diff) | |
download | android-node-v8-f9938b61418a448a8ef835c1016233e41ed5948e.tar.gz android-node-v8-f9938b61418a448a8ef835c1016233e41ed5948e.tar.bz2 android-node-v8-f9938b61418a448a8ef835c1016233e41ed5948e.zip |
async_wrap: setupHooks now accepts object
The number of callbacks accepted to setupHooks was getting unwieldy.
Instead change the implementation to accept an object with all callbacks
PR-URL: https://github.com/nodejs/node/pull/5756
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/async-wrap.cc | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/async-wrap.cc b/src/async-wrap.cc index dde07aa075..570ed2f165 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -121,18 +121,35 @@ static void SetupHooks(const FunctionCallbackInfo<Value>& args) { if (env->async_hooks()->callbacks_enabled()) return env->ThrowError("hooks should not be set while also enabled"); - - if (!args[0]->IsFunction()) + if (!args[0]->IsObject()) + return env->ThrowTypeError("first argument must be an object"); + + Local<Object> fn_obj = args[0].As<Object>(); + + Local<Value> init_v = fn_obj->Get( + env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "init")).ToLocalChecked(); + Local<Value> pre_v = fn_obj->Get( + env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "pre")).ToLocalChecked(); + Local<Value> post_v = fn_obj->Get( + env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "post")).ToLocalChecked(); + Local<Value> destroy_v = fn_obj->Get( + env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "destroy")).ToLocalChecked(); + + if (!init_v->IsFunction()) return env->ThrowTypeError("init callback must be a function"); - env->set_async_hooks_init_function(args[0].As<Function>()); + env->set_async_hooks_init_function(init_v.As<Function>()); - if (args[1]->IsFunction()) - env->set_async_hooks_pre_function(args[1].As<Function>()); - if (args[2]->IsFunction()) - env->set_async_hooks_post_function(args[2].As<Function>()); - if (args[3]->IsFunction()) - env->set_async_hooks_destroy_function(args[3].As<Function>()); + if (pre_v->IsFunction()) + env->set_async_hooks_pre_function(pre_v.As<Function>()); + if (post_v->IsFunction()) + env->set_async_hooks_post_function(post_v.As<Function>()); + if (destroy_v->IsFunction()) + env->set_async_hooks_destroy_function(destroy_v.As<Function>()); } |