From 2593c1413155a42604c53327b9c2b23b017f0dfa Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Wed, 12 Nov 2014 15:58:23 -0800 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 220f9eb..1ed8d67 100644 --- a/node.gyp +++ b/node.gyp @@ -88,6 +88,7 @@ ], 'sources': [ + '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 bcfa19d..f3270c9 100644 --- a/src/async-wrap-inl.h +++ b/src/async-wrap-inl.h @@ -51,134 +51,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) { - assert(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, NULL); - 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, NULL); - 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, NULL); - - 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); - - assert(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, NULL); - - 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 0000000..6f3f1e9 --- /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, NULL); + 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, NULL); + 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, NULL); + + 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, NULL); + + 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 f383ac9..1d30a3b 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); -- 2.7.4