OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 class NoSuchMethodInfo { | 5 class NoSuchMethodInfo { |
6 Object receiver; | 6 Object receiver; |
7 String name; | 7 String name; |
8 List args; | 8 List args; |
9 NoSuchMethodInfo(Object r, String m, List a) | 9 NoSuchMethodInfo(Object r, String m, List a) |
10 : receiver = r, name = m, args = a; | 10 : receiver = r, name = m, args = a; |
11 } | 11 } |
12 | 12 |
13 class A { | 13 class A { |
14 noSuchMethod(InvocationMirror invocation) { | 14 noSuchMethod(String name, List args) { |
15 topLevelInfo = new NoSuchMethodInfo(this, invocation.memberName, | 15 topLevelInfo = new NoSuchMethodInfo(this, name, args); |
16 invocation.positionalArguments); | |
17 return topLevelInfo; | 16 return topLevelInfo; |
18 } | 17 } |
19 | 18 |
20 foo(a, b, c) { | 19 foo(a, b, c) { |
21 Expect.fail('Should never enter here'); | 20 Expect.fail('Should never enter here'); |
22 } | 21 } |
23 } | 22 } |
24 | 23 |
25 // Used for the setter case. | 24 // Used for the setter case. |
26 NoSuchMethodInfo topLevelInfo; | 25 NoSuchMethodInfo topLevelInfo; |
27 | 26 |
28 main() { | 27 main() { |
29 A a = new A(); | 28 A a = new A(); |
30 var info = a.foo(); | 29 var info = a.foo(); |
31 Expect.equals('foo', info.name); | 30 Expect.equals('foo', info.name); |
32 Expect.isTrue(info.args.isEmpty); | 31 Expect.isTrue(info.args.isEmpty); |
33 Expect.isTrue(info.receiver === a); | 32 Expect.isTrue(info.receiver === a); |
34 | 33 |
35 info = a.foo(2); | 34 info = a.foo(2); |
36 Expect.equals('foo', info.name); | 35 Expect.equals('foo', info.name); |
37 Expect.isTrue(info.args.length == 1); | 36 Expect.isTrue(info.args.length == 1); |
38 Expect.isTrue(info.args[0] === 2); | 37 Expect.isTrue(info.args[0] === 2); |
39 Expect.isTrue(info.receiver === a); | 38 Expect.isTrue(info.receiver === a); |
40 | 39 |
41 info = a.bar; | 40 info = a.bar; |
42 Expect.equals('bar', info.name); | 41 Expect.equals('get:bar', info.name); |
43 Expect.isTrue(info.args.length == 0); | 42 Expect.isTrue(info.args.length == 0); |
44 Expect.isTrue(info.receiver === a); | 43 Expect.isTrue(info.receiver === a); |
45 | 44 |
46 a.bar = 2; | 45 a.bar = 2; |
47 info = topLevelInfo; | 46 info = topLevelInfo; |
48 Expect.equals('bar', info.name); | 47 Expect.equals('set:bar', info.name); |
49 Expect.isTrue(info.args.length == 1); | 48 Expect.isTrue(info.args.length == 1); |
50 Expect.isTrue(info.args[0] === 2); | 49 Expect.isTrue(info.args[0] === 2); |
51 Expect.isTrue(info.receiver === a); | 50 Expect.isTrue(info.receiver === a); |
52 } | 51 } |
OLD | NEW |