Skip to content

Commit 5d17b16

Browse files
trevnorrispiscisaureus
authored andcommitted
async-wrap: move MakeCallback to .cc
MakeCallback is too large a function to be inlined. Likewise, only having header files will not allow for any part of AsyncWrap to be exposed cleanly via NODE_MODULE_CONTEXT_AWARE_BUILTIN(). PR-URL: nodejs/node-v0.x-archive#8110 Signed-off-by: Trevor Norris <[email protected]> Reviewed-by: Fedor Indutny <[email protected]> Reviewed-by: Alexis Campailla <[email protected]> Reviewed-by: Julien Gilli <[email protected]>
1 parent 0d60ab3 commit 5d17b16

File tree

4 files changed

+169
-132
lines changed

4 files changed

+169
-132
lines changed

node.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
'sources': [
9191
'src/debug-agent.cc',
92+
'src/async-wrap.cc',
9293
'src/fs_event_wrap.cc',
9394
'src/cares_wrap.cc',
9495
'src/handle_wrap.cc',

src/async-wrap-inl.h

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -46,134 +46,6 @@ inline uint32_t AsyncWrap::provider_type() const {
4646
}
4747

4848

49-
// I hate you domains.
50-
inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
51-
const v8::Handle<v8::Function> cb,
52-
int argc,
53-
v8::Handle<v8::Value>* argv) {
54-
CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
55-
56-
v8::Local<v8::Object> context = object();
57-
v8::Local<v8::Object> process = env()->process_object();
58-
v8::Local<v8::Value> domain_v = context->Get(env()->domain_string());
59-
v8::Local<v8::Object> domain;
60-
61-
v8::TryCatch try_catch;
62-
try_catch.SetVerbose(true);
63-
64-
bool has_domain = domain_v->IsObject();
65-
if (has_domain) {
66-
domain = domain_v.As<v8::Object>();
67-
68-
if (domain->Get(env()->disposed_string())->IsTrue())
69-
return Undefined(env()->isolate());
70-
71-
v8::Local<v8::Function> enter =
72-
domain->Get(env()->enter_string()).As<v8::Function>();
73-
if (enter->IsFunction()) {
74-
enter->Call(domain, 0, nullptr);
75-
if (try_catch.HasCaught())
76-
return Undefined(env()->isolate());
77-
}
78-
}
79-
80-
v8::Local<v8::Value> ret = cb->Call(context, argc, argv);
81-
82-
if (try_catch.HasCaught()) {
83-
return Undefined(env()->isolate());
84-
}
85-
86-
if (has_domain) {
87-
v8::Local<v8::Function> exit =
88-
domain->Get(env()->exit_string()).As<v8::Function>();
89-
if (exit->IsFunction()) {
90-
exit->Call(domain, 0, nullptr);
91-
if (try_catch.HasCaught())
92-
return Undefined(env()->isolate());
93-
}
94-
}
95-
96-
Environment::TickInfo* tick_info = env()->tick_info();
97-
98-
if (tick_info->in_tick()) {
99-
return ret;
100-
}
101-
102-
if (tick_info->length() == 0) {
103-
env()->isolate()->RunMicrotasks();
104-
}
105-
106-
if (tick_info->length() == 0) {
107-
tick_info->set_index(0);
108-
return ret;
109-
}
110-
111-
tick_info->set_in_tick(true);
112-
113-
env()->tick_callback_function()->Call(process, 0, nullptr);
114-
115-
tick_info->set_in_tick(false);
116-
117-
if (try_catch.HasCaught()) {
118-
tick_info->set_last_threw(true);
119-
return Undefined(env()->isolate());
120-
}
121-
122-
return ret;
123-
}
124-
125-
126-
inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
127-
const v8::Handle<v8::Function> cb,
128-
int argc,
129-
v8::Handle<v8::Value>* argv) {
130-
if (env()->using_domains())
131-
return MakeDomainCallback(cb, argc, argv);
132-
133-
CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
134-
135-
v8::Local<v8::Object> context = object();
136-
v8::Local<v8::Object> process = env()->process_object();
137-
138-
v8::TryCatch try_catch;
139-
try_catch.SetVerbose(true);
140-
141-
v8::Local<v8::Value> ret = cb->Call(context, argc, argv);
142-
143-
if (try_catch.HasCaught()) {
144-
return Undefined(env()->isolate());
145-
}
146-
147-
Environment::TickInfo* tick_info = env()->tick_info();
148-
149-
if (tick_info->in_tick()) {
150-
return ret;
151-
}
152-
153-
if (tick_info->length() == 0) {
154-
env()->isolate()->RunMicrotasks();
155-
}
156-
157-
if (tick_info->length() == 0) {
158-
tick_info->set_index(0);
159-
return ret;
160-
}
161-
162-
tick_info->set_in_tick(true);
163-
164-
env()->tick_callback_function()->Call(process, 0, nullptr);
165-
166-
tick_info->set_in_tick(false);
167-
168-
if (try_catch.HasCaught()) {
169-
tick_info->set_last_threw(true);
170-
return Undefined(env()->isolate());
171-
}
172-
173-
return ret;
174-
}
175-
176-
17749
inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
17850
const v8::Handle<v8::String> symbol,
17951
int argc,

