Skip to content

Commit

Permalink
src: handle async-listener if not initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
tjfontaine committed Apr 14, 2014
1 parent 7676b02 commit 6a74d6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/async-wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ inline AsyncWrap::AsyncWrap(Environment* env,

if (parent_has_async_queue) {
parent_val = parent->object().As<v8::Value>();
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;
Expand All @@ -71,22 +71,31 @@ inline AsyncWrap::AsyncWrap(Environment* env,
object.As<v8::Value>(),
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;
else
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);
}


inline AsyncWrap::~AsyncWrap() {
}


inline void AsyncWrap::Call(v8::Local<v8::Function> func,
v8::Handle<v8::Object> recv,
size_t argc,
v8::Handle<v8::Value>* argv) {
if (!func->IsUndefined())
func->Call(recv, argc, argv);
}


template <class Type>
inline void AsyncWrap::AddMethods(v8::Local<v8::FunctionTemplate> t) {
NODE_SET_PROTOTYPE_METHOD(t, "_removeAsyncQueue", RemoveAsyncQueue<Type>);
Expand Down Expand Up @@ -118,7 +127,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(

if (has_async_queue()) {
v8::Local<v8::Value> val = context.As<v8::Value>();
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());
Expand Down Expand Up @@ -164,7 +173,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(

if (has_async_queue()) {
v8::Local<v8::Value> val = context.As<v8::Value>();
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());
Expand Down
5 changes: 5 additions & 0 deletions src/async-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class AsyncWrap : public BaseObject {
template <class Type>
static inline void AddMethods(v8::Local<v8::FunctionTemplate> t);

inline void Call(v8::Local<v8::Function> func,
v8::Handle<v8::Object> recv,
size_t argc,
v8::Handle<v8::Value>* argv);

inline bool has_async_queue();

inline ProviderType provider_type() const;
Expand Down

0 comments on commit 6a74d6c

Please sign in to comment.