Skip to content

Commit 517e3a6

Browse files
committed
async_wrap: mode constructor/destructor to .cc
The constructor and destructor shouldn't have been placed in the -inl.h file from the beginning. PR-URL: #9753 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 18016d3 commit 517e3a6

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
@@ -15,77 +15,6 @@
1515

1616
namespace node {
1717

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

src/async-wrap.cc

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

193193

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

src/async-wrap.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ class AsyncWrap : public BaseObject {
4949
#undef V
5050
};
5151

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

57-
inline virtual ~AsyncWrap();
57+
virtual ~AsyncWrap();
5858

5959
inline ProviderType provider_type() const;
6060

0 commit comments

Comments
 (0)