OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library test.invoke_call_through_getter; | 5 library test.invoke_call_through_implicit_getter; |
6 | 6 |
7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 | 10 |
11 class FakeFunctionCall { | 11 class FakeFunctionCall { |
12 call(x, y) => '1 $x $y'; | 12 call(x, y) => '1 $x $y'; |
13 } | 13 } |
14 class FakeFunctionNSM { | 14 class FakeFunctionNSM { |
15 noSuchMethod(msg) => msg.positionalArguments.join(', '); | 15 noSuchMethod(msg) => msg.positionalArguments.join(', '); |
16 } | 16 } |
17 | 17 |
18 class C { | 18 class C { |
19 get fakeFunctionCall => new FakeFunctionCall(); | 19 var fakeFunctionCall = new FakeFunctionCall(); |
20 get fakeFunctionNSM => new FakeFunctionNSM(); | 20 var fakeFunctionNSM = new FakeFunctionNSM(); |
21 get closure => (x, y) => '2 $this $x $y'; | 21 var closure; // = (x, y) => '2 $this $x $y'; |
22 get closureOpt => (x, y, [z, w]) => '3 $this $x $y $z $w'; | 22 var closureOpt; // = (x, y, [z, w]) => '3 $this $x $y $z $w'; |
23 get closureNamed => (x, y, {z, w}) => '4 $this $x $y $z $w'; | 23 var closureNamed; // = (x, y, {z, w}) => '4 $this $x $y $z $w'; |
24 get notAClosure => 'Not a closure'; | 24 var notAClosure = 'Not a closure'; |
25 noSuchMethod(msg) => 'DNU'; | 25 noSuchMethod(msg) => 'DNU'; |
26 | 26 |
| 27 C() { |
| 28 closure = (x, y) => '2 $this $x $y'; |
| 29 closureOpt = (x, y, [z, w]) => '3 $this $x $y $z $w'; |
| 30 closureNamed = (x, y, {z, w}) => '4 $this $x $y $z $w'; |
| 31 } |
| 32 |
27 toString() => 'C'; | 33 toString() => 'C'; |
28 } | 34 } |
29 | 35 |
30 testInstanceBase() { | 36 testInstanceBase() { |
31 var c = new C(); | 37 var c = new C(); |
32 | 38 |
33 Expect.equals('1 5 6', c.fakeFunctionCall(5, 6)); | 39 Expect.equals('1 5 6', c.fakeFunctionCall(5, 6)); |
34 Expect.equals('7, 8', c.fakeFunctionNSM(7, 8)); | 40 Expect.equals('7, 8', c.fakeFunctionNSM(7, 8)); |
35 Expect.equals('2 C 9 10', c.closure(9, 10)); | 41 Expect.equals('2 C 9 10', c.closure(9, 10)); |
36 Expect.equals('3 C 11 12 13 null', c.closureOpt(11, 12, 13)); | 42 Expect.equals('3 C 11 12 13 null', c.closureOpt(11, 12, 13)); |
(...skipping 18 matching lines...) Expand all Loading... |
55 im.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); | 61 im.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); |
56 Expect.equals('DNU', | 62 Expect.equals('DNU', |
57 im.invoke(#doesNotExist, [17, 18]).reflectee); | 63 im.invoke(#doesNotExist, [17, 18]).reflectee); |
58 Expect.throws(() => im.invoke(#closure, ['wrong arity']), | 64 Expect.throws(() => im.invoke(#closure, ['wrong arity']), |
59 (e) => e is NoSuchMethodError); | 65 (e) => e is NoSuchMethodError); |
60 Expect.throws(() => im.invoke(#notAClosure, []), | 66 Expect.throws(() => im.invoke(#notAClosure, []), |
61 (e) => e is NoSuchMethodError); | 67 (e) => e is NoSuchMethodError); |
62 } | 68 } |
63 | 69 |
64 class D { | 70 class D { |
65 static get fakeFunctionCall => new FakeFunctionCall(); | 71 static var fakeFunctionCall = new FakeFunctionCall(); |
66 static get fakeFunctionNSM => new FakeFunctionNSM(); | 72 static var fakeFunctionNSM = new FakeFunctionNSM(); |
67 static get closure => (x, y) => '2 $x $y'; | 73 static var closure = (x, y) => '2 $x $y'; |
68 static get closureOpt => (x, y, [z, w]) => '3 $x $y $z $w'; | 74 static var closureOpt = (x, y, [z, w]) => '3 $x $y $z $w'; |
69 static get closureNamed => (x, y, {z, w}) => '4 $x $y $z $w'; | 75 static var closureNamed = (x, y, {z, w}) => '4 $x $y $z $w'; |
70 static get notAClosure => 'Not a closure'; | 76 static var notAClosure = 'Not a closure'; |
71 } | 77 } |
72 | 78 |
73 testClassBase() { | 79 testClassBase() { |
74 Expect.equals('1 5 6', D.fakeFunctionCall(5, 6)); | 80 Expect.equals('1 5 6', D.fakeFunctionCall(5, 6)); |
75 Expect.equals('7, 8', D.fakeFunctionNSM(7, 8)); | 81 Expect.equals('7, 8', D.fakeFunctionNSM(7, 8)); |
76 Expect.equals('2 9 10', D.closure(9, 10)); | 82 Expect.equals('2 9 10', D.closure(9, 10)); |
77 Expect.equals('3 11 12 13 null', D.closureOpt(11, 12, 13)); | 83 Expect.equals('3 11 12 13 null', D.closureOpt(11, 12, 13)); |
78 Expect.equals('4 14 15 null 16', D.closureNamed(14, 15, w: 16)); | 84 Expect.equals('4 14 15 null 16', D.closureNamed(14, 15, w: 16)); |
79 Expect.throws(() => D.closure('wrong arity'), (e) => e is NoSuchMethodError); | 85 Expect.throws(() => D.closure('wrong arity'), (e) => e is NoSuchMethodError); |
80 } | 86 } |
81 | 87 |
82 testClassReflective() { | 88 testClassReflective() { |
83 ClassMirror cm = reflectClass(D); | 89 ClassMirror cm = reflectClass(D); |
84 | 90 |
85 Expect.equals('1 5 6', | 91 Expect.equals('1 5 6', |
86 cm.invoke(#fakeFunctionCall, [5, 6]).reflectee); | 92 cm.invoke(#fakeFunctionCall, [5, 6]).reflectee); |
87 Expect.equals('7, 8', | 93 Expect.equals('7, 8', |
88 cm.invoke(#fakeFunctionNSM, [7, 8]).reflectee); | 94 cm.invoke(#fakeFunctionNSM, [7, 8]).reflectee); |
89 Expect.equals('2 9 10', | 95 Expect.equals('2 9 10', |
90 cm.invoke(#closure, [9, 10]).reflectee); | 96 cm.invoke(#closure, [9, 10]).reflectee); |
91 Expect.equals('3 11 12 13 null', | 97 Expect.equals('3 11 12 13 null', |
92 cm.invoke(#closureOpt, [11, 12, 13]).reflectee); | 98 cm.invoke(#closureOpt, [11, 12, 13]).reflectee); |
93 Expect.equals('4 14 15 null 16', | 99 Expect.equals('4 14 15 null 16', |
94 cm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); | 100 cm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); |
95 Expect.throws(() => cm.invoke(#closure, ['wrong arity']), | 101 Expect.throws(() => cm.invoke(#closure, ['wrong arity']), |
96 (e) => e is NoSuchMethodError); | 102 (e) => e is NoSuchMethodError); |
97 } | 103 } |
98 | 104 |
99 get fakeFunctionCall => new FakeFunctionCall(); | 105 var fakeFunctionCall = new FakeFunctionCall(); |
100 get fakeFunctionNSM => new FakeFunctionNSM(); | 106 var fakeFunctionNSM = new FakeFunctionNSM(); |
101 get closure => (x, y) => '2 $x $y'; | 107 var closure = (x, y) => '2 $x $y'; |
102 get closureOpt => (x, y, [z, w]) => '3 $x $y $z $w'; | 108 var closureOpt = (x, y, [z, w]) => '3 $x $y $z $w'; |
103 get closureNamed => (x, y, {z, w}) => '4 $x $y $z $w'; | 109 var closureNamed = (x, y, {z, w}) => '4 $x $y $z $w'; |
104 get notAClosure => 'Not a closure'; | 110 var notAClosure = 'Not a closure'; |
105 | 111 |
106 testLibraryBase() { | 112 testLibraryBase() { |
107 Expect.equals('1 5 6', fakeFunctionCall(5, 6)); | 113 Expect.equals('1 5 6', fakeFunctionCall(5, 6)); |
108 Expect.equals('7, 8', fakeFunctionNSM(7, 8)); | 114 Expect.equals('7, 8', fakeFunctionNSM(7, 8)); |
109 Expect.equals('2 9 10', closure(9, 10)); | 115 Expect.equals('2 9 10', closure(9, 10)); |
110 Expect.equals('3 11 12 13 null', closureOpt(11, 12, 13)); | 116 Expect.equals('3 11 12 13 null', closureOpt(11, 12, 13)); |
111 Expect.equals('4 14 15 null 16', closureNamed(14, 15, w: 16)); | 117 Expect.equals('4 14 15 null 16', closureNamed(14, 15, w: 16)); |
112 Expect.throws(() => closure('wrong arity'), (e) => e is NoSuchMethodError); | 118 Expect.throws(() => closure('wrong arity'), (e) => e is NoSuchMethodError); |
113 } | 119 } |
114 | 120 |
115 testLibraryReflective() { | 121 testLibraryReflective() { |
116 LibraryMirror lm = reflectClass(D).owner; | 122 LibraryMirror lm = reflectClass(D).owner; |
117 | 123 |
118 Expect.equals('1 5 6', | 124 Expect.equals('1 5 6', |
119 lm.invoke(#fakeFunctionCall, [5, 6]).reflectee); | 125 lm.invoke(#fakeFunctionCall, [5, 6]).reflectee); |
120 Expect.equals('7, 8', | 126 Expect.equals('7, 8', |
121 lm.invoke(#fakeFunctionNSM, [7, 8]).reflectee); | 127 lm.invoke(#fakeFunctionNSM, [7, 8]).reflectee); |
122 Expect.equals('2 9 10', | 128 Expect.equals('2 9 10', |
123 lm.invoke(#closure, [9, 10]).reflectee); | 129 lm.invoke(#closure, [9, 10]).reflectee); |
124 Expect.equals('3 11 12 13 null', | 130 Expect.equals('3 11 12 13 null', |
125 lm.invoke(#closureOpt, [11, 12, 13]).reflectee); | 131 lm.invoke(#closureOpt, [11, 12, 13]).reflectee); |
126 Expect.equals('4 14 15 null 16', | 132 Expect.equals('4 14 15 null 16', |
127 lm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); | 133 lm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); |
128 Expect.throws(() => lm.invoke(#closure, ['wrong arity']), | 134 Expect.throws(() => lm.invoke(#closure, ['wrong arity']), |
129 (e) => e is NoSuchMethodError); | 135 (e) => e is NoSuchMethodError); |
130 } | 136 } |
131 | 137 |
132 main() { | 138 main() { |
133 testInstanceBase(); | 139 // Do not access the getters/closures at the base level in this variant. |
| 140 //testInstanceBase(); |
134 testInstanceReflective(); | 141 testInstanceReflective(); |
135 testClassBase(); | 142 //testClassBase(); |
136 testClassReflective(); | 143 testClassReflective(); |
137 testLibraryBase(); | 144 //testLibraryBase(); |
138 testLibraryReflective(); | 145 testLibraryReflective(); |
139 } | 146 } |
OLD | NEW |