Browse Source

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 <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>
archived-io.js-v0.12
Trevor Norris 10 years ago
committed by Bert Belder
parent
commit
5d17b16ecc
  1. 1
      node.gyp
  2. 128
      src/async-wrap-inl.h
  3. 164
      src/async-wrap.cc
  4. 8
      src/async-wrap.h

1
node.gyp

@ -89,6 +89,7 @@
'sources': [ 'sources': [
'src/debug-agent.cc', 'src/debug-agent.cc',
'src/async-wrap.cc',
'src/fs_event_wrap.cc', 'src/fs_event_wrap.cc',
'src/cares_wrap.cc', 'src/cares_wrap.cc',
'src/handle_wrap.cc', 'src/handle_wrap.cc',

128
src/async-wrap-inl.h

@ -46,134 +46,6 @@ inline uint32_t AsyncWrap::provider_type() const {
} }
// I hate you domains.
inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
const v8::Handle<v8::Function> cb,
int argc,
v8::Handle<v8::Value>* argv) {
CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
v8::Local<v8::Object> context = object();
v8::Local<v8::Object> process = env()->process_object();
v8::Local<v8::Value> domain_v = context->Get(env()->domain_string());
v8::Local<v8::Object> domain;
v8::TryCatch try_catch;
try_catch.SetVerbose(true);
bool has_domain = domain_v->IsObject();
if (has_domain) {
domain = domain_v.As<v8::Object>();
if (domain->Get(env()->disposed_string())->IsTrue())
return Undefined(env()->isolate());
v8::Local<v8::Function> enter =
domain->Get(env()->enter_string()).As<v8::Function>();
if (enter->IsFunction()) {
enter->Call(domain, 0, nullptr);
if (try_catch.HasCaught())
return Undefined(env()->isolate());
}
}
v8::Local<v8::Value> ret = cb->Call(context, argc, argv);
if (try_catch.HasCaught()) {
return Undefined(env()->isolate());
}
if (has_domain) {
v8::Local<v8::Function> exit =
domain->Get(env()->exit_string()).As<v8::Function>();
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<v8::Value> AsyncWrap::MakeCallback(
const v8::Handle<v8::Function> cb,
int argc,
v8::Handle<v8::Value>* argv) {
if (env()->using_domains())
return MakeDomainCallback(cb, argc, argv);
CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
v8::Local<v8::Object> context = object();
v8::Local<v8::Object> process = env()->process_object();
v8::TryCatch try_catch;
try_catch.SetVerbose(true);
v8::Local<v8::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;
}
inline v8::Handle<v8::Value> AsyncWrap::MakeCallback( inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
const v8::Handle<v8::String> symbol, const v8::Handle<v8::String> symbol,
int argc, int argc,

164
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<Value> AsyncWrap::MakeDomainCallback(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;
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);
if (try_catch.HasCaught())
return Undefined(env()->isolate());
}
}
Local<Value> ret = cb->Call(context, argc, argv);
if (try_catch.HasCaught()) {
return Undefined(env()->isolate());
}
if (has_domain) {
Local<Function> exit =
domain->Get(env()->exit_string()).As<Function>();
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<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

8
src/async-wrap.h

@ -61,9 +61,9 @@ class AsyncWrap : public BaseObject {
inline uint32_t provider_type() const; inline uint32_t provider_type() const;
// Only call these within a valid HandleScope. // Only call these within a valid HandleScope.
inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb, v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
int argc, int argc,
v8::Handle<v8::Value>* argv); v8::Handle<v8::Value>* argv);
inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::String> symbol, inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::String> symbol,
int argc, int argc,
v8::Handle<v8::Value>* argv); v8::Handle<v8::Value>* argv);
@ -76,7 +76,7 @@ class AsyncWrap : public BaseObject {
// TODO(trevnorris): BURN IN FIRE! Remove this as soon as a suitable // TODO(trevnorris): BURN IN FIRE! Remove this as soon as a suitable
// replacement is committed. // replacement is committed.
inline v8::Handle<v8::Value> MakeDomainCallback( v8::Handle<v8::Value> MakeDomainCallback(
const v8::Handle<v8::Function> cb, const v8::Handle<v8::Function> cb,
int argc, int argc,
v8::Handle<v8::Value>* argv); v8::Handle<v8::Value>* argv);

Loading…
Cancel
Save