Index: gin/function_template.h |
diff --git a/gin/function_template.h b/gin/function_template.h |
index fe95f519ef8a5ddb8e943f6148d2e16068b55d78..7ba54b5910ef4ffcb032deba86a8490a0fba72ef 100644 |
--- a/gin/function_template.h |
+++ b/gin/function_template.h |
@@ -501,6 +501,20 @@ v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( |
holder->GetHandle(isolate))); |
} |
+// CreateFunctionHandler installs a CallAsFunction handler on the given |
+// object template that forwards to a provided C++ function or base::Callback. |
+template<typename Sig> |
+void CreateFunctionHandler(v8::Isolate* isolate, |
+ v8::Local<v8::ObjectTemplate> tmpl, |
+ const base::Callback<Sig> callback, |
+ int callback_flags = 0) { |
+ typedef internal::CallbackHolder<Sig> HolderT; |
+ HolderT* holder = new HolderT(isolate, callback, callback_flags); |
+ tmpl->SetCallAsFunctionHandler(&internal::Dispatcher<Sig>::DispatchToCallback, |
+ ConvertToV8<v8::Handle<v8::External> >( |
+ isolate, holder->GetHandle(isolate))); |
+} |
+ |
} // namespace gin |
#endif // GIN_FUNCTION_TEMPLATE_H_ |