Chromium Code Reviews| 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: |