Created
January 15, 2016 13:19
-
-
Save xaxxon/4a110e192e3ca61a9e9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Specialization for methods that don't return void. Sets v8::FunctionCallbackInfo::GetReturnValue to value returned by the method | |
*/ | |
template<typename RETURN_TYPE, typename CLASS_TYPE, typename ... PARAMETERS> | |
struct RunMethod<RETURN_TYPE(CLASS_TYPE::*)(PARAMETERS...)>{ | |
typedef RETURN_TYPE(CLASS_TYPE::*METHOD_TYPE)(PARAMETERS...); | |
void operator()(CLASS_TYPE & object, METHOD_TYPE method, const v8::FunctionCallbackInfo<v8::Value> & info, PARAMETERS... parameters) { | |
RETURN_TYPE return_value = (object.*method)(parameters...); | |
auto casted_result = CastToJS<RETURN_TYPE>()(info.GetIsolate(), return_value); | |
info.GetReturnValue().Set(casted_result); | |
} | |
}; | |
// const method version | |
template<typename RETURN_TYPE, typename CLASS_TYPE, typename ... PARAMETERS> | |
struct RunMethod<RETURN_TYPE(CLASS_TYPE::*)(PARAMETERS...) const>{ | |
typedef RETURN_TYPE(CLASS_TYPE::*METHOD_TYPE)(PARAMETERS...) const; | |
void operator()(CLASS_TYPE & object, METHOD_TYPE method, const v8::FunctionCallbackInfo<v8::Value> & info, PARAMETERS... parameters) { | |
RETURN_TYPE return_value = (object.*method)(parameters...); | |
auto casted_result = CastToJS<RETURN_TYPE>()(info.GetIsolate(), return_value); | |
info.GetReturnValue().Set(casted_result); | |
} | |
}; | |
/** | |
* Specialization for methods that return void. No value set for v8::FunctionCallbackInfo::GetReturnValue | |
* The javascript call will return the javascript "undefined" value | |
*/ | |
template<typename CLASS_TYPE, typename ... PARAMETERS> | |
struct RunMethod<void(CLASS_TYPE::*)(PARAMETERS...)> { | |
typedef void(CLASS_TYPE::*METHOD_TYPE)(PARAMETERS...); | |
void operator()(CLASS_TYPE & object, METHOD_TYPE method, const v8::FunctionCallbackInfo<v8::Value> &, PARAMETERS... parameters) { | |
(object.*method)(parameters...); | |
} | |
}; | |
// const method version | |
template<typename CLASS_TYPE, typename ... PARAMETERS> | |
struct RunMethod<void(CLASS_TYPE::*)(PARAMETERS...) const> { | |
typedef void(CLASS_TYPE::*METHOD_TYPE)(PARAMETERS...) const; | |
void operator()(CLASS_TYPE & object, METHOD_TYPE method, const v8::FunctionCallbackInfo<v8::Value> &, PARAMETERS... parameters) { | |
(object.*method)(parameters...); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment