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

Side by Side Diff: gin/wrappable_unittest.cc

Issue 671433004: [gin] Use variadic templates in gin/function_template.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing exception throwing. 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
« gin/function_template.h ('K') | « gin/function_template.h.pump ('k') | no next file » | 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return Wrappable<MyCallableObject>::GetObjectTemplateBuilder(isolate) 90 return Wrappable<MyCallableObject>::GetObjectTemplateBuilder(isolate)
91 .SetCallAsFunctionHandler(&MyCallableObject::Call); 91 .SetCallAsFunctionHandler(&MyCallableObject::Call);
92 } 92 }
93 93
94 MyCallableObject() : result_(0) { 94 MyCallableObject() : result_(0) {
95 } 95 }
96 96
97 virtual ~MyCallableObject() { 97 virtual ~MyCallableObject() {
98 } 98 }
99 99
100 void Call(int val, const gin::Arguments& arguments) { 100 void Call(int val1, int val2, int val3, const gin::Arguments& arguments) {
101 if (arguments.IsConstructCall()) 101 if (arguments.IsConstructCall())
102 arguments.ThrowTypeError("Cannot be called as constructor."); 102 arguments.ThrowTypeError("Cannot be called as constructor.");
103 else 103 else
104 result_ = val; 104 result_ = val1;
105 } 105 }
106 106
107 int result_; 107 int result_;
108 }; 108 };
109 109
110 class MyObject2 : public Wrappable<MyObject2> { 110 class MyObject2 : public Wrappable<MyObject2> {
111 public: 111 public:
112 static WrapperInfo kWrapperInfo; 112 static WrapperInfo kWrapperInfo;
113 }; 113 };
114 114
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 227
228 TEST_F(WrappableTest, CallAsFunction) { 228 TEST_F(WrappableTest, CallAsFunction) {
229 v8::Isolate* isolate = instance_->isolate(); 229 v8::Isolate* isolate = instance_->isolate();
230 v8::HandleScope handle_scope(isolate); 230 v8::HandleScope handle_scope(isolate);
231 231
232 gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate)); 232 gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate));
233 EXPECT_EQ(0, object->result()); 233 EXPECT_EQ(0, object->result());
234 v8::Handle<v8::String> source = StringToV8(isolate, 234 v8::Handle<v8::String> source = StringToV8(isolate,
235 "(function(obj) {" 235 "(function(obj) {"
236 "obj(42);" 236 "obj(42, 2, 5);"
237 "})"); 237 "})");
238 gin::TryCatch try_catch; 238 gin::TryCatch try_catch;
239 v8::Handle<v8::Script> script = v8::Script::Compile(source); 239 v8::Handle<v8::Script> script = v8::Script::Compile(source);
240 v8::Handle<v8::Value> val = script->Run(); 240 v8::Handle<v8::Value> val = script->Run();
241 v8::Handle<v8::Function> func; 241 v8::Handle<v8::Function> func;
242 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); 242 EXPECT_TRUE(ConvertFromV8(isolate, val, &func));
243 v8::Handle<v8::Value> argv[] = { 243 v8::Handle<v8::Value> argv[] = {
244 ConvertToV8(isolate, object.get()) 244 ConvertToV8(isolate, object.get())
245 }; 245 };
246 func->Call(v8::Undefined(isolate), 1, argv); 246 func->Call(v8::Undefined(isolate), 1, argv);
247 EXPECT_FALSE(try_catch.HasCaught()); 247 EXPECT_FALSE(try_catch.HasCaught());
248 EXPECT_EQ(42, object->result()); 248 EXPECT_EQ(42, object->result());
249 } 249 }
250 250
251 TEST_F(WrappableTest, CallAsConstructor) { 251 TEST_F(WrappableTest, CallAsConstructor) {
252 v8::Isolate* isolate = instance_->isolate(); 252 v8::Isolate* isolate = instance_->isolate();
253 v8::HandleScope handle_scope(isolate); 253 v8::HandleScope handle_scope(isolate);
254 254
255 gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate)); 255 gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate));
256 EXPECT_EQ(0, object->result()); 256 EXPECT_EQ(0, object->result());
257 v8::Handle<v8::String> source = StringToV8(isolate, 257 v8::Handle<v8::String> source = StringToV8(isolate,
258 "(function(obj) {" 258 "(function(obj) {"
259 "new obj(42);" 259 "new obj(42, 2, 5);"
260 "})"); 260 "})");
261 gin::TryCatch try_catch; 261 gin::TryCatch try_catch;
262 v8::Handle<v8::Script> script = v8::Script::Compile(source); 262 v8::Handle<v8::Script> script = v8::Script::Compile(source);
263 v8::Handle<v8::Value> val = script->Run(); 263 v8::Handle<v8::Value> val = script->Run();
264 v8::Handle<v8::Function> func; 264 v8::Handle<v8::Function> func;
265 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); 265 EXPECT_TRUE(ConvertFromV8(isolate, val, &func));
266 v8::Handle<v8::Value> argv[] = { 266 v8::Handle<v8::Value> argv[] = {
267 ConvertToV8(isolate, object.get()) 267 ConvertToV8(isolate, object.get())
268 }; 268 };
269 func->Call(v8::Undefined(isolate), 1, argv); 269 func->Call(v8::Undefined(isolate), 1, argv);
270 EXPECT_TRUE(try_catch.HasCaught()); 270 EXPECT_TRUE(try_catch.HasCaught());
271 } 271 }
272 272
273 } // namespace gin 273 } // namespace gin
OLDNEW
« gin/function_template.h ('K') | « gin/function_template.h.pump ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698