OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "gin/arguments.h" | 6 #include "gin/arguments.h" |
7 #include "gin/per_isolate_data.h" | 7 #include "gin/per_isolate_data.h" |
8 #include "gin/public/isolate_holder.h" | 8 #include "gin/public/isolate_holder.h" |
9 #include "gin/test/v8_test.h" | 9 #include "gin/test/v8_test.h" |
10 #include "gin/wrappable.h" | 10 #include "gin/wrappable.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 v8::Isolate* isolate = instance_->isolate(); | 91 v8::Isolate* isolate = instance_->isolate(); |
92 v8::HandleScope handle_scope(isolate); | 92 v8::HandleScope handle_scope(isolate); |
93 | 93 |
94 RegisterTemplate(isolate); | 94 RegisterTemplate(isolate); |
95 scoped_refptr<MyObject> obj = MyObject::Create(); | 95 scoped_refptr<MyObject> obj = MyObject::Create(); |
96 | 96 |
97 v8::Handle<v8::Value> wrapper = ConvertToV8(isolate, obj.get()); | 97 v8::Handle<v8::Value> wrapper = ConvertToV8(isolate, obj.get()); |
98 EXPECT_FALSE(wrapper.IsEmpty()); | 98 EXPECT_FALSE(wrapper.IsEmpty()); |
99 | 99 |
100 MyObject* unwrapped = 0; | 100 MyObject* unwrapped = 0; |
101 EXPECT_TRUE(ConvertFromV8(wrapper, &unwrapped)); | 101 EXPECT_TRUE(ConvertFromV8(isolate, wrapper, &unwrapped)); |
102 EXPECT_EQ(obj, unwrapped); | 102 EXPECT_EQ(obj, unwrapped); |
103 } | 103 } |
104 | 104 |
105 TEST_F(WrappableTest, GetAndSetProperty) { | 105 TEST_F(WrappableTest, GetAndSetProperty) { |
106 v8::Isolate* isolate = instance_->isolate(); | 106 v8::Isolate* isolate = instance_->isolate(); |
107 v8::HandleScope handle_scope(isolate); | 107 v8::HandleScope handle_scope(isolate); |
108 | 108 |
109 RegisterTemplate(isolate); | 109 RegisterTemplate(isolate); |
110 scoped_refptr<MyObject> obj = MyObject::Create(); | 110 scoped_refptr<MyObject> obj = MyObject::Create(); |
111 | 111 |
112 obj->set_value(42); | 112 obj->set_value(42); |
113 EXPECT_EQ(42, obj->value()); | 113 EXPECT_EQ(42, obj->value()); |
114 | 114 |
115 v8::Handle<v8::String> source = StringToV8(isolate, | 115 v8::Handle<v8::String> source = StringToV8(isolate, |
116 "(function (obj) {" | 116 "(function (obj) {" |
117 " if (obj.value !== 42) throw 'FAIL';" | 117 " if (obj.value !== 42) throw 'FAIL';" |
118 " else obj.value = 191; })"); | 118 " else obj.value = 191; })"); |
119 EXPECT_FALSE(source.IsEmpty()); | 119 EXPECT_FALSE(source.IsEmpty()); |
120 | 120 |
121 v8::TryCatch try_catch; | 121 v8::TryCatch try_catch; |
122 v8::Handle<v8::Script> script = v8::Script::New(source); | 122 v8::Handle<v8::Script> script = v8::Script::New(source); |
123 EXPECT_FALSE(script.IsEmpty()); | 123 EXPECT_FALSE(script.IsEmpty()); |
124 v8::Handle<v8::Value> val = script->Run(); | 124 v8::Handle<v8::Value> val = script->Run(); |
125 EXPECT_FALSE(val.IsEmpty()); | 125 EXPECT_FALSE(val.IsEmpty()); |
126 v8::Handle<v8::Function> func; | 126 v8::Handle<v8::Function> func; |
127 EXPECT_TRUE(ConvertFromV8(val, &func)); | 127 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); |
128 v8::Handle<v8::Value> argv[] = { | 128 v8::Handle<v8::Value> argv[] = { |
129 ConvertToV8(isolate, obj.get()), | 129 ConvertToV8(isolate, obj.get()), |
130 }; | 130 }; |
131 func->Call(v8::Undefined(isolate), 1, argv); | 131 func->Call(v8::Undefined(isolate), 1, argv); |
132 | 132 |
133 EXPECT_EQ(191, obj->value()); | 133 EXPECT_EQ(191, obj->value()); |
134 } | 134 } |
135 | 135 |
136 } // namespace | 136 } // namespace |
137 } // namespace gin | 137 } // namespace gin |
OLD | NEW |