Skip to content

Commit bb05cd1

Browse files
trevnorrisMylesBorins
authored andcommitted
async_wrap: mode constructor/destructor to .cc
The constructor and destructor shouldn't have been placed in the -inl.h file from the beginning. Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent c0c5608 commit bb05cd1

File tree

3 files changed

+76
-76
lines changed

3 files changed

+76
-76
lines changed

src/async-wrap-inl.h

-71
Original file line numberDiff line numberDiff line change
@@ -13,77 +13,6 @@
1313

1414
namespace node {
1515

16-
inline AsyncWrap::AsyncWrap(Environment* env,
17-
v8::Local<v8::Object> object,
18-
ProviderType provider,
19-
AsyncWrap* parent)
20-
: BaseObject(env, object), bits_(static_cast<uint32_t>(provider) << 1),
21-
uid_(env->get_async_wrap_uid()) {
22-
CHECK_NE(provider, PROVIDER_NONE);
23-
CHECK_GE(object->InternalFieldCount(), 1);
24-
25-
// Shift provider value over to prevent id collision.
26-
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider);
27-
28-
v8::Local<v8::Function> init_fn = env->async_hooks_init_function();
29-
30-
// No init callback exists, no reason to go on.
31-
if (init_fn.IsEmpty())
32-
return;
33-
34-
// If async wrap callbacks are disabled and no parent was passed that has
35-
// run the init callback then return.
36-
if (!env->async_wrap_callbacks_enabled() &&
37-
(parent == nullptr || !parent->ran_init_callback()))
38-
return;
39-
40-
v8::HandleScope scope(env->isolate());
41-
42-
v8::Local<v8::Value> argv[] = {
43-
v8::Number::New(env->isolate(), get_uid()),
44-
v8::Int32::New(env->isolate(), provider),
45-
Null(env->isolate()),
46-
Null(env->isolate())
47-
};
48-
49-
if (parent != nullptr) {
50-
argv[2] = v8::Number::New(env->isolate(), parent->get_uid());
51-
argv[3] = parent->object();
52-
}
53-
54-
v8::TryCatch try_catch(env->isolate());
55-
56-
v8::MaybeLocal<v8::Value> ret =
57-
init_fn->Call(env->context(), object, arraysize(argv), argv);
58-
59-
if (ret.IsEmpty()) {
60-
ClearFatalExceptionHandlers(env);
61-
FatalException(env->isolate(), try_catch);
62-
}
63-
64-
bits_ |= 1; // ran_init_callback() is true now.
65-
}
66-
67-
68-
inline AsyncWrap::~AsyncWrap() {
69-
if (!ran_init_callback())
70-
return;
71-
72-
v8::Local<v8::Function> fn = env()->async_hooks_destroy_function();
73-
if (!fn.IsEmpty()) {
74-
v8::HandleScope scope(env()->isolate());
75-
v8::Local<v8::Value> uid = v8::Number::New(env()->isolate(), get_uid());
76-
v8::TryCatch try_catch(env()->isolate());
77-
v8::MaybeLocal<v8::Value> ret =
78-
fn->Call(env()->context(), v8::Null(env()->isolate()), 1, &uid);
79-
if (ret.IsEmpty()) {
80-
ClearFatalExceptionHandlers(env());
81-
FatalException(env()->isolate(), try_catch);
82-
}
83-
}
84-
}
85-
86-
8716
inline bool AsyncWrap::ran_init_callback() const {
8817
return static_cast<bool>(bits_ & 1);
8918
}

src/async-wrap.cc

+71
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,77 @@ void LoadAsyncWrapperInfo(Environment* env) {
192192
}
193193

194194

195+
AsyncWrap::AsyncWrap(Environment* env,
196+
Local<Object> object,
197+
ProviderType provider,
198+
AsyncWrap* parent)
199+
: BaseObject(env,object), bits_(static_cast<uint32_t>(provider) << 1),
200+
uid_(env->get_async_wrap_uid()) {
201+
CHECK_NE(provider, PROVIDER_NONE);
202+
CHECK_GE(object->InternalFieldCount(), 1);
203+
204+
// Shift provider value over to prevent id collision.
205+
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider);
206+
207+
Local<Function> init_fn = env->async_hooks_init_function();
208+
209+
// No init callback exists, no reason to go on.
210+
if (init_fn.IsEmpty())
211+
return;
212+
213+
// If async wrap callbacks are disabled and no parent was passed that has
214+
// run the init callback then return.
215+
if (!env->async_wrap_callbacks_enabled() &&
216+
(parent == nullptr || !parent->ran_init_callback()))
217+
return;
218+
219+
HandleScope scope(env->isolate());
220+
221+
Local<Value> argv[] = {
222+
Number::New(env->isolate(), get_uid()),
223+
Int32::New(env->isolate(), provider),
224+
Null(env->isolate()),
225+
Null(env->isolate())
226+
};
227+
228+
if (parent != nullptr) {
229+
argv[2] = Number::New(env->isolate(), parent->get_uid());
230+
argv[3] = parent->object();
231+
}
232+
233+
TryCatch try_catch(env->isolate());
234+
235+
MaybeLocal<Value> ret =
236+
init_fn->Call(env->context(), object, arraysize(argv), argv);
237+
238+
if (ret.IsEmpty()) {
239+
ClearFatalExceptionHandlers(env);
240+
FatalException(env->isolate(), try_catch);
241+
}
242+
243+
bits_ |= 1; // ran_init_callback() is true now.
244+
}
245+
246+
247+
AsyncWrap::~AsyncWrap() {
248+
if (!ran_init_callback())
249+
return;
250+
251+
Local<Function> fn = env()->async_hooks_destroy_function();
252+
if (!fn.IsEmpty()) {
253+
HandleScope scope(env()->isolate());
254+
Local<Value> uid = Number::New(env()->isolate(), get_uid());
255+
TryCatch try_catch(env()->isolate());
256+
MaybeLocal<Value> ret =
257+
fn->Call(env()->context(), Null(env()->isolate()), 1, &uid);
258+
if (ret.IsEmpty()) {
259+
ClearFatalExceptionHandlers(env());
260+
FatalException(env()->isolate(), try_catch);
261+
}
262+
}
263+
}
264+
265+
195266
Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
196267
int argc,
197268
Local<Value>* argv) {

src/async-wrap.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class AsyncWrap : public BaseObject {
4747
#undef V
4848
};
4949

50-
inline AsyncWrap(Environment* env,
51-
v8::Local<v8::Object> object,
52-
ProviderType provider,
53-
AsyncWrap* parent = nullptr);
50+
AsyncWrap(Environment* env,
51+
v8::Local<v8::Object> object,
52+
ProviderType provider,
53+
AsyncWrap* parent = nullptr);
5454

55-
inline virtual ~AsyncWrap();
55+
virtual ~AsyncWrap();
5656

5757
inline ProviderType provider_type() const;
5858

0 commit comments

Comments
 (0)