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

Side by Side Diff: gin/wrappable_unittest.cc

Issue 681713002: Update from chromium https://crrev.com/301315 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « gin/function_template.h.pump ('k') | gpu/command_buffer/service/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/handle.h" 7 #include "gin/handle.h"
8 #include "gin/object_template_builder.h" 8 #include "gin/object_template_builder.h"
9 #include "gin/per_isolate_data.h" 9 #include "gin/per_isolate_data.h"
10 #include "gin/public/isolate_holder.h" 10 #include "gin/public/isolate_holder.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 v8::Isolate* isolate) override { 87 v8::Isolate* isolate) override {
88 return Wrappable<MyCallableObject>::GetObjectTemplateBuilder(isolate) 88 return Wrappable<MyCallableObject>::GetObjectTemplateBuilder(isolate)
89 .SetCallAsFunctionHandler(&MyCallableObject::Call); 89 .SetCallAsFunctionHandler(&MyCallableObject::Call);
90 } 90 }
91 91
92 MyCallableObject() : result_(0) { 92 MyCallableObject() : result_(0) {
93 } 93 }
94 94
95 ~MyCallableObject() override {} 95 ~MyCallableObject() override {}
96 96
97 void Call(int val, const gin::Arguments& arguments) { 97 void Call(int val1, int val2, int val3, const gin::Arguments& arguments) {
98 if (arguments.IsConstructCall()) 98 if (arguments.IsConstructCall())
99 arguments.ThrowTypeError("Cannot be called as constructor."); 99 arguments.ThrowTypeError("Cannot be called as constructor.");
100 else 100 else
101 result_ = val; 101 result_ = val1;
102 } 102 }
103 103
104 int result_; 104 int result_;
105 }; 105 };
106 106
107 class MyObject2 : public Wrappable<MyObject2> { 107 class MyObject2 : public Wrappable<MyObject2> {
108 public: 108 public:
109 static WrapperInfo kWrapperInfo; 109 static WrapperInfo kWrapperInfo;
110 }; 110 };
111 111
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 223 }
224 224
225 TEST_F(WrappableTest, CallAsFunction) { 225 TEST_F(WrappableTest, CallAsFunction) {
226 v8::Isolate* isolate = instance_->isolate(); 226 v8::Isolate* isolate = instance_->isolate();
227 v8::HandleScope handle_scope(isolate); 227 v8::HandleScope handle_scope(isolate);
228 228
229 gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate)); 229 gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate));
230 EXPECT_EQ(0, object->result()); 230 EXPECT_EQ(0, object->result());
231 v8::Handle<v8::String> source = StringToV8(isolate, 231 v8::Handle<v8::String> source = StringToV8(isolate,
232 "(function(obj) {" 232 "(function(obj) {"
233 "obj(42);" 233 "obj(42, 2, 5);"
234 "})"); 234 "})");
235 gin::TryCatch try_catch; 235 gin::TryCatch try_catch;
236 v8::Handle<v8::Script> script = v8::Script::Compile(source); 236 v8::Handle<v8::Script> script = v8::Script::Compile(source);
237 v8::Handle<v8::Value> val = script->Run(); 237 v8::Handle<v8::Value> val = script->Run();
238 v8::Handle<v8::Function> func; 238 v8::Handle<v8::Function> func;
239 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); 239 EXPECT_TRUE(ConvertFromV8(isolate, val, &func));
240 v8::Handle<v8::Value> argv[] = { 240 v8::Handle<v8::Value> argv[] = {
241 ConvertToV8(isolate, object.get()) 241 ConvertToV8(isolate, object.get())
242 }; 242 };
243 func->Call(v8::Undefined(isolate), 1, argv); 243 func->Call(v8::Undefined(isolate), 1, argv);
244 EXPECT_FALSE(try_catch.HasCaught()); 244 EXPECT_FALSE(try_catch.HasCaught());
245 EXPECT_EQ(42, object->result()); 245 EXPECT_EQ(42, object->result());
246 } 246 }
247 247
248 TEST_F(WrappableTest, CallAsConstructor) { 248 TEST_F(WrappableTest, CallAsConstructor) {
249 v8::Isolate* isolate = instance_->isolate(); 249 v8::Isolate* isolate = instance_->isolate();
250 v8::HandleScope handle_scope(isolate); 250 v8::HandleScope handle_scope(isolate);
251 251
252 gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate)); 252 gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate));
253 EXPECT_EQ(0, object->result()); 253 EXPECT_EQ(0, object->result());
254 v8::Handle<v8::String> source = StringToV8(isolate, 254 v8::Handle<v8::String> source = StringToV8(isolate,
255 "(function(obj) {" 255 "(function(obj) {"
256 "new obj(42);" 256 "new obj(42, 2, 5);"
257 "})"); 257 "})");
258 gin::TryCatch try_catch; 258 gin::TryCatch try_catch;
259 v8::Handle<v8::Script> script = v8::Script::Compile(source); 259 v8::Handle<v8::Script> script = v8::Script::Compile(source);
260 v8::Handle<v8::Value> val = script->Run(); 260 v8::Handle<v8::Value> val = script->Run();
261 v8::Handle<v8::Function> func; 261 v8::Handle<v8::Function> func;
262 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); 262 EXPECT_TRUE(ConvertFromV8(isolate, val, &func));
263 v8::Handle<v8::Value> argv[] = { 263 v8::Handle<v8::Value> argv[] = {
264 ConvertToV8(isolate, object.get()) 264 ConvertToV8(isolate, object.get())
265 }; 265 };
266 func->Call(v8::Undefined(isolate), 1, argv); 266 func->Call(v8::Undefined(isolate), 1, argv);
267 EXPECT_TRUE(try_catch.HasCaught()); 267 EXPECT_TRUE(try_catch.HasCaught());
268 } 268 }
269 269
270 } // namespace gin 270 } // namespace gin
OLDNEW
« no previous file with comments | « gin/function_template.h.pump ('k') | gpu/command_buffer/service/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698