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

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
Index: gin/wrappable.h
diff --git a/gin/wrappable.h b/gin/wrappable.h
index 755707166bb3c39fa19e4365eda69239d860f07c..649c5ff601a5e2527585c6f8c4af08f3a1a9bcd1 100644
--- a/gin/wrappable.h
+++ b/gin/wrappable.h
@@ -27,11 +27,23 @@ GIN_EXPORT void* FromV8Impl(v8::Isolate* isolate,
// USAGE:
// // my_class.h
// class MyClass : Wrappable<MyClass> {
+// public:
+// static WrapperInfo kWrapperInfo;
+//
+// private:
+// friend class Wrappable<MyClass>;
+// static v8::Local<v8::ObjectTemplate> GetObjectTemplate(
Aaron Boodman 2013/12/16 16:44:26 It's ok for this to be public now (I think before
Aaron Boodman 2013/12/16 16:50:35 Some classes don't want to have any methods or pro
jochen (gone - plz use gerrit) 2013/12/17 14:32:31 Done.
+// 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, &kWrapperInfo).Build();
+// }
//
// Subclasses should also typically have private constructors and expose a
// static Create function that returns a gin::Handle. Forcing creators through
@@ -46,18 +58,25 @@ class Wrappable;
// Non-template base class to share code between templates instances.
class GIN_EXPORT WrappableBase {
protected:
+ typedef v8::Local<v8::ObjectTemplate> (*TemplateBuilder)(v8::Isolate*);
Aaron Boodman 2013/12/16 16:44:26 Confusing name since we also have ObjectTemplateBu
jochen (gone - plz use gerrit) 2013/12/17 14:32:31 Done.
+
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
+ WrapperInfo* wrapper_info,
+ TemplateBuilder builder);
private:
static void WeakCallback(
const v8::WeakCallbackData<v8::Object, WrappableBase>& data);
+ v8::Handle<v8::Object> CreateWrapper(v8::Isolate* isolate,
+ WrapperInfo* wrapper_info,
+ TemplateBuilder builder);
+
+ v8::Persistent<v8::Object> wrapper_; // Weak
+
DISALLOW_COPY_AND_ASSIGN(WrappableBase);
};
@@ -69,7 +88,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:

Powered by Google App Engine
This is Rietveld 408576698