Skip to content

Instantly share code, notes, and snippets.

@rectalogic
Created April 5, 2012 17:01
Show Gist options
  • Save rectalogic/2312526 to your computer and use it in GitHub Desktop.
Save rectalogic/2312526 to your computer and use it in GitHub Desktop.
template dispatching to pointer to member function
template<class T, int Arity, v8::Handle<v8::Value> (T::*InvocationCallbackMember)(v8::Arguments const&)>
static v8::Handle<v8::Value> InvocationCallbackDispatcher(v8::Arguments const& args) {
if (args.Length() < Arity)
return ThrowArgCount();
T* object = T::FromV8Object(args.Holder());
if (!object)
return ThrowObjectDisposed();
try {
return ((*object).*(InvocationCallbackMember))(args);
} catch (...) {
return v8::ThrowException(v8::String::New("Caught unknown native exception."));
}
}
////
InvocationCallbackDispatcher<Canvas, 2, &Canvas::Callback_getContext>(args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment