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

Side by Side Diff: tests/language/invocation_mirror_indirect_test.dart

Issue 11264005: InvocationMirror implemented in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Optimization + updated cf comments. Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test indirect use of InvocationMirror.invokeOn and Function.apply in
6 // noSuchMethod.
7
8 class PlusMinus {
9 noSuchMethod(var invocation) {
10 var invok = invocation.invokeOn;
11 var funcApp = Function.apply;
12 if (invocation.memberName == 'mul') {
13 return invok(mulObject);
14 } else if (invocation.memberName == 'div') {
15 return invok(divObject);
16 }
17 return funcApp(plus,
18 invocation.positionalArguments,
19 invocation.namedArguments);
20 }
21
22 int plus(int a, int b) => a+b;
ngeoffray 2012/10/26 08:34:55 spaces between +, and same for other operators in
Johnni Winther 2012/10/26 10:18:01 Done.
23
24 get mulObject => new Mul();
25
26 get divObject => new Div();
27 }
28
29 class Mul {
30 int mul(int a, int b, [int c]) {
31 if (?c) {
32 return a*b*c;
33 }
34 return a*b;
35 }
36 }
37
38 class Div {
39 int div({int num, int denom}) => num/denom;
40 }
41
42 void main() {
43 var pm = new PlusMinus();
44 Expect.equals(7, pm.plus(2, 5));
45 Expect.equals(5, pm.minus(2, 3)); // Calls plus.
46 Expect.equals(6, pm.mul(2, 3));
47 Expect.equals(24, pm.mul(2, 3, 4));
48 Expect.equals(5, pm.div(num:10, denom:2));
49 Expect.equals(5, pm.div(denom:2, num:10));
50 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698