summaryrefslogtreecommitdiffstats
path: root/gin/function_template.h
diff options
context:
space:
mode:
Diffstat (limited to 'gin/function_template.h')
-rw-r--r--gin/function_template.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/gin/function_template.h b/gin/function_template.h
index fe95f51..7ba54b5 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_