src/async-wrap.cc

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
#include "async-wrap.h"
23+
#include "async-wrap-inl.h"
24+
#include "env.h"
25+
#include "env-inl.h"
26+
#include "util.h"
27+
#include "util-inl.h"
28+
29+
#include "v8.h"
30+
31+
using v8::Function;
32+
using v8::Handle;
33+
using v8::Local;
34+
using v8::Object;
35+
using v8::TryCatch;
36+
using v8::Value;
37+
38+
namespace node {
39+
40+
Handle<Value> AsyncWrap::MakeDomainCallback(const Handle<Function> cb,
41+
int argc,
42+
Handle<Value>* argv) {
43+
CHECK(env()->context() == env()->isolate()->GetCurrentContext());
44+
45+
Local<Object> context = object();
46+
Local<Object> process = env()->process_object();
47+
Local<Value> domain_v = context->Get(env()->domain_string());
48+
Local<Object> domain;
49+
50+
TryCatch try_catch;
51+
try_catch.SetVerbose(true);
52+
53+
bool has_domain = domain_v->IsObject();
54+
if (has_domain) {
55+
domain = domain_v.As<Object>();
56+
57+
if (domain->Get(env()->disposed_string())->IsTrue())
58+
return Undefined(env()->isolate());
59+
60+
Local<Function> enter =
61+
domain->Get(env()->enter_string()).As<Function>();
62+
if (enter->IsFunction()) {
63+
enter->Call(domain, 0, nullptr);
64+
if (try_catch.HasCaught())
65+
return Undefined(env()->isolate());
66+
}
67+
}
68+
69+
Local<Value> ret = cb->Call(context, argc, argv);
70+
71+
if (try_catch.HasCaught()) {
72+
return Undefined(env()->isolate());
73+
}
74+
75+
if (has_domain) {
76+
Local<Function> exit =
77+
domain->Get(env()->exit_string()).As<Function>();
78+
if (exit->IsFunction()) {
79+
exit->Call(domain, 0, nullptr);
80+
if (try_catch.HasCaught())
81+
return Undefined(env()->isolate());
82+
}
83+
}
84+
85+
Environment::TickInfo* tick_info = env()->tick_info();
86+
87+
if (tick_info->in_tick()) {
88+
return ret;
89+
}
90+
91+
if (tick_info->length() == 0) {
92+
env()->isolate()->RunMicrotasks();
93+
}
94+
95+
if (tick_info->length() == 0) {
96+
tick_info->set_index(0);
97+
return ret;
98+
}
99+
100+
tick_info->set_in_tick(true);
101+
102+
env()->tick_callback_function()->Call(process, 0, nullptr);
103+
104+
tick_info->set_in_tick(false);
105+
106+
if (try_catch.HasCaught()) {
107+
tick_info->set_last_threw(true);
108+
return Undefined(env()->isolate());
109+
}
110+
111+
return ret;
112+
}
113+
114+
115+
Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb,
116+
int argc,
117+
Handle<Value>* argv) {
118+
if (env()->using_domains())
119+
return MakeDomainCallback(cb, argc, argv);
120+
121+
CHECK(env()->context() == env()->isolate()->GetCurrentContext());
122+
123+
Local<Object> context = object();
124+
Local<Object> process = env()->process_object();
125+
126+
TryCatch try_catch;
127+
try_catch.SetVerbose(true);
128+
129+
Local<Value> ret = cb->Call(context, argc, argv);
130+
131+
if (try_catch.HasCaught()) {
132+
return Undefined(env()->isolate());
133+
}
134+
135+
Environment::TickInfo* tick_info = env()->tick_info();
136+
137+
if (tick_info->in_tick()) {
138+
return ret;
139+
}
140+
141+
if (tick_info->length() == 0) {
142+
env()->isolate()->RunMicrotasks();
143+
}
144+
145+
if (tick_info->length() == 0) {
146+
tick_info->set_index(0);
147+
return ret;
148+
}
149+
150+
tick_info->set_in_tick(true);
151+
152+
env()->tick_callback_function()->Call(process, 0, nullptr);
153+
154+
tick_info->set_in_tick(false);
155+
156+
if (try_catch.HasCaught()) {
157+
tick_info->set_last_threw(true);
158+
return Undefined(env()->isolate());
159+
}
160+
161+
return ret;
162+
}
163+
164+
} // namespace node

src/async-wrap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class AsyncWrap : public BaseObject {
6161
inline uint32_t provider_type() const;
6262

6363
// Only call these within a valid HandleScope.
64-
inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
65-
int argc,
66-
v8::Handle<v8::Value>* argv);
64+
v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
65+
int argc,
66+
v8::Handle<v8::Value>* argv);
6767
inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::String> symbol,
6868
int argc,
6969
v8::Handle<v8::Value>* argv);
@@ -76,7 +76,7 @@ class AsyncWrap : public BaseObject {
7676

7777
// TODO(trevnorris): BURN IN FIRE! Remove this as soon as a suitable
7878
// replacement is committed.
79-
inline v8::Handle<v8::Value> MakeDomainCallback(
79+
v8::Handle<v8::Value> MakeDomainCallback(
8080
const v8::Handle<v8::Function> cb,
8181
int argc,
8282
v8::Handle<v8::Value>* argv);

0 commit comments

Comments
 (0)