summaryrefslogtreecommitdiff
path: root/src/async-wrap.cc
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2014-12-09 05:24:59 +0100
committerBert Belder <bertbelder@gmail.com>2014-12-09 17:57:14 +0100
commita1da024cab797fd9318e7b754512887a71b1b242 (patch)
tree27eb38774de37c4a5f62252b2f8fef6e7bd49591 /src/async-wrap.cc
parent5d17b16ecceb61c2c9946d8f59093561a8912142 (diff)
downloadnode-new-a1da024cab797fd9318e7b754512887a71b1b242.tar.gz
node, async-wrap: remove MakeDomainCallback
C++ won't deoptimize like JS if specific conditional branches are sporadically met in the future. Combined with the amount of code duplication removal and simplified maintenance complexity, it makes more sense to merge MakeCallback and MakeDomainCallback. Additionally, type casting in V8 before verifying what that type is will cause V8 to abort in debug mode if that type isn't what was expected. Fix this by first checking the v8::Value before casting. PR-URL: https://github.com/joyent/node/pull/8110 Signed-off-by: Trevor Norris <trev.norris@gmail.com> Reviewed-by: Fedor Indutny <fedor@indutny.com> Reviewed-by: Alexis Campailla <alexis@janeasystems.com> Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
Diffstat (limited to 'src/async-wrap.cc')
-rw-r--r--src/async-wrap.cc88
1 files changed, 20 insertions, 68 deletions
diff --git a/src/async-wrap.cc b/src/async-wrap.cc
index 0bf52b0da3..4f742ce21e 100644
--- a/src/async-wrap.cc
+++ b/src/async-wrap.cc
@@ -37,30 +37,33 @@ using v8::Value;
namespace node {
-Handle<Value> AsyncWrap::MakeDomainCallback(const Handle<Function> cb,
- int argc,
- Handle<Value>* argv) {
+Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb,
+ int argc,
+ Handle<Value>* argv) {
CHECK(env()->context() == env()->isolate()->GetCurrentContext());
Local<Object> context = object();
Local<Object> process = env()->process_object();
- Local<Value> domain_v = context->Get(env()->domain_string());
Local<Object> domain;
+ bool has_domain = false;
+
+ if (env()->using_domains()) {
+ Local<Value> domain_v = context->Get(env()->domain_string());
+ has_domain = domain_v->IsObject();
+ if (has_domain) {
+ domain = domain_v.As<Object>();
+ if (domain->Get(env()->disposed_string())->IsTrue())
+ return Undefined(env()->isolate());
+ }
+ }
TryCatch try_catch;
try_catch.SetVerbose(true);
- bool has_domain = domain_v->IsObject();
if (has_domain) {
- domain = domain_v.As<Object>();
-
- if (domain->Get(env()->disposed_string())->IsTrue())
- return Undefined(env()->isolate());
-
- Local<Function> enter =
- domain->Get(env()->enter_string()).As<Function>();
- if (enter->IsFunction()) {
- enter->Call(domain, 0, nullptr);
+ Local<Value> enter_v = domain->Get(env()->enter_string());
+ if (enter_v->IsFunction()) {
+ enter_v.As<Function>()->Call(domain, 0, nullptr);
if (try_catch.HasCaught())
return Undefined(env()->isolate());
}
@@ -73,10 +76,9 @@ Handle<Value> AsyncWrap::MakeDomainCallback(const Handle<Function> cb,
}
if (has_domain) {
- Local<Function> exit =
- domain->Get(env()->exit_string()).As<Function>();
- if (exit->IsFunction()) {
- exit->Call(domain, 0, nullptr);
+ Local<Value> exit_v = domain->Get(env()->exit_string());
+ if (exit_v->IsFunction()) {
+ exit_v.As<Function>()->Call(domain, 0, nullptr);
if (try_catch.HasCaught())
return Undefined(env()->isolate());
}
@@ -111,54 +113,4 @@ Handle<Value> AsyncWrap::MakeDomainCallback(const Handle<Function> cb,
return ret;
}
-
-Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb,
- int argc,
- Handle<Value>* argv) {
- if (env()->using_domains())
- return MakeDomainCallback(cb, argc, argv);
-
- CHECK(env()->context() == env()->isolate()->GetCurrentContext());
-
- Local<Object> context = object();
- Local<Object> process = env()->process_object();
-
- TryCatch try_catch;
- try_catch.SetVerbose(true);
-
- Local<Value> ret = cb->Call(context, argc, argv);
-
- if (try_catch.HasCaught()) {
- return Undefined(env()->isolate());
- }
-
- Environment::TickInfo* tick_info = env()->tick_info();
-
- if (tick_info->in_tick()) {
- return ret;
- }
-
- if (tick_info->length() == 0) {
- env()->isolate()->RunMicrotasks();
- }
-
- if (tick_info->length() == 0) {
- tick_info->set_index(0);
- return ret;
- }
-
- tick_info->set_in_tick(true);
-
- env()->tick_callback_function()->Call(process, 0, nullptr);
-
- tick_info->set_in_tick(false);
-
- if (try_catch.HasCaught()) {
- tick_info->set_last_threw(true);
- return Undefined(env()->isolate());
- }
-
- return ret;
-}
-
} // namespace node