From 1e58351ace7189166163b2d0268944d1fc5a82df Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Tue, 11 Jul 2017 16:10:22 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20enter=20node::MakeCallback=20if?= =?UTF-8?q?=20we=20have=20a=20calling=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this means we already have JavaScript frames on the execution stack --- src/node/node_function.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) 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;