From 2e62914837ecd91e708a1a1427de33f75de14475 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Tue, 9 Dec 2014 04:55:48 +0100 Subject: [PATCH] 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: https://github.com/joyent/node/pull/8110 Signed-off-by: Trevor Norris Reviewed-by: Fedor Indutny Reviewed-by: Alexis Campailla Reviewed-by: Julien Gilli --- node.gyp | 1 + src/async-wrap-inl.h | 128 --------------------------------- src/async-wrap.cc | 164 +++++++++++++++++++++++++++++++++++++++++++ src/async-wrap.h | 8 +-- 4 files changed, 169 insertions(+), 132 deletions(-) create mode 100644 src/async-wrap.cc diff --git a/node.gyp b/node.gyp index 8615bf72736f7e..c2d0b0a94aa946 100644 --- a/node.gyp +++ b/node.gyp @@ -89,6 +89,7 @@ 'sources': [ 'src/debug-agent.cc', + 'src/async-wrap.cc', 'src/fs_event_wrap.cc', 'src/cares_wrap.cc', 'src/handle_wrap.cc', diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h index d64aeab2c7e6b7..38a5c7fd237a7f 100644 --- a/src/async-wrap-inl.h +++ b/src/async-wrap-inl.h @@ -46,134 +46,6 @@ inline uint32_t AsyncWrap::provider_type() const { } -// I hate you domains. -inline v8::Handle AsyncWrap::MakeDomainCallback( - const v8::Handle cb, - int argc, - v8::Handle* argv) { - CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext()); - - v8::Local context = object(); - v8::Local process = env()->process_object(); - v8::Local domain_v = context->Get(env()->domain_string()); - v8::Local domain; - - v8::TryCatch try_catch; - try_catch.SetVerbose(true); - - bool has_domain = domain_v->IsObject(); - if (has_domain) { - domain = domain_v.As(); - - if (domain->Get(env()->disposed_string())->IsTrue()) - return Undefined(env()->isolate()); - - v8::Local enter = - domain->Get(env()->enter_string()).As(); - if (enter->IsFunction()) { - enter->Call(domain, 0, nullptr); - if (try_catch.HasCaught()) - return Undefined(env()->isolate()); - } - } - - v8::Local ret = cb->Call(context, argc, argv); - - if (try_catch.HasCaught()) { - return Undefined(env()->isolate()); - } - - if (has_domain) { - v8::Local exit = - domain->Get(env()->exit_string()).As(); - if (exit->IsFunction()) { - exit->Call(domain, 0, nullptr); - 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; -} - - -inline v8::Handle AsyncWrap::MakeCallback( - const v8::Handle cb, - int argc, - v8::Handle* argv) { - if (env()->using_domains()) - return MakeDomainCallback(cb, argc, argv); - - CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext()); - - v8::Local context = object(); - v8::Local process = env()->process_object(); - - v8::TryCatch try_catch; - try_catch.SetVerbose(true); - - v8::Local 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; -} - - inline v8::Handle AsyncWrap::MakeCallback( const v8::Handle symbol, int argc, diff --git a/src/async-wrap.cc b/src/async-wrap.cc new file mode 100644 index 00000000000000..0bf52b0da30d25 --- /dev/null +++ b/src/async-wrap.cc @@ -0,0 +1,164 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +#include "async-wrap.h" +#include "async-wrap-inl.h" +#include "env.h" +#include "env-inl.h" +#include "util.h" +#include "util-inl.h" + +#include "v8.h" + +using v8::Function; +using v8::Handle; +using v8::Local; +using v8::Object; +using v8::TryCatch; +using v8::Value; + +namespace node { + +Handle AsyncWrap::MakeDomainCallback(const Handle cb, + int argc, + Handle* argv) { + CHECK(env()->context() == env()->isolate()->GetCurrentContext()); + + Local context = object(); + Local process = env()->process_object(); + Local domain_v = context->Get(env()->domain_string()); + Local domain; + + TryCatch try_catch; + try_catch.SetVerbose(true); + + bool has_domain = domain_v->IsObject(); + if (has_domain) { + domain = domain_v.As(); + + if (domain->Get(env()->disposed_string())->IsTrue()) + return Undefined(env()->isolate()); + + Local enter = + domain->Get(env()->enter_string()).As(); + if (enter->IsFunction()) { + enter->Call(domain, 0, nullptr); + if (try_catch.HasCaught()) + return Undefined(env()->isolate()); + } + } + + Local ret = cb->Call(context, argc, argv); + + if (try_catch.HasCaught()) { + return Undefined(env()->isolate()); + } + + if (has_domain) { + Local exit = + domain->Get(env()->exit_string()).As(); + if (exit->IsFunction()) { + exit->Call(domain, 0, nullptr); + 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; +} + + +Handle AsyncWrap::MakeCallback(const Handle cb, + int argc, + Handle* argv) { + if (env()->using_domains()) + return MakeDomainCallback(cb, argc, argv); + + CHECK(env()->context() == env()->isolate()->GetCurrentContext()); + + Local context = object(); + Local process = env()->process_object(); + + TryCatch try_catch; + try_catch.SetVerbose(true); + + Local 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 diff --git a/src/async-wrap.h b/src/async-wrap.h index bac927fc815b7f..9393c4c3457cfb 100644 --- a/src/async-wrap.h +++ b/src/async-wrap.h @@ -61,9 +61,9 @@ class AsyncWrap : public BaseObject { inline uint32_t provider_type() const; // Only call these within a valid HandleScope. - inline v8::Handle MakeCallback(const v8::Handle cb, - int argc, - v8::Handle* argv); + v8::Handle MakeCallback(const v8::Handle cb, + int argc, + v8::Handle* argv); inline v8::Handle MakeCallback(const v8::Handle symbol, int argc, v8::Handle* argv); @@ -76,7 +76,7 @@ class AsyncWrap : public BaseObject { // TODO(trevnorris): BURN IN FIRE! Remove this as soon as a suitable // replacement is committed. - inline v8::Handle MakeDomainCallback( + v8::Handle MakeDomainCallback( const v8::Handle cb, int argc, v8::Handle* argv);