Add MakeCallback method abstraction

Needed for node to kick next tick properly. JSC uses regular call
This commit is contained in:
blagoev 2017-05-07 02:02:05 +03:00
parent 9c700053af
commit 44432660ea
3 changed files with 19 additions and 0 deletions

View File

@ -151,6 +151,7 @@ struct Function {
using ObjectType = typename T::Object; using ObjectType = typename T::Object;
using ValueType = typename T::Value; 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[]); static ValueType call(ContextType, const FunctionType &, const ObjectType &, size_t, const ValueType[]);
template<size_t N> static ValueType call(ContextType ctx, const FunctionType &function, template<size_t N> static ValueType call(ContextType ctx, const FunctionType &function,
const ObjectType &this_object, const ValueType (&arguments)[N]) 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; 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<> template<>
inline JSObjectRef jsc::Function::construct(JSContextRef ctx, const JSObjectRef &function, size_t argc, const JSValueRef arguments[]) { inline JSObjectRef jsc::Function::construct(JSContextRef ctx, const JSObjectRef &function, size_t argc, const JSValueRef arguments[]) {
JSValueRef exception = nullptr; 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(); 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<> 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[]) { 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; Nan::TryCatch trycatch;