Fix event_loop_dispatcher

This commit is contained in:
blagoev 2017-05-17 16:06:21 +03:00
parent 33bb01be11
commit 4751aca0dc
4 changed files with 25 additions and 2 deletions

View File

@ -50,7 +50,11 @@ private:
struct State {
public:
State(std::function<void(Args...)> func) : m_func(func), m_signal(nullptr) { }
State(std::function<void(Args...)> func) :
m_func(func),
m_signal(nullptr)
{
}
const std::function<void(Args...)> m_func;
std::queue<Tuple> 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<EventLoopSignal<Callback>> m_signal;

View File

@ -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<size_t N> static ValueType call(ContextType ctx, const FunctionType &function,
const ObjectType &this_object, const ValueType (&arguments)[N])

View File

@ -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;

View File

@ -36,6 +36,19 @@ inline v8::Local<v8::Value> node::Function::call(v8::Isolate* isolate, const v8:
return result.ToLocalChecked();
}
template<>
inline v8::Local<v8::Value> node::Function::callback(v8::Isolate* isolate, const v8::Local<v8::Function> &function, const v8::Local<v8::Object> &this_object, size_t argc, const v8::Local<v8::Value> arguments[]) {
Nan::TryCatch trycatch;
auto recv = this_object.IsEmpty() ? isolate->GetCurrentContext()->Global() : this_object;
auto result = Nan::MakeCallback(recv, function, (int)argc, const_cast<v8::Local<v8::Value>*>(arguments));
if (trycatch.HasCaught()) {
throw node::Exception(isolate, trycatch.Exception());
}
return result;
}
template<>
inline v8::Local<v8::Object> node::Function::construct(v8::Isolate* isolate, const v8::Local<v8::Function> &function, size_t argc, const v8::Local<v8::Value> arguments[]) {
Nan::TryCatch trycatch;