diff options
author | Trevor Norris <trev.norris@gmail.com> | 2015-05-04 16:00:37 -0600 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2015-05-04 20:07:56 -0600 |
commit | bd42ba056afe1efe9a4f58f1274d9305c4998a1f (patch) | |
tree | f320f7a4b578d477ff57559c5ce80a2e1b1280ab /src | |
parent | 4b2c78644972cdbeeb498f287640e3d6067a814f (diff) | |
download | android-node-v8-bd42ba056afe1efe9a4f58f1274d9305c4998a1f.tar.gz android-node-v8-bd42ba056afe1efe9a4f58f1274d9305c4998a1f.tar.bz2 android-node-v8-bd42ba056afe1efe9a4f58f1274d9305c4998a1f.zip |
async-wrap: set flags using functions
Setting flags using cryptic numeric object fields is confusing. Instead
use much simpler .enable()/.disable() calls on the async_wrap object.
PR-URL: https://github.com/iojs/io.js/pull/1614
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src')
-rw-r--r-- | src/async-wrap.cc | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 5710c43146..2da6b10293 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -23,32 +23,28 @@ using v8::kExternalUint32Array; namespace node { +static void EnableHooksJS(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + env->async_hooks()->set_enable_callbacks(1); +} + + +static void DisableHooksJS(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + env->async_hooks()->set_enable_callbacks(0); +} + + static void SetupHooks(const FunctionCallbackInfo<Value>& args) { - Environment* env = Environment::GetCurrent(args.GetIsolate()); + Environment* env = Environment::GetCurrent(args); - CHECK(args[0]->IsObject()); + CHECK(args[0]->IsFunction()); CHECK(args[1]->IsFunction()); CHECK(args[2]->IsFunction()); - CHECK(args[3]->IsFunction()); - - // Attach Fields enum from Environment::AsyncHooks. - // Flags attached to this object are: - // - kCallInitHook (0): Tells the AsyncWrap constructor whether it should - // make a call to the init JS callback. This is disabled by default, so - // even after setting the callbacks the flag will have to be set to - // non-zero to have those callbacks called. This only affects the init - // callback. If the init callback was called, then the pre/post callbacks - // will automatically be called. - Local<Object> async_hooks_obj = args[0].As<Object>(); - Environment::AsyncHooks* async_hooks = env->async_hooks(); - async_hooks_obj->SetIndexedPropertiesToExternalArrayData( - async_hooks->fields(), - kExternalUint32Array, - async_hooks->fields_count()); - - env->set_async_hooks_init_function(args[1].As<Function>()); - env->set_async_hooks_pre_function(args[2].As<Function>()); - env->set_async_hooks_post_function(args[3].As<Function>()); + + env->set_async_hooks_init_function(args[0].As<Function>()); + env->set_async_hooks_pre_function(args[1].As<Function>()); + env->set_async_hooks_post_function(args[2].As<Function>()); env->set_using_asyncwrap(true); } @@ -61,7 +57,9 @@ static void Initialize(Handle<Object> target, Isolate* isolate = env->isolate(); HandleScope scope(isolate); - NODE_SET_METHOD(target, "setupHooks", SetupHooks); + env->SetMethod(target, "setupHooks", SetupHooks); + env->SetMethod(target, "disable", DisableHooksJS); + env->SetMethod(target, "enable", EnableHooksJS); Local<Object> async_providers = Object::New(isolate); #define V(PROVIDER) \ |