diff --git a/src/node/node_function.hpp b/src/node/node_function.hpp index 56c33498..914dbed7 100644 --- a/src/node/node_function.hpp +++ b/src/node/node_function.hpp @@ -38,6 +38,14 @@ inline v8::Local node::Function::call(v8::Isolate* isolate, const v8: template<> inline v8::Local node::Function::callback(v8::Isolate* isolate, const v8::Local &function, const v8::Local &this_object, size_t argc, const v8::Local arguments[]) { + if (!isolate->GetCallingContext().IsEmpty()) { + // if there are any JavaScript frames on the stack below this one we don't need to + // go through the trouble of calling MakeCallback. MakeCallback is only for when a + // thread with no JavaScript frames on its stack needs to call into JavaScript, like in + // an uv_async callback. + return call(isolate, function, this_object, argc, arguments); + } + v8::TryCatch trycatch(isolate); auto recv = this_object.IsEmpty() ? isolate->GetCurrentContext()->Global() : this_object;