Skip to content

Commit 6a74d6c

Browse files
committed
src: handle async-listener if not initialized
1 parent 7676b02 commit 6a74d6c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/async-wrap-inl.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ inline AsyncWrap::AsyncWrap(Environment* env,
6161

6262
if (parent_has_async_queue) {
6363
parent_val = parent->object().As<v8::Value>();
64-
env->async_listener_load_function()->Call(process, 1, &parent_val);
64+
Call(env->async_listener_load_function(), process, 1, &parent_val);
6565

6666
if (try_catch.HasCaught())
6767
return;
@@ -71,22 +71,31 @@ inline AsyncWrap::AsyncWrap(Environment* env,
7171
object.As<v8::Value>(),
7272
v8::Integer::NewFromUnsigned(env->isolate(), provider)
7373
};
74-
env->async_listener_run_function()->Call(process, ARRAY_SIZE(val_v), val_v);
74+
Call(env->async_listener_run_function(), process, ARRAY_SIZE(val_v), val_v);
7575

7676
if (!try_catch.HasCaught())
7777
async_flags_ |= HAS_ASYNC_LISTENER;
7878
else
7979
return;
8080

8181
if (parent_has_async_queue)
82-
env->async_listener_unload_function()->Call(process, 1, &parent_val);
82+
Call(env->async_listener_unload_function(), process, 1, &parent_val);
8383
}
8484

8585

8686
inline AsyncWrap::~AsyncWrap() {
8787
}
8888

8989

90+
inline void AsyncWrap::Call(v8::Local<v8::Function> func,
91+
v8::Handle<v8::Object> recv,
92+
size_t argc,
93+
v8::Handle<v8::Value>* argv) {
94+
if (!func->IsUndefined())
95+
func->Call(recv, argc, argv);
96+
}
97+
98+
9099
template <class Type>
91100
inline void AsyncWrap::AddMethods(v8::Local<v8::FunctionTemplate> t) {
92101
NODE_SET_PROTOTYPE_METHOD(t, "_removeAsyncQueue", RemoveAsyncQueue<Type>);
@@ -118,7 +127,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
118127

119128
if (has_async_queue()) {
120129
v8::Local<v8::Value> val = context.As<v8::Value>();
121-
env()->async_listener_load_function()->Call(process, 1, &val);
130+
Call(env()->async_listener_load_function(), process, 1, &val);
122131

123132
if (try_catch.HasCaught())
124133
return v8::Undefined(env()->isolate());
@@ -164,7 +173,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
164173

165174
if (has_async_queue()) {
166175
v8::Local<v8::Value> val = context.As<v8::Value>();
167-
env()->async_listener_unload_function()->Call(process, 1, &val);
176+
Call(env()->async_listener_unload_function(), process, 1, &val);
168177

169178
if (try_catch.HasCaught())
170179
return Undefined(env()->isolate());

src/async-wrap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ class AsyncWrap : public BaseObject {
6464
template <class Type>
6565
static inline void AddMethods(v8::Local<v8::FunctionTemplate> t);
6666

67+
inline void Call(v8::Local<v8::Function> func,
68+
v8::Handle<v8::Object> recv,
69+
size_t argc,
70+
v8::Handle<v8::Value>* argv);
71+
6772
inline bool has_async_queue();
6873

6974
inline ProviderType provider_type() const;

0 commit comments

Comments
 (0)