diff options
Diffstat (limited to 'gin/object_template_builder.h')
-rw-r--r-- | gin/object_template_builder.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gin/object_template_builder.h b/gin/object_template_builder.h index 6367b71..768f4c8 100644 --- a/gin/object_template_builder.h +++ b/gin/object_template_builder.h @@ -27,6 +27,11 @@ struct CallbackTraits { T callback) { return CreateFunctionTemplate(isolate, base::Bind(callback)); } + static void SetAsFunctionHandler(v8::Isolate* isolate, + v8::Local<v8::ObjectTemplate> tmpl, + T callback) { + CreateFunctionHandler(isolate, tmpl, base::Bind(callback)); + } }; // Specialization for base::Callback. @@ -36,6 +41,11 @@ struct CallbackTraits<base::Callback<T> > { v8::Isolate* isolate, const base::Callback<T>& callback) { return CreateFunctionTemplate(isolate, callback); } + static void SetAsFunctionHandler(v8::Isolate* isolate, + v8::Local<v8::ObjectTemplate> tmpl, + const base::Callback<T>& callback) { + CreateFunctionHandler(isolate, tmpl, callback); + } }; // Specialization for member function pointers. We need to handle this case @@ -50,6 +60,12 @@ struct CallbackTraits<T, typename base::enable_if< return CreateFunctionTemplate(isolate, base::Bind(callback), HolderIsFirstArgument); } + static void SetAsFunctionHandler(v8::Isolate* isolate, + v8::Local<v8::ObjectTemplate> tmpl, + T callback) { + CreateFunctionHandler( + isolate, tmpl, base::Bind(callback), HolderIsFirstArgument); + } }; // This specialization allows people to construct function templates directly if @@ -103,6 +119,11 @@ class GIN_EXPORT ObjectTemplateBuilder { CallbackTraits<T>::CreateTemplate(isolate_, getter), CallbackTraits<U>::CreateTemplate(isolate_, setter)); } + template<typename T> + ObjectTemplateBuilder& SetCallAsFunctionHandler(const T& callback) { + CallbackTraits<T>::SetAsFunctionHandler(isolate_, template_, callback); + return *this; + } v8::Local<v8::ObjectTemplate> Build(); |