From 4751aca0dcdf6ba4acc1b2bce85912d9c087085e Mon Sep 17 00:00:00 2001 From: blagoev Date: Wed, 17 May 2017 16:06:21 +0300 Subject: [PATCH] Fix event_loop_dispatcher --- src/event_loop_dispatcher.hpp | 8 ++++++-- src/js_types.hpp | 1 + src/jsc/jsc_function.hpp | 5 +++++ src/node/node_function.hpp | 13 +++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/event_loop_dispatcher.hpp b/src/event_loop_dispatcher.hpp index 0e3ff749..df454fd6 100644 --- a/src/event_loop_dispatcher.hpp +++ b/src/event_loop_dispatcher.hpp @@ -50,7 +50,11 @@ private: struct State { public: - State(std::function func) : m_func(func), m_signal(nullptr) { } + State(std::function func) : + m_func(func), + m_signal(nullptr) + { + } const std::function m_func; std::queue m_invocations; @@ -71,7 +75,7 @@ private: ::_apply_polyfill::apply(tuple, m_state->m_func); m_state->m_invocations.pop(); } - m_state->m_signal = nullptr; + m_state->m_signal.reset(); } }; const std::shared_ptr> m_signal; diff --git a/src/js_types.hpp b/src/js_types.hpp index 8a5a10be..1c6a3aec 100644 --- a/src/js_types.hpp +++ b/src/js_types.hpp @@ -151,6 +151,7 @@ struct Function { using ObjectType = typename T::Object; using ValueType = typename T::Value; + static ValueType callback(ContextType, const FunctionType &, const ObjectType &, size_t, const ValueType[]); static ValueType call(ContextType, const FunctionType &, const ObjectType &, size_t, const ValueType[]); template static ValueType call(ContextType ctx, const FunctionType &function, const ObjectType &this_object, const ValueType (&arguments)[N]) diff --git a/src/jsc/jsc_function.hpp b/src/jsc/jsc_function.hpp index 866c973f..da3f2a3d 100644 --- a/src/jsc/jsc_function.hpp +++ b/src/jsc/jsc_function.hpp @@ -33,6 +33,11 @@ inline JSValueRef jsc::Function::call(JSContextRef ctx, const JSObjectRef &funct return result; } +template<> +inline JSValueRef jsc::Function::callback(JSContextRef ctx, const JSObjectRef &function, const JSObjectRef &this_object, size_t argc, const JSValueRef arguments[]) { + return jsc::Function::call(ctx, function, this_object, argc, arguments); +} + template<> inline JSObjectRef jsc::Function::construct(JSContextRef ctx, const JSObjectRef &function, size_t argc, const JSValueRef arguments[]) { JSValueRef exception = nullptr; diff --git a/src/node/node_function.hpp b/src/node/node_function.hpp index 39e90720..cb07959a 100644 --- a/src/node/node_function.hpp +++ b/src/node/node_function.hpp @@ -36,6 +36,19 @@ inline v8::Local node::Function::call(v8::Isolate* isolate, const v8: return result.ToLocalChecked(); } +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[]) { + Nan::TryCatch trycatch; + + auto recv = this_object.IsEmpty() ? isolate->GetCurrentContext()->Global() : this_object; + auto result = Nan::MakeCallback(recv, function, (int)argc, const_cast*>(arguments)); + + if (trycatch.HasCaught()) { + throw node::Exception(isolate, trycatch.Exception()); + } + return result; +} + template<> inline v8::Local node::Function::construct(v8::Isolate* isolate, const v8::Local &function, size_t argc, const v8::Local arguments[]) { Nan::TryCatch trycatch;