Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: gin/wrappable.h

Issue 113893005: [gin] Introduce Wrappable::GetObjectTemplate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gin/object_template_builder.cc ('k') | gin/wrappable.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/wrappable.h
diff --git a/gin/wrappable.h b/gin/wrappable.h
index 755707166bb3c39fa19e4365eda69239d860f07c..fccca1ac4aa46d03a228fac26d05ce2da116209e 100644
--- a/gin/wrappable.h
+++ b/gin/wrappable.h
@@ -27,11 +27,22 @@ GIN_EXPORT void* FromV8Impl(v8::Isolate* isolate,
// USAGE:
// // my_class.h
// class MyClass : Wrappable<MyClass> {
+// public:
+// static WrapperInfo kWrapperInfo;
+//
+// // Optional, only required if non-empty template should be used.
+// static v8::Local<v8::ObjectTemplate> GetObjectTemplate(
+// v8::Isolate* isolate);
// ...
// };
//
// // my_class.cc
-// INIT_WRAPABLE(MyClass);
+// WrapperInfo MyClass::kWrapperInfo = { kEmbedderNativeGin };
+//
+// v8::Local<v8::ObjectTemplate> MyClass::GetObjectTemplate(
+// v8::Isolate* isolate) {
+// return ObjectTemplateBuilder(isolate).SetValue("foobar", 42).Build();
+// }
//
// Subclasses should also typically have private constructors and expose a
// static Create function that returns a gin::Handle. Forcing creators through
@@ -46,18 +57,30 @@ class Wrappable;
// Non-template base class to share code between templates instances.
class GIN_EXPORT WrappableBase {
protected:
+ typedef v8::Local<v8::ObjectTemplate>(*GetObjectTemplateFunction)(
+ v8::Isolate*);
+
WrappableBase();
virtual ~WrappableBase();
- v8::Handle<v8::Object> GetWrapperImpl(v8::Isolate* isolate,
- WrapperInfo* wrapper_info);
- v8::Handle<v8::Object> CreateWrapper(v8::Isolate* isolate,
- WrapperInfo* wrapper_info);
- v8::Persistent<v8::Object> wrapper_; // Weak
+
+ v8::Handle<v8::Object> GetWrapperImpl(
+ v8::Isolate* isolate,
+ WrapperInfo* wrapper_info,
+ GetObjectTemplateFunction template_getter);
+
+ static v8::Local<v8::ObjectTemplate> GetObjectTemplate(v8::Isolate* isolate);
private:
static void WeakCallback(
const v8::WeakCallbackData<v8::Object, WrappableBase>& data);
+ v8::Handle<v8::Object> CreateWrapper(
+ v8::Isolate* isolate,
+ WrapperInfo* wrapper_info,
+ GetObjectTemplateFunction template_getter);
+
+ v8::Persistent<v8::Object> wrapper_; // Weak
+
DISALLOW_COPY_AND_ASSIGN(WrappableBase);
};
@@ -69,7 +92,7 @@ class Wrappable : public WrappableBase {
// To customize the wrapper created for a subclass, override GetWrapperInfo()
// instead of overriding this function.
v8::Handle<v8::Object> GetWrapper(v8::Isolate* isolate) {
- return GetWrapperImpl(isolate, &T::kWrapperInfo);
+ return GetWrapperImpl(isolate, &T::kWrapperInfo, &T::GetObjectTemplate);
}
protected:
« no previous file with comments | « gin/object_template_builder.cc ('k') | gin/wrappable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698