Add MakeCallback method abstraction
Needed for node to kick next tick properly. JSC uses regular call
This commit is contained in:
parent
9c700053af
commit
44432660ea
|
@ -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])
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue