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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // Invocation and noSuchMethod testing. | 7 // Invocation and noSuchMethod testing. |
8 | 8 |
9 Map<Symbol, dynamic> listToNamedArguments(list) { | 9 Map<Symbol, dynamic> listToNamedArguments(list) { |
10 var iterator = list.iterator; | 10 var iterator = list.iterator; |
11 var result = new Map<Symbol, dynamic>(); | 11 var result = new Map<Symbol, dynamic>(); |
12 while (iterator.moveNext()) { | 12 while (iterator.moveNext()) { |
13 Symbol key = iterator.current; | 13 Symbol key = iterator.current; |
14 Expect.isTrue(iterator.moveNext()); | 14 Expect.isTrue(iterator.moveNext()); |
15 result[key] = iterator.current; | 15 result[key] = iterator.current; |
16 } | 16 } |
17 return result; | 17 return result; |
18 } | 18 } |
19 | 19 |
20 | |
21 /** Class with noSuchMethod that returns the mirror */ | 20 /** Class with noSuchMethod that returns the mirror */ |
22 class N { | 21 class N { |
23 // Storage for the last argument to noSuchMethod. | 22 // Storage for the last argument to noSuchMethod. |
24 // Needed for setters, which don't evaluate to the return value. | 23 // Needed for setters, which don't evaluate to the return value. |
25 var last; | 24 var last; |
26 noSuchMethod(Invocation m) => last = m; | 25 noSuchMethod(Invocation m) => last = m; |
27 | 26 |
28 flif(int x) { Expect.fail("never get here"); } | 27 flif(int x) { |
29 flaf([int x]) { Expect.fail("never get here"); } | 28 Expect.fail("never get here"); |
30 flof({int y}) { Expect.fail("never get here"); } | 29 } |
| 30 |
| 31 flaf([int x]) { |
| 32 Expect.fail("never get here"); |
| 33 } |
| 34 |
| 35 flof({int y}) { |
| 36 Expect.fail("never get here"); |
| 37 } |
31 | 38 |
32 get wut => this; | 39 get wut => this; |
33 final int plif = 99; | 40 final int plif = 99; |
34 int get plaf { Expect.fail("never get here"); return 0; } | 41 int get plaf { |
| 42 Expect.fail("never get here"); |
| 43 return 0; |
| 44 } |
35 } | 45 } |
36 | 46 |
37 /** As [N] but also implements 'call', so we can call it with wrong arguments.*/ | 47 /** As [N] but also implements 'call', so we can call it with wrong arguments.*/ |
38 class C extends N { | 48 class C extends N { |
39 call(int x) { Expect.fail("never get here"); } | 49 call(int x) { |
| 50 Expect.fail("never get here"); |
| 51 } |
40 } | 52 } |
41 | 53 |
42 /** | 54 /** |
43 * Checks the data of an Invocation. | 55 * Checks the data of an Invocation. |
44 * | 56 * |
45 * Call without optionals for getters, with only positional for setters, | 57 * Call without optionals for getters, with only positional for setters, |
46 * and with both optionals for everything else. | 58 * and with both optionals for everything else. |
47 */ | 59 */ |
48 testInvocationMirror(Invocation im, Symbol name, | 60 testInvocationMirror(Invocation im, Symbol name, |
49 [List positional, List named]) { | 61 [List positional, List named]) { |
50 Expect.isTrue(im is Invocation, "is Invocation"); | 62 Expect.isTrue(im is Invocation, "is Invocation"); |
51 Expect.equals(name, im.memberName, "name"); | 63 Expect.equals(name, im.memberName, "name"); |
52 if (named == null) { | 64 if (named == null) { |
53 Expect.isTrue(im.isAccessor, "$name:isAccessor"); | 65 Expect.isTrue(im.isAccessor, "$name:isAccessor"); |
54 Expect.isFalse(im.isMethod, "$name:isMethod"); | 66 Expect.isFalse(im.isMethod, "$name:isMethod"); |
55 if (positional == null) { | 67 if (positional == null) { |
56 Expect.isTrue(im.isGetter, "$name:isGetter"); | 68 Expect.isTrue(im.isGetter, "$name:isGetter"); |
57 Expect.isFalse(im.isSetter, "$name:isSetter"); | 69 Expect.isFalse(im.isSetter, "$name:isSetter"); |
58 Expect.equals(0, im.positionalArguments.length, "$name:#positional"); | 70 Expect.equals(0, im.positionalArguments.length, "$name:#positional"); |
59 Expect.equals(0, im.namedArguments.length, "$name:#named"); | 71 Expect.equals(0, im.namedArguments.length, "$name:#named"); |
60 return; | 72 return; |
61 } | 73 } |
62 Expect.isTrue(im.isSetter, "$name:isSetter"); | 74 Expect.isTrue(im.isSetter, "$name:isSetter"); |
63 Expect.isFalse(im.isGetter, "$name:isGetter"); | 75 Expect.isFalse(im.isGetter, "$name:isGetter"); |
64 Expect.equals(1, im.positionalArguments.length, "$name:#positional"); | 76 Expect.equals(1, im.positionalArguments.length, "$name:#positional"); |
65 Expect.equals(positional[0], im.positionalArguments[0], | 77 Expect.equals( |
66 "$name:positional[0]"); | 78 positional[0], im.positionalArguments[0], "$name:positional[0]"); |
67 Expect.equals(0, im.namedArguments.length, "$name:#named"); | 79 Expect.equals(0, im.namedArguments.length, "$name:#named"); |
68 return; | 80 return; |
69 } | 81 } |
70 Map<Symbol, dynamic> namedArguments = listToNamedArguments(named); | 82 Map<Symbol, dynamic> namedArguments = listToNamedArguments(named); |
71 Expect.isTrue(im.isMethod, "$name:isMethod"); | 83 Expect.isTrue(im.isMethod, "$name:isMethod"); |
72 Expect.isFalse(im.isAccessor, "$name:isAccessor"); | 84 Expect.isFalse(im.isAccessor, "$name:isAccessor"); |
73 Expect.isFalse(im.isSetter, "$name:isSetter"); | 85 Expect.isFalse(im.isSetter, "$name:isSetter"); |
74 Expect.isFalse(im.isGetter, "$name:isGetter"); | 86 Expect.isFalse(im.isGetter, "$name:isGetter"); |
75 | 87 |
76 Expect.listEquals(positional, im.positionalArguments); | 88 Expect.listEquals(positional, im.positionalArguments); |
77 | 89 |
78 Expect.equals(namedArguments.length, im.namedArguments.length, | 90 Expect.equals( |
79 "$name:#named"); | 91 namedArguments.length, im.namedArguments.length, "$name:#named"); |
80 namedArguments.forEach((k, v) { | 92 namedArguments.forEach((k, v) { |
81 Expect.isTrue(im.namedArguments.containsKey(k), | 93 Expect.isTrue( |
82 "$name:?namedArguments[$k]"); | 94 im.namedArguments.containsKey(k), "$name:?namedArguments[$k]"); |
83 Expect.equals(v, im.namedArguments[k], "$name:namedArguments[$k]"); | 95 Expect.equals(v, im.namedArguments[k], "$name:namedArguments[$k]"); |
84 }); | 96 }); |
85 } | 97 } |
86 | 98 |
87 | |
88 // Test different ways that noSuchMethod can be called. | 99 // Test different ways that noSuchMethod can be called. |
89 testInvocationMirrors() { | 100 testInvocationMirrors() { |
90 var n = new N(); | 101 var n = new N(); |
91 var c = new C(); | 102 var c = new C(); |
92 | 103 |
93 // Missing property/method access. | 104 // Missing property/method access. |
94 testInvocationMirror(n.bar, const Symbol('bar')); | 105 testInvocationMirror(n.bar, const Symbol('bar')); |
95 testInvocationMirror((n..bar = 42).last, const Symbol('bar='), [42]); | 106 testInvocationMirror((n..bar = 42).last, const Symbol('bar='), [42]); |
96 testInvocationMirror(n.bar(), const Symbol('bar'), [], []); | 107 testInvocationMirror(n.bar(), const Symbol('bar'), [], []); |
97 testInvocationMirror(n.bar(42), const Symbol('bar'), [42], []); | 108 testInvocationMirror(n.bar(42), const Symbol('bar'), [42], []); |
98 testInvocationMirror(n.bar(x: 42), const Symbol('bar'), [], | 109 testInvocationMirror( |
99 [const Symbol("x"), 42]); | 110 n.bar(x: 42), const Symbol('bar'), [], [const Symbol("x"), 42]); |
100 testInvocationMirror(n.bar(37, x: 42), const Symbol('bar'), [37], | 111 testInvocationMirror( |
101 [const Symbol("x"), 42]); | 112 n.bar(37, x: 42), const Symbol('bar'), [37], [const Symbol("x"), 42]); |
102 | 113 |
103 // Missing operator access. | 114 // Missing operator access. |
104 testInvocationMirror(n + 4, const Symbol('+'), [4], []); | 115 testInvocationMirror(n + 4, const Symbol('+'), [4], []); |
105 testInvocationMirror(n - 4, const Symbol('-'), [4], []); | 116 testInvocationMirror(n - 4, const Symbol('-'), [4], []); |
106 testInvocationMirror(-n, const Symbol('unary-'), [], []); | 117 testInvocationMirror(-n, const Symbol('unary-'), [], []); |
107 testInvocationMirror(n[42], const Symbol('[]'), [42], []); | 118 testInvocationMirror(n[42], const Symbol('[]'), [42], []); |
108 testInvocationMirror((n..[37] = 42).last, const Symbol('[]='), [37, 42], []); | 119 testInvocationMirror((n..[37] = 42).last, const Symbol('[]='), [37, 42], []); |
109 | 120 |
110 // Calling as function when it's not. | 121 // Calling as function when it's not. |
111 testInvocationMirror(n(), const Symbol('call'), [], []); | 122 testInvocationMirror(n(), const Symbol('call'), [], []); |
112 testInvocationMirror(n(42), const Symbol('call'), [42], []); | 123 testInvocationMirror(n(42), const Symbol('call'), [42], []); |
113 testInvocationMirror(n(x: 42), const Symbol('call'), [], | 124 testInvocationMirror( |
114 [const Symbol("x"), 42]); | 125 n(x: 42), const Symbol('call'), [], [const Symbol("x"), 42]); |
115 testInvocationMirror(n(37, x: 42), const Symbol('call'), [37], | 126 testInvocationMirror( |
116 [const Symbol("x"), 42]); | 127 n(37, x: 42), const Symbol('call'), [37], [const Symbol("x"), 42]); |
117 | 128 |
118 // Calling with arguments not matching existing call method. | 129 // Calling with arguments not matching existing call method. |
119 testInvocationMirror(c(), const Symbol('call'), [], []); | 130 testInvocationMirror(c(), const Symbol('call'), [], []); |
120 testInvocationMirror(c(37, 42), const Symbol('call'), [37, 42], []); | 131 testInvocationMirror(c(37, 42), const Symbol('call'), [37, 42], []); |
121 testInvocationMirror(c(x: 42), const Symbol('call'), [], | 132 testInvocationMirror( |
122 [const Symbol("x"), 42]); | 133 c(x: 42), const Symbol('call'), [], [const Symbol("x"), 42]); |
123 testInvocationMirror(c(37, x: 42), const Symbol('call'), [37], | 134 testInvocationMirror( |
124 [const Symbol("x"), 42]); | 135 c(37, x: 42), const Symbol('call'), [37], [const Symbol("x"), 42]); |
125 | 136 |
126 // Wrong arguments to existing function. | 137 // Wrong arguments to existing function. |
127 testInvocationMirror(n.flif(), const Symbol("flif"), [], []); | 138 testInvocationMirror(n.flif(), const Symbol("flif"), [], []); |
128 testInvocationMirror(n.flif(37, 42), const Symbol("flif"), [37, 42], []); | 139 testInvocationMirror(n.flif(37, 42), const Symbol("flif"), [37, 42], []); |
129 testInvocationMirror(n.flif(x: 42), const Symbol("flif"), [], | 140 testInvocationMirror( |
130 [const Symbol("x"), 42]); | 141 n.flif(x: 42), const Symbol("flif"), [], [const Symbol("x"), 42]); |
131 testInvocationMirror(n.flif(37, x: 42), const Symbol("flif"), [37], | 142 testInvocationMirror( |
132 [const Symbol("x"), 42]); | 143 n.flif(37, x: 42), const Symbol("flif"), [37], [const Symbol("x"), 42]); |
133 testInvocationMirror((n..flif = 42).last, const Symbol("flif="), [42]); | 144 testInvocationMirror((n..flif = 42).last, const Symbol("flif="), [42]); |
134 | 145 |
135 testInvocationMirror(n.flaf(37, 42), const Symbol("flaf"), [37, 42], []); | 146 testInvocationMirror(n.flaf(37, 42), const Symbol("flaf"), [37, 42], []); |
136 testInvocationMirror(n.flaf(x: 42), const Symbol("flaf"), [], | 147 testInvocationMirror( |
137 [const Symbol("x"), 42]); | 148 n.flaf(x: 42), const Symbol("flaf"), [], [const Symbol("x"), 42]); |
138 testInvocationMirror(n.flaf(37, x: 42), const Symbol("flaf"), [37], | 149 testInvocationMirror( |
139 [const Symbol("x"), 42]); | 150 n.flaf(37, x: 42), const Symbol("flaf"), [37], [const Symbol("x"), 42]); |
140 testInvocationMirror((n..flaf = 42).last, const Symbol("flaf="), [42]); | 151 testInvocationMirror((n..flaf = 42).last, const Symbol("flaf="), [42]); |
141 | 152 |
142 testInvocationMirror(n.flof(37, 42), const Symbol("flof"), [37, 42], []); | 153 testInvocationMirror(n.flof(37, 42), const Symbol("flof"), [37, 42], []); |
143 testInvocationMirror(n.flof(x: 42), const Symbol("flof"), [], | 154 testInvocationMirror( |
144 [const Symbol("x"), 42]); | 155 n.flof(x: 42), const Symbol("flof"), [], [const Symbol("x"), 42]); |
145 testInvocationMirror(n.flof(37, y: 42), const Symbol("flof"), [37], | 156 testInvocationMirror( |
146 [const Symbol("y"), 42]); | 157 n.flof(37, y: 42), const Symbol("flof"), [37], [const Symbol("y"), 42]); |
147 testInvocationMirror((n..flof = 42).last, const Symbol("flof="), [42]); | 158 testInvocationMirror((n..flof = 42).last, const Symbol("flof="), [42]); |
148 | 159 |
149 // Reading works. | 160 // Reading works. |
150 Expect.isTrue(n.flif is Function); | 161 Expect.isTrue(n.flif is Function); |
151 Expect.isTrue(n.flaf is Function); | 162 Expect.isTrue(n.flaf is Function); |
152 Expect.isTrue(n.flof is Function); | 163 Expect.isTrue(n.flof is Function); |
153 | 164 |
154 // Writing to read-only fields. | 165 // Writing to read-only fields. |
155 testInvocationMirror((n..wut = 42).last, const Symbol("wut="), [42]); | 166 testInvocationMirror((n..wut = 42).last, const Symbol("wut="), [42]); |
156 testInvocationMirror((n..plif = 42).last, const Symbol("plif="), [42]); | 167 testInvocationMirror((n..plif = 42).last, const Symbol("plif="), [42]); |
157 testInvocationMirror((n..plaf = 42).last, const Symbol("plaf="), [42]); | 168 testInvocationMirror((n..plaf = 42).last, const Symbol("plaf="), [42]); |
158 | 169 |
159 // Trick call to n.call - wut is a getter returning n again. | 170 // Trick call to n.call - wut is a getter returning n again. |
160 testInvocationMirror(n.wut(42), const Symbol("call"), [42], []); | 171 testInvocationMirror(n.wut(42), const Symbol("call"), [42], []); |
161 | 172 |
162 // Calling noSuchMethod itself, badly. | 173 // Calling noSuchMethod itself, badly. |
163 testInvocationMirror(n.noSuchMethod(), const Symbol("noSuchMethod"), [], []); | 174 testInvocationMirror(n.noSuchMethod(), const Symbol("noSuchMethod"), [], []); |
164 testInvocationMirror(n.noSuchMethod(37, 42), const Symbol("noSuchMethod"), | 175 testInvocationMirror( |
165 [37, 42], []); | 176 n.noSuchMethod(37, 42), const Symbol("noSuchMethod"), [37, 42], []); |
166 testInvocationMirror(n.noSuchMethod(37, x:42), | 177 testInvocationMirror(n.noSuchMethod(37, x: 42), const Symbol("noSuchMethod"), |
167 const Symbol("noSuchMethod"), [37], | 178 [37], [const Symbol("x"), 42]); |
168 [const Symbol("x"), 42]); | 179 testInvocationMirror(n.noSuchMethod(x: 42), const Symbol("noSuchMethod"), [], |
169 testInvocationMirror(n.noSuchMethod(x:42), const Symbol("noSuchMethod"), [], | 180 [const Symbol("x"), 42]); |
170 [const Symbol("x"), 42]); | |
171 | 181 |
172 // Closurizing a method means that calling it badly will not hit the | 182 // Closurizing a method means that calling it badly will not hit the |
173 // original receivers noSuchMethod, only the one inherited from Object | 183 // original receivers noSuchMethod, only the one inherited from Object |
174 // by the closure object. | 184 // by the closure object. |
175 Expect.throws(() { var x = n.flif; x(37, 42); }, | 185 Expect.throws(() { |
176 (e) => e is NoSuchMethodError); | 186 var x = n.flif; |
177 Expect.throws(() { var x = c.call; x(37, 42); }, | 187 x(37, 42); |
178 (e) => e is NoSuchMethodError); | 188 }, (e) => e is NoSuchMethodError); |
| 189 Expect.throws(() { |
| 190 var x = c.call; |
| 191 x(37, 42); |
| 192 }, (e) => e is NoSuchMethodError); |
179 } | 193 } |
180 | 194 |
181 class M extends N { | 195 class M extends N { |
182 noSuchMethod(Invocation m) { throw "never get here"; } | 196 noSuchMethod(Invocation m) { |
| 197 throw "never get here"; |
| 198 } |
183 | 199 |
184 testSuperCalls() { | 200 testSuperCalls() { |
185 // Missing property/method access. | 201 // Missing property/method access. |
186 testInvocationMirror(super.bar, const Symbol('bar')); | 202 testInvocationMirror(super.bar, const Symbol('bar')); |
187 testInvocationMirror((){super.bar = 42; return last;}(), | 203 testInvocationMirror(() { |
188 const Symbol('bar='), [42]); | 204 super.bar = 42; |
| 205 return last; |
| 206 }(), const Symbol('bar='), [42]); |
189 testInvocationMirror(super.bar(), const Symbol('bar'), [], []); | 207 testInvocationMirror(super.bar(), const Symbol('bar'), [], []); |
190 testInvocationMirror(super.bar(42), const Symbol('bar'), [42], []); | 208 testInvocationMirror(super.bar(42), const Symbol('bar'), [42], []); |
191 testInvocationMirror(super.bar(x: 42), const Symbol('bar'), [], | 209 testInvocationMirror( |
192 [const Symbol("x"), 42]); | 210 super.bar(x: 42), const Symbol('bar'), [], [const Symbol("x"), 42]); |
193 testInvocationMirror(super.bar(37, x: 42), const Symbol('bar'), [37], | 211 testInvocationMirror(super.bar(37, x: 42), const Symbol('bar'), [37], |
194 [const Symbol("x"), 42]); | 212 [const Symbol("x"), 42]); |
195 | 213 |
196 // Missing operator access. | 214 // Missing operator access. |
197 testInvocationMirror(super + 4, const Symbol('+'), [4], []); | 215 testInvocationMirror(super + 4, const Symbol('+'), [4], []); |
198 testInvocationMirror(super - 4, const Symbol('-'), [4], []); | 216 testInvocationMirror(super - 4, const Symbol('-'), [4], []); |
199 testInvocationMirror(-super, const Symbol('unary-'), [], []); | 217 testInvocationMirror(-super, const Symbol('unary-'), [], []); |
200 testInvocationMirror(super[42], const Symbol('[]'), [42], []); | 218 testInvocationMirror(super[42], const Symbol('[]'), [42], []); |
201 testInvocationMirror((){super[37] = 42; return last;}(), | 219 testInvocationMirror(() { |
202 const Symbol('[]='), [37, 42], []); | 220 super[37] = 42; |
| 221 return last; |
| 222 }(), const Symbol('[]='), [37, 42], []); |
203 | 223 |
204 // Wrong arguments to existing function. | 224 // Wrong arguments to existing function. |
205 testInvocationMirror(super.flif(), const Symbol("flif"), [], []); | 225 testInvocationMirror(super.flif(), const Symbol("flif"), [], []); |
206 testInvocationMirror(super.flif(37, 42), const Symbol("flif"), [37, 42], | 226 testInvocationMirror( |
207 []); | 227 super.flif(37, 42), const Symbol("flif"), [37, 42], []); |
208 testInvocationMirror(super.flif(x: 42), const Symbol("flif"), [], | 228 testInvocationMirror( |
209 [const Symbol("x"), 42]); | 229 super.flif(x: 42), const Symbol("flif"), [], [const Symbol("x"), 42]); |
210 testInvocationMirror(super.flif(37, x: 42), const Symbol("flif"), [37], | 230 testInvocationMirror(super.flif(37, x: 42), const Symbol("flif"), [37], |
211 [const Symbol("x"), 42]); | 231 [const Symbol("x"), 42]); |
212 testInvocationMirror((){super.flif = 42; return last;}(), | 232 testInvocationMirror(() { |
213 const Symbol("flif="), [42]); | 233 super.flif = 42; |
| 234 return last; |
| 235 }(), const Symbol("flif="), [42]); |
214 | 236 |
215 testInvocationMirror(super.flaf(37, 42), const Symbol("flaf"), [37, 42], | 237 testInvocationMirror( |
216 []); | 238 super.flaf(37, 42), const Symbol("flaf"), [37, 42], []); |
217 testInvocationMirror(super.flaf(x: 42), const Symbol("flaf"), [], | 239 testInvocationMirror( |
218 [const Symbol("x"), 42]); | 240 super.flaf(x: 42), const Symbol("flaf"), [], [const Symbol("x"), 42]); |
219 testInvocationMirror(super.flaf(37, x: 42), const Symbol("flaf"), [37], | 241 testInvocationMirror(super.flaf(37, x: 42), const Symbol("flaf"), [37], |
220 [const Symbol("x"), 42]); | 242 [const Symbol("x"), 42]); |
221 testInvocationMirror((){super.flaf = 42; return last;}(), | 243 testInvocationMirror(() { |
222 const Symbol("flaf="), [42]); | 244 super.flaf = 42; |
| 245 return last; |
| 246 }(), const Symbol("flaf="), [42]); |
223 | 247 |
224 testInvocationMirror(super.flof(37, 42), const Symbol("flof"), [37, 42], | 248 testInvocationMirror( |
225 []); | 249 super.flof(37, 42), const Symbol("flof"), [37, 42], []); |
226 testInvocationMirror(super.flof(x: 42), const Symbol("flof"), [], | 250 testInvocationMirror( |
227 [const Symbol("x"), 42]); | 251 super.flof(x: 42), const Symbol("flof"), [], [const Symbol("x"), 42]); |
228 testInvocationMirror(super.flof(37, y: 42), const Symbol("flof"), [37], | 252 testInvocationMirror(super.flof(37, y: 42), const Symbol("flof"), [37], |
229 [const Symbol("y"), 42]); | 253 [const Symbol("y"), 42]); |
230 testInvocationMirror((){super.flof = 42; return last;}(), | 254 testInvocationMirror(() { |
231 const Symbol("flof="), [42]); | 255 super.flof = 42; |
| 256 return last; |
| 257 }(), const Symbol("flof="), [42]); |
232 | 258 |
233 // Reading works. | 259 // Reading works. |
234 Expect.isTrue(super.flif is Function); | 260 Expect.isTrue(super.flif is Function); |
235 Expect.isTrue(super.flaf is Function); | 261 Expect.isTrue(super.flaf is Function); |
236 Expect.isTrue(super.flof is Function); | 262 Expect.isTrue(super.flof is Function); |
237 | 263 |
238 // Writing to read-only fields. | 264 // Writing to read-only fields. |
239 testInvocationMirror((){super.wut = 42; return last;}(), | 265 testInvocationMirror(() { |
240 const Symbol("wut="), [42]); | 266 super.wut = 42; |
241 testInvocationMirror((){super.plif = 42; return last;}(), | 267 return last; |
242 const Symbol("plif="), [42]); | 268 }(), const Symbol("wut="), [42]); |
243 testInvocationMirror((){super.plaf = 42; return last;}(), | 269 testInvocationMirror(() { |
244 const Symbol("plaf="), [42]); | 270 super.plif = 42; |
| 271 return last; |
| 272 }(), const Symbol("plif="), [42]); |
| 273 testInvocationMirror(() { |
| 274 super.plaf = 42; |
| 275 return last; |
| 276 }(), const Symbol("plaf="), [42]); |
245 | 277 |
246 // Calling noSuchMethod itself, badly. | 278 // Calling noSuchMethod itself, badly. |
247 testInvocationMirror(super.noSuchMethod(), const Symbol("noSuchMethod"), [], | 279 testInvocationMirror( |
248 []); | 280 super.noSuchMethod(), const Symbol("noSuchMethod"), [], []); |
249 testInvocationMirror(super.noSuchMethod(37, 42), | 281 testInvocationMirror( |
250 const Symbol("noSuchMethod"), [37, 42], []); | 282 super.noSuchMethod(37, 42), const Symbol("noSuchMethod"), [37, 42], []); |
251 testInvocationMirror(super.noSuchMethod(37, x:42), | 283 testInvocationMirror(super.noSuchMethod(37, x: 42), |
252 const Symbol("noSuchMethod"), [37], | 284 const Symbol("noSuchMethod"), [37], [const Symbol("x"), 42]); |
253 [const Symbol("x"), 42]); | 285 testInvocationMirror(super.noSuchMethod(x: 42), |
254 testInvocationMirror(super.noSuchMethod(x:42), | 286 const Symbol("noSuchMethod"), [], [const Symbol("x"), 42]); |
255 const Symbol("noSuchMethod"), [], | |
256 [const Symbol("x"), 42]); | |
257 | 287 |
258 // Closurizing a method means that calling it badly will not hit the | 288 // Closurizing a method means that calling it badly will not hit the |
259 // original receivers noSuchMethod, only the one inherited from Object | 289 // original receivers noSuchMethod, only the one inherited from Object |
260 // by the closure object. | 290 // by the closure object. |
261 Expect.throws(() { var x = super.flif; x(37, 42); }, | 291 Expect.throws(() { |
262 (e) => e is NoSuchMethodError); | 292 var x = super.flif; |
| 293 x(37, 42); |
| 294 }, (e) => e is NoSuchMethodError); |
263 } | 295 } |
264 } | 296 } |
265 | 297 |
266 | |
267 | |
268 // Test the NoSuchMethodError thrown by different incorrect calls. | 298 // Test the NoSuchMethodError thrown by different incorrect calls. |
269 testNoSuchMethodErrors() { | 299 testNoSuchMethodErrors() { |
270 test(Function block) { | 300 test(Function block) { |
271 Expect.throws(block, (e) => e is NoSuchMethodError); | 301 Expect.throws(block, (e) => e is NoSuchMethodError); |
272 } | 302 } |
| 303 |
273 var n = new N(); | 304 var n = new N(); |
274 var o = new Object(); | 305 var o = new Object(); |
275 test(() => o.bar); | 306 test(() => o.bar); |
276 test(() => o.bar = 42); | 307 test(() => o.bar = 42); |
277 test(() => o.bar()); | 308 test(() => o.bar()); |
278 test(() => o + 2); | 309 test(() => o + 2); |
279 test(() => -o); | 310 test(() => -o); |
280 test(() => o[0]); | 311 test(() => o[0]); |
281 test(() => o[0] = 42); | 312 test(() => o[0] = 42); |
282 test(() => o()); | 313 test(() => o()); |
283 test(() => o.toString = 42); | 314 test(() => o.toString = 42); |
284 test(() => o.toString(42)); | 315 test(() => o.toString(42)); |
285 test(() => o.toString(x: 37)); | 316 test(() => o.toString(x: 37)); |
286 test(() => o.hashCode = 42); | 317 test(() => o.hashCode = 42); |
287 test(() => o.hashCode()); // Thrown by int.noSuchMethod. | 318 test(() => o.hashCode()); // Thrown by int.noSuchMethod. |
288 test(() => (n.flif)()); // Extracted method has no noSuchMethod. | 319 test(() => (n.flif)()); // Extracted method has no noSuchMethod. |
289 } | 320 } |
290 | 321 |
291 main() { | 322 main() { |
292 testInvocationMirrors(); | 323 testInvocationMirrors(); |
293 testNoSuchMethodErrors(); | 324 testNoSuchMethodErrors(); |
294 new M().testSuperCalls(); | 325 new M().testSuperCalls(); |
295 } | 326 } |
OLD | NEW |