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

Unified Diff: gin/wrappable_unittest.cc

Issue 105743007: Gin: Make it easier to implement Wrappable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blah 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_unittest.cc
diff --git a/gin/wrappable_unittest.cc b/gin/wrappable_unittest.cc
index 8886a7990ccebbe7f1950f7577d25a27a039e962..2a5fd44537dd356aab01789fa682f4f6028640e4 100644
--- a/gin/wrappable_unittest.cc
+++ b/gin/wrappable_unittest.cc
@@ -16,16 +16,13 @@
namespace gin {
namespace {
-class MyObject : public Wrappable {
+class MyObject : public Wrappable<MyObject> {
public:
static gin::Handle<MyObject> Create(v8::Isolate* isolate);
int value() const { return value_; }
void set_value(int value) { value_ = value; }
- static WrapperInfo kWrapperInfo;
- virtual WrapperInfo* GetWrapperInfo() OVERRIDE;
-
private:
MyObject() : value_(0) {}
virtual ~MyObject() {}
@@ -33,68 +30,46 @@ class MyObject : public Wrappable {
int value_;
};
-WrapperInfo MyObject::kWrapperInfo = { kEmbedderNativeGin };
-
gin::Handle<MyObject> MyObject::Create(v8::Isolate* isolate) {
return CreateHandle(isolate, new MyObject());
}
-WrapperInfo* MyObject::GetWrapperInfo() {
- return &kWrapperInfo;
-}
-
-
-class MyObject2 : public Wrappable {
- public:
- MyObject2() {
- }
- static WrapperInfo kWrapperInfo;
- virtual WrapperInfo* GetWrapperInfo() OVERRIDE;
+class MyObject2 : public Wrappable<MyObject2> {
};
-WrapperInfo MyObject2::kWrapperInfo = { kEmbedderNativeGin };
-
-WrapperInfo* MyObject2::GetWrapperInfo() {
- return &kWrapperInfo;
-}
-
-
-class MyObjectBlink : public Wrappable {
- public:
- MyObjectBlink() {
- }
- static WrapperInfo kWrapperInfo;
- virtual WrapperInfo* GetWrapperInfo() OVERRIDE;
+class MyObjectBlink : public Wrappable<MyObjectBlink> {
};
-WrapperInfo MyObjectBlink::kWrapperInfo = { kEmbedderBlink };
-
-WrapperInfo* MyObjectBlink::GetWrapperInfo() {
- return &kWrapperInfo;
-}
-
void RegisterTemplates(v8::Isolate* isolate) {
PerIsolateData* data = PerIsolateData::From(isolate);
- DCHECK(data->GetObjectTemplate(&MyObject::kWrapperInfo).IsEmpty());
+ DCHECK(data->GetObjectTemplate(
+ &WrappableTraits<MyObject>::kWrapperInfo).IsEmpty());
v8::Handle<v8::ObjectTemplate> templ = ObjectTemplateBuilder(isolate)
.SetProperty("value", &MyObject::value, &MyObject::set_value)
.Build();
templ->SetInternalFieldCount(kNumberOfInternalFields);
- data->SetObjectTemplate(&MyObject::kWrapperInfo, templ);
+ data->SetObjectTemplate(&WrappableTraits<MyObject>::kWrapperInfo, templ);
templ = v8::ObjectTemplate::New(isolate);
templ->SetInternalFieldCount(kNumberOfInternalFields);
- data->SetObjectTemplate(&MyObject2::kWrapperInfo, templ);
+ data->SetObjectTemplate(&WrappableTraits<MyObject2>::kWrapperInfo, templ);
templ = v8::ObjectTemplate::New(isolate);
templ->SetInternalFieldCount(kNumberOfInternalFields);
- data->SetObjectTemplate(&MyObjectBlink::kWrapperInfo, templ);
+ data->SetObjectTemplate(&WrappableTraits<MyObjectBlink>::kWrapperInfo, templ);
}
typedef V8Test WrappableTest;
+TEST_F(WrappableTest, WrappableTraitsAreConstant) {
+ // We rely on the fact that WrappableTraits<T>::kWrapperInfo is constant
+ // across translation units. This test ensures that remains the case.
+ EXPECT_EQ(&WrappableTraits<WrappableTraitsTest>::kWrapperInfo,
+ WrappableTraitsTest::GetWrapperInfo());
+}
+
TEST_F(WrappableTest, WrapAndUnwrap) {
v8::Isolate* isolate = instance_->isolate();
v8::HandleScope handle_scope(isolate);

Powered by Google App Engine
This is Rietveld 408576698