summaryrefslogtreecommitdiffstats
path: root/gin
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-19 15:18:04 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-19 15:18:04 +0000
commit75a2090ac410946983997301e148bd4cd19e0390 (patch)
tree25b9eb1a0fe2fa013cf08907f2b94bba63efc297 /gin
parenta986af907efccef8657d8c59fdfa21292984f193 (diff)
downloadchromium_src-75a2090ac410946983997301e148bd4cd19e0390.zip
chromium_src-75a2090ac410946983997301e148bd4cd19e0390.tar.gz
chromium_src-75a2090ac410946983997301e148bd4cd19e0390.tar.bz2
[gin] fix casting WrappableBase to a derived class
We first need to cast the void pointer to WrappableBase before we can cast it to the derived class: initially a WrappableBase* is stored as holder, so we can't directly cast it to the derived class. To test this, I added a useless base class so the test object this pointers don't align with the WrappableBase this pointer. Also update the comments about how to use WrappableBase. BUG=none R=aa@chromium.org,dcarney@chromium.org Review URL: https://codereview.chromium.org/119173002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin')
-rw-r--r--gin/wrappable.h13
-rw-r--r--gin/wrappable_unittest.cc14
2 files changed, 20 insertions, 7 deletions
diff --git a/gin/wrappable.h b/gin/wrappable.h
index e20c7f1..ff52b19 100644
--- a/gin/wrappable.h
+++ b/gin/wrappable.h
@@ -31,17 +31,18 @@ GIN_EXPORT void* FromV8Impl(v8::Isolate* isolate,
// static WrapperInfo kWrapperInfo;
//
// // Optional, only required if non-empty template should be used.
-// static v8::Local<v8::ObjectTemplate> GetObjectTemplate(
+// virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
// v8::Isolate* isolate);
// ...
// };
//
// // my_class.cc
-// WrapperInfo MyClass::kWrapperInfo = { kEmbedderNativeGin };
+// WrapperInfo MyClass::kWrapperInfo = {kEmbedderNativeGin};
//
-// v8::Local<v8::ObjectTemplate> MyClass::GetObjectTemplate(
+// gin::ObjectTemplateBuilder MyClass::GetObjectTemplateBuilder(
// v8::Isolate* isolate) {
-// return ObjectTemplateBuilder(isolate).SetValue("foobar", 42).Build();
+// return Wrappable<MyClass>::GetObjectTemplateBuilder(isolate)
+// .SetValue("foobar", 42);
// }
//
// Subclasses should also typically have private constructors and expose a
@@ -104,8 +105,8 @@ struct Converter<T*, typename base::enable_if<
}
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, T** out) {
- *out = static_cast<T*>(internal::FromV8Impl(isolate, val,
- &T::kWrapperInfo));
+ *out = static_cast<T*>(static_cast<WrappableBase*>(
+ internal::FromV8Impl(isolate, val, &T::kWrapperInfo)));
return *out != NULL;
}
};
diff --git a/gin/wrappable_unittest.cc b/gin/wrappable_unittest.cc
index ad8b6b7..2428dc1 100644
--- a/gin/wrappable_unittest.cc
+++ b/gin/wrappable_unittest.cc
@@ -15,7 +15,19 @@
namespace gin {
-class MyObject : public Wrappable<MyObject> {
+class BaseClass {
+ public:
+ BaseClass() : value_(23) {}
+ virtual ~BaseClass() {}
+
+ private:
+ int value_;
+
+ DISALLOW_COPY_AND_ASSIGN(BaseClass);
+};
+
+class MyObject : public BaseClass,
+ public Wrappable<MyObject> {
public:
static WrapperInfo kWrapperInfo;