diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h index 0e5b63a42b39..c9741300b0a9 100644 --- a/src/async-wrap-inl.h +++ b/src/async-wrap-inl.h @@ -61,7 +61,7 @@ inline AsyncWrap::AsyncWrap(Environment* env, if (parent_has_async_queue) { parent_val = parent->object().As(); - env->async_listener_load_function()->Call(process, 1, &parent_val); + Call(env->async_listener_load_function(), process, 1, &parent_val); if (try_catch.HasCaught()) return; @@ -71,7 +71,7 @@ inline AsyncWrap::AsyncWrap(Environment* env, object.As(), v8::Integer::NewFromUnsigned(env->isolate(), provider) }; - env->async_listener_run_function()->Call(process, ARRAY_SIZE(val_v), val_v); + Call(env->async_listener_run_function(), process, ARRAY_SIZE(val_v), val_v); if (!try_catch.HasCaught()) async_flags_ |= HAS_ASYNC_LISTENER; @@ -79,7 +79,7 @@ inline AsyncWrap::AsyncWrap(Environment* env, return; if (parent_has_async_queue) - env->async_listener_unload_function()->Call(process, 1, &parent_val); + Call(env->async_listener_unload_function(), process, 1, &parent_val); } @@ -87,6 +87,15 @@ inline AsyncWrap::~AsyncWrap() { } +inline void AsyncWrap::Call(v8::Local func, + v8::Handle recv, + size_t argc, + v8::Handle* argv) { + if (!func->IsUndefined()) + func->Call(recv, argc, argv); +} + + template inline void AsyncWrap::AddMethods(v8::Local t) { NODE_SET_PROTOTYPE_METHOD(t, "_removeAsyncQueue", RemoveAsyncQueue); @@ -118,7 +127,7 @@ inline v8::Handle AsyncWrap::MakeCallback( if (has_async_queue()) { v8::Local val = context.As(); - env()->async_listener_load_function()->Call(process, 1, &val); + Call(env()->async_listener_load_function(), process, 1, &val); if (try_catch.HasCaught()) return v8::Undefined(env()->isolate()); @@ -164,7 +173,7 @@ inline v8::Handle AsyncWrap::MakeCallback( if (has_async_queue()) { v8::Local val = context.As(); - env()->async_listener_unload_function()->Call(process, 1, &val); + Call(env()->async_listener_unload_function(), process, 1, &val); if (try_catch.HasCaught()) return Undefined(env()->isolate()); diff --git a/src/async-wrap.h b/src/async-wrap.h index 20ff33ad88ce..455df7ce4c87 100644 --- a/src/async-wrap.h +++ b/src/async-wrap.h @@ -64,6 +64,11 @@ class AsyncWrap : public BaseObject { template static inline void AddMethods(v8::Local t); + inline void Call(v8::Local func, + v8::Handle recv, + size_t argc, + v8::Handle* argv); + inline bool has_async_queue(); inline ProviderType provider_type() const;