OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import "package:compiler/src/js/js.dart"; | 6 import "package:compiler/src/js/js.dart"; |
7 import "package:compiler/src/js/rewrite_async.dart"; | 7 import "package:compiler/src/js/rewrite_async.dart"; |
| 8 import "package:compiler/src/js_backend/js_backend.dart" show StringBackedName; |
8 | 9 |
9 import "backend_dart/dart_printer_test.dart" show PrintDiagnosticListener; | 10 import "backend_dart/dart_printer_test.dart" show PrintDiagnosticListener; |
10 | 11 |
11 void testTransform(String source, String expected) { | 12 void testTransform(String source, String expected) { |
12 Fun fun = js(source); | 13 Fun fun = js(source); |
13 Fun rewritten = new AsyncRewriter( | 14 Fun rewritten = new AsyncRewriter( |
14 null, // The diagnostic helper should not be used in these tests. | 15 null, // The diagnostic helper should not be used in these tests. |
15 null, | 16 null, |
16 asyncHelper: new VariableUse("thenHelper"), | 17 asyncHelper: new VariableUse("thenHelper"), |
17 newCompleter: new VariableUse("Completer"), | 18 newCompleter: new VariableUse("Completer"), |
18 safeVariableName: (String name) => "__$name", | 19 safeVariableName: (String name) => "__$name", |
19 bodyName: "body").rewrite(fun); | 20 bodyName: new StringBackedName("body")).rewrite(fun); |
20 | 21 |
21 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); | 22 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); |
22 SimpleJavaScriptPrintingContext context = | 23 SimpleJavaScriptPrintingContext context = |
23 new SimpleJavaScriptPrintingContext(); | 24 new SimpleJavaScriptPrintingContext(); |
24 Printer printer = new Printer(options, context); | 25 Printer printer = new Printer(options, context); |
25 printer.visit(rewritten); | 26 printer.visit(rewritten); |
26 Expect.stringEquals(expected, context.getText()); | 27 Expect.stringEquals(expected, context.getText()); |
27 } | 28 } |
28 | 29 |
29 main() { | 30 main() { |
30 testTransform(""" | 31 testTransform(""" |
31 function(a) async { | 32 function(a) async { |
32 print(this.x); // Ensure `this` is translated in the helper function. | 33 print(this.x); // Ensure `this` is translated in the helper function. |
33 await foo(); | 34 await foo(); |
34 }""", """ | 35 }""", """ |
35 function(a) { | 36 function(a) { |
36 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__self = this; | 37 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__self = this; |
37 function __body(__errorCode, __result) { | 38 function body(__errorCode, __result) { |
38 if (__errorCode === 1) { | 39 if (__errorCode === 1) { |
39 __currentError = __result; | 40 __currentError = __result; |
40 __goto = __handler; | 41 __goto = __handler; |
41 } | 42 } |
42 while (true) | 43 while (true) |
43 switch (__goto) { | 44 switch (__goto) { |
44 case 0: | 45 case 0: |
45 // Function start | 46 // Function start |
46 print(__self.x); | 47 print(__self.x); |
47 __goto = 2; | 48 __goto = 2; |
48 return thenHelper(foo(), __body, __completer); | 49 return thenHelper(foo(), body, __completer); |
49 case 2: | 50 case 2: |
50 // returning from await. | 51 // returning from await. |
51 // implicit return | 52 // implicit return |
52 return thenHelper(null, 0, __completer, null); | 53 return thenHelper(null, 0, __completer, null); |
53 case 1: | 54 case 1: |
54 // rethrow | 55 // rethrow |
55 return thenHelper(__currentError, 1, __completer); | 56 return thenHelper(__currentError, 1, __completer); |
56 } | 57 } |
57 } | 58 } |
58 return thenHelper(null, __body, __completer, null); | 59 return thenHelper(null, body, __completer, null); |
59 }"""); | 60 }"""); |
60 | 61 |
61 testTransform(""" | 62 testTransform(""" |
62 function(b) async { | 63 function(b) async { |
63 try { | 64 try { |
64 __outer: while (true) { // Overlapping label name. | 65 __outer: while (true) { // Overlapping label name. |
65 try { | 66 try { |
66 inner: while (true) { | 67 inner: while (true) { |
67 break __outer; // Break from untranslated loop to translated target. | 68 break __outer; // Break from untranslated loop to translated target. |
68 break; // break to untranslated target. | 69 break; // break to untranslated target. |
69 } | 70 } |
70 while (true) { | 71 while (true) { |
71 return; // Return via finallies. | 72 return; // Return via finallies. |
72 } | 73 } |
73 var __helper = await foo(); // Overlapping variable name. | 74 var __helper = await foo(); // Overlapping variable name. |
74 } finally { | 75 } finally { |
75 foo(); | 76 foo(); |
76 continue; // Continue from finally with pending finally. | 77 continue; // Continue from finally with pending finally. |
77 return 2; // Return from finally with pending finally. | 78 return 2; // Return from finally with pending finally. |
78 } | 79 } |
79 } | 80 } |
80 } finally { | 81 } finally { |
81 return 3; // Return from finally with no pending finally. | 82 return 3; // Return from finally with no pending finally. |
82 } | 83 } |
83 return 4; | 84 return 4; |
84 }""", """ | 85 }""", """ |
85 function(b) { | 86 function(b) { |
86 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, __next = [], __helper; | 87 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, __next = [], __helper; |
87 function __body(__errorCode, __result) { | 88 function body(__errorCode, __result) { |
88 if (__errorCode === 1) { | 89 if (__errorCode === 1) { |
89 __currentError = __result; | 90 __currentError = __result; |
90 __goto = __handler; | 91 __goto = __handler; |
91 } | 92 } |
92 while (true) | 93 while (true) |
93 __outer1: | 94 __outer1: |
94 switch (__goto) { | 95 switch (__goto) { |
95 case 0: | 96 case 0: |
96 // Function start | 97 // Function start |
97 __handler = 3; | 98 __handler = 3; |
98 case 7: | 99 case 7: |
99 // while condition | 100 // while condition |
100 __handler = 9; | 101 __handler = 9; |
101 inner: | 102 inner: |
102 while (true) { | 103 while (true) { |
103 __next = [6]; | 104 __next = [6]; |
104 // goto finally | 105 // goto finally |
105 __goto = 10; | 106 __goto = 10; |
106 break __outer1; | 107 break __outer1; |
107 break; | 108 break; |
108 } | 109 } |
109 while (true) { | 110 while (true) { |
110 __next = [1, 4]; | 111 __next = [1, 4]; |
111 // goto finally | 112 // goto finally |
112 __goto = 10; | 113 __goto = 10; |
113 break __outer1; | 114 break __outer1; |
114 } | 115 } |
115 __goto = 12; | 116 __goto = 12; |
116 return thenHelper(foo(), __body, __completer); | 117 return thenHelper(foo(), body, __completer); |
117 case 12: | 118 case 12: |
118 // returning from await. | 119 // returning from await. |
119 __helper = __result; | 120 __helper = __result; |
120 __next.push(11); | 121 __next.push(11); |
121 // goto finally | 122 // goto finally |
122 __goto = 10; | 123 __goto = 10; |
123 break; | 124 break; |
124 case 9: | 125 case 9: |
125 // uncaught | 126 // uncaught |
126 __next = [3]; | 127 __next = [3]; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 __goto = 1; | 173 __goto = 1; |
173 break; | 174 break; |
174 case 1: | 175 case 1: |
175 // return | 176 // return |
176 return thenHelper(__returnValue, 0, __completer, null); | 177 return thenHelper(__returnValue, 0, __completer, null); |
177 case 2: | 178 case 2: |
178 // rethrow | 179 // rethrow |
179 return thenHelper(__currentError, 1, __completer); | 180 return thenHelper(__currentError, 1, __completer); |
180 } | 181 } |
181 } | 182 } |
182 return thenHelper(null, __body, __completer, null); | 183 return thenHelper(null, body, __completer, null); |
183 }"""); | 184 }"""); |
184 | 185 |
185 testTransform(""" | 186 testTransform(""" |
186 function(c) async { | 187 function(c) async { |
187 var a, b, c, d, e, f; | 188 var a, b, c, d, e, f; |
188 a = b++; // post- and preincrements. | 189 a = b++; // post- and preincrements. |
189 b = --b; | 190 b = --b; |
190 c = (await foo()).a++; | 191 c = (await foo()).a++; |
191 d = ++(await foo()).a; | 192 d = ++(await foo()).a; |
192 e = foo1()[await foo2()]--; | 193 e = foo1()[await foo2()]--; |
193 f = --foo1()[await foo2()]; | 194 f = --foo1()[await foo2()]; |
194 }""", """ | 195 }""", """ |
195 function(c) { | 196 function(c) { |
196 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a, b, c, d, e, f, __temp1; | 197 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a, b, c, d, e, f, __temp1; |
197 function __body(__errorCode, __result) { | 198 function body(__errorCode, __result) { |
198 if (__errorCode === 1) { | 199 if (__errorCode === 1) { |
199 __currentError = __result; | 200 __currentError = __result; |
200 __goto = __handler; | 201 __goto = __handler; |
201 } | 202 } |
202 while (true) | 203 while (true) |
203 switch (__goto) { | 204 switch (__goto) { |
204 case 0: | 205 case 0: |
205 // Function start | 206 // Function start |
206 a = b++; | 207 a = b++; |
207 b = --b; | 208 b = --b; |
208 __goto = 2; | 209 __goto = 2; |
209 return thenHelper(foo(), __body, __completer); | 210 return thenHelper(foo(), body, __completer); |
210 case 2: | 211 case 2: |
211 // returning from await. | 212 // returning from await. |
212 c = __result.a++; | 213 c = __result.a++; |
213 __goto = 3; | 214 __goto = 3; |
214 return thenHelper(foo(), __body, __completer); | 215 return thenHelper(foo(), body, __completer); |
215 case 3: | 216 case 3: |
216 // returning from await. | 217 // returning from await. |
217 d = ++__result.a; | 218 d = ++__result.a; |
218 __temp1 = foo1(); | 219 __temp1 = foo1(); |
219 __goto = 4; | 220 __goto = 4; |
220 return thenHelper(foo2(), __body, __completer); | 221 return thenHelper(foo2(), body, __completer); |
221 case 4: | 222 case 4: |
222 // returning from await. | 223 // returning from await. |
223 e = __temp1[__result]--; | 224 e = __temp1[__result]--; |
224 __temp1 = foo1(); | 225 __temp1 = foo1(); |
225 __goto = 5; | 226 __goto = 5; |
226 return thenHelper(foo2(), __body, __completer); | 227 return thenHelper(foo2(), body, __completer); |
227 case 5: | 228 case 5: |
228 // returning from await. | 229 // returning from await. |
229 f = --__temp1[__result]; | 230 f = --__temp1[__result]; |
230 // implicit return | 231 // implicit return |
231 return thenHelper(null, 0, __completer, null); | 232 return thenHelper(null, 0, __completer, null); |
232 case 1: | 233 case 1: |
233 // rethrow | 234 // rethrow |
234 return thenHelper(__currentError, 1, __completer); | 235 return thenHelper(__currentError, 1, __completer); |
235 } | 236 } |
236 } | 237 } |
237 return thenHelper(null, __body, __completer, null); | 238 return thenHelper(null, body, __completer, null); |
238 }"""); | 239 }"""); |
239 | 240 |
240 testTransform(""" | 241 testTransform(""" |
241 function(d2) async { | 242 function(d2) async { |
242 var a, b, c, d, e, f, g, h; // empty initializer | 243 var a, b, c, d, e, f, g, h; // empty initializer |
243 a = foo1() || await foo2(); // short circuiting operators | 244 a = foo1() || await foo2(); // short circuiting operators |
244 b = await foo1() || foo2(); | 245 b = await foo1() || foo2(); |
245 c = await foo1() || foo3(await foo2()); | 246 c = await foo1() || foo3(await foo2()); |
246 d = foo1() || foo2(); | 247 d = foo1() || foo2(); |
247 e = foo1() && await foo2(); | 248 e = foo1() && await foo2(); |
248 f = await foo1() && foo2(); | 249 f = await foo1() && foo2(); |
249 g = await foo1() && await foo2(); | 250 g = await foo1() && await foo2(); |
250 h = foo1() && foo2(); | 251 h = foo1() && foo2(); |
251 }""", """ | 252 }""", """ |
252 function(d2) { | 253 function(d2) { |
253 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a, b, c, d, e, f, g, h, __temp1; | 254 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a, b, c, d, e, f, g, h, __temp1; |
254 function __body(__errorCode, __result) { | 255 function body(__errorCode, __result) { |
255 if (__errorCode === 1) { | 256 if (__errorCode === 1) { |
256 __currentError = __result; | 257 __currentError = __result; |
257 __goto = __handler; | 258 __goto = __handler; |
258 } | 259 } |
259 while (true) | 260 while (true) |
260 switch (__goto) { | 261 switch (__goto) { |
261 case 0: | 262 case 0: |
262 // Function start | 263 // Function start |
263 __temp1 = foo1(); | 264 __temp1 = foo1(); |
264 if (__temp1) | 265 if (__temp1) |
265 __result = __temp1; | 266 __result = __temp1; |
266 else { | 267 else { |
267 // goto then | 268 // goto then |
268 __goto = 2; | 269 __goto = 2; |
269 break; | 270 break; |
270 } | 271 } |
271 // goto join | 272 // goto join |
272 __goto = 3; | 273 __goto = 3; |
273 break; | 274 break; |
274 case 2: | 275 case 2: |
275 // then | 276 // then |
276 __goto = 4; | 277 __goto = 4; |
277 return thenHelper(foo2(), __body, __completer); | 278 return thenHelper(foo2(), body, __completer); |
278 case 4: | 279 case 4: |
279 // returning from await. | 280 // returning from await. |
280 case 3: | 281 case 3: |
281 // join | 282 // join |
282 a = __result; | 283 a = __result; |
283 __goto = 5; | 284 __goto = 5; |
284 return thenHelper(foo1(), __body, __completer); | 285 return thenHelper(foo1(), body, __completer); |
285 case 5: | 286 case 5: |
286 // returning from await. | 287 // returning from await. |
287 b = __result || foo2(); | 288 b = __result || foo2(); |
288 __goto = 8; | 289 __goto = 8; |
289 return thenHelper(foo1(), __body, __completer); | 290 return thenHelper(foo1(), body, __completer); |
290 case 8: | 291 case 8: |
291 // returning from await. | 292 // returning from await. |
292 __temp1 = __result; | 293 __temp1 = __result; |
293 if (__temp1) | 294 if (__temp1) |
294 __result = __temp1; | 295 __result = __temp1; |
295 else { | 296 else { |
296 // goto then | 297 // goto then |
297 __goto = 6; | 298 __goto = 6; |
298 break; | 299 break; |
299 } | 300 } |
300 // goto join | 301 // goto join |
301 __goto = 7; | 302 __goto = 7; |
302 break; | 303 break; |
303 case 6: | 304 case 6: |
304 // then | 305 // then |
305 __temp1 = foo3; | 306 __temp1 = foo3; |
306 __goto = 9; | 307 __goto = 9; |
307 return thenHelper(foo2(), __body, __completer); | 308 return thenHelper(foo2(), body, __completer); |
308 case 9: | 309 case 9: |
309 // returning from await. | 310 // returning from await. |
310 __result = __temp1(__result); | 311 __result = __temp1(__result); |
311 case 7: | 312 case 7: |
312 // join | 313 // join |
313 c = __result; | 314 c = __result; |
314 d = foo1() || foo2(); | 315 d = foo1() || foo2(); |
315 __temp1 = foo1(); | 316 __temp1 = foo1(); |
316 if (__temp1) { | 317 if (__temp1) { |
317 // goto then | 318 // goto then |
318 __goto = 10; | 319 __goto = 10; |
319 break; | 320 break; |
320 } else | 321 } else |
321 __result = __temp1; | 322 __result = __temp1; |
322 // goto join | 323 // goto join |
323 __goto = 11; | 324 __goto = 11; |
324 break; | 325 break; |
325 case 10: | 326 case 10: |
326 // then | 327 // then |
327 __goto = 12; | 328 __goto = 12; |
328 return thenHelper(foo2(), __body, __completer); | 329 return thenHelper(foo2(), body, __completer); |
329 case 12: | 330 case 12: |
330 // returning from await. | 331 // returning from await. |
331 case 11: | 332 case 11: |
332 // join | 333 // join |
333 e = __result; | 334 e = __result; |
334 __goto = 13; | 335 __goto = 13; |
335 return thenHelper(foo1(), __body, __completer); | 336 return thenHelper(foo1(), body, __completer); |
336 case 13: | 337 case 13: |
337 // returning from await. | 338 // returning from await. |
338 f = __result && foo2(); | 339 f = __result && foo2(); |
339 __goto = 16; | 340 __goto = 16; |
340 return thenHelper(foo1(), __body, __completer); | 341 return thenHelper(foo1(), body, __completer); |
341 case 16: | 342 case 16: |
342 // returning from await. | 343 // returning from await. |
343 __temp1 = __result; | 344 __temp1 = __result; |
344 if (__temp1) { | 345 if (__temp1) { |
345 // goto then | 346 // goto then |
346 __goto = 14; | 347 __goto = 14; |
347 break; | 348 break; |
348 } else | 349 } else |
349 __result = __temp1; | 350 __result = __temp1; |
350 // goto join | 351 // goto join |
351 __goto = 15; | 352 __goto = 15; |
352 break; | 353 break; |
353 case 14: | 354 case 14: |
354 // then | 355 // then |
355 __goto = 17; | 356 __goto = 17; |
356 return thenHelper(foo2(), __body, __completer); | 357 return thenHelper(foo2(), body, __completer); |
357 case 17: | 358 case 17: |
358 // returning from await. | 359 // returning from await. |
359 case 15: | 360 case 15: |
360 // join | 361 // join |
361 g = __result; | 362 g = __result; |
362 h = foo1() && foo2(); | 363 h = foo1() && foo2(); |
363 // implicit return | 364 // implicit return |
364 return thenHelper(null, 0, __completer, null); | 365 return thenHelper(null, 0, __completer, null); |
365 case 1: | 366 case 1: |
366 // rethrow | 367 // rethrow |
367 return thenHelper(__currentError, 1, __completer); | 368 return thenHelper(__currentError, 1, __completer); |
368 } | 369 } |
369 } | 370 } |
370 return thenHelper(null, __body, __completer, null); | 371 return thenHelper(null, body, __completer, null); |
371 }"""); | 372 }"""); |
372 | 373 |
373 testTransform(""" | 374 testTransform(""" |
374 function(x, y) async { | 375 function(x, y) async { |
375 while (true) { | 376 while (true) { |
376 switch(y) { // Switch with no awaits in case key expressions | 377 switch(y) { // Switch with no awaits in case key expressions |
377 case 0: | 378 case 0: |
378 case 1: | 379 case 1: |
379 await foo(); | 380 await foo(); |
380 continue; // Continue the loop, not the switch | 381 continue; // Continue the loop, not the switch |
381 case 1: // Duplicate case | 382 case 1: // Duplicate case |
382 await foo(); | 383 await foo(); |
383 break; // Break the switch | 384 break; // Break the switch |
384 case 2: | 385 case 2: |
385 foo(); // No default | 386 foo(); // No default |
386 } | 387 } |
387 } | 388 } |
388 }""", """ | 389 }""", """ |
389 function(x, y) { | 390 function(x, y) { |
390 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError; | 391 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError; |
391 function __body(__errorCode, __result) { | 392 function body(__errorCode, __result) { |
392 if (__errorCode === 1) { | 393 if (__errorCode === 1) { |
393 __currentError = __result; | 394 __currentError = __result; |
394 __goto = __handler; | 395 __goto = __handler; |
395 } | 396 } |
396 while (true) | 397 while (true) |
397 switch (__goto) { | 398 switch (__goto) { |
398 case 0: | 399 case 0: |
399 // Function start | 400 // Function start |
400 case 2: | 401 case 2: |
401 // while condition | 402 // while condition |
(...skipping 20 matching lines...) Expand all Loading... |
422 // goto after switch | 423 // goto after switch |
423 __goto = 5; | 424 __goto = 5; |
424 break; | 425 break; |
425 } | 426 } |
426 break; | 427 break; |
427 case 6: | 428 case 6: |
428 // case | 429 // case |
429 case 7: | 430 case 7: |
430 // case | 431 // case |
431 __goto = 10; | 432 __goto = 10; |
432 return thenHelper(foo(), __body, __completer); | 433 return thenHelper(foo(), body, __completer); |
433 case 10: | 434 case 10: |
434 // returning from await. | 435 // returning from await. |
435 // goto while condition | 436 // goto while condition |
436 __goto = 2; | 437 __goto = 2; |
437 break; | 438 break; |
438 case 8: | 439 case 8: |
439 // case | 440 // case |
440 __goto = 11; | 441 __goto = 11; |
441 return thenHelper(foo(), __body, __completer); | 442 return thenHelper(foo(), body, __completer); |
442 case 11: | 443 case 11: |
443 // returning from await. | 444 // returning from await. |
444 // goto after switch | 445 // goto after switch |
445 __goto = 5; | 446 __goto = 5; |
446 break; | 447 break; |
447 case 9: | 448 case 9: |
448 // case | 449 // case |
449 foo(); | 450 foo(); |
450 case 5: | 451 case 5: |
451 // after switch | 452 // after switch |
452 // goto while condition | 453 // goto while condition |
453 __goto = 2; | 454 __goto = 2; |
454 break; | 455 break; |
455 case 3: | 456 case 3: |
456 // after while | 457 // after while |
457 // implicit return | 458 // implicit return |
458 return thenHelper(null, 0, __completer, null); | 459 return thenHelper(null, 0, __completer, null); |
459 case 1: | 460 case 1: |
460 // rethrow | 461 // rethrow |
461 return thenHelper(__currentError, 1, __completer); | 462 return thenHelper(__currentError, 1, __completer); |
462 } | 463 } |
463 } | 464 } |
464 return thenHelper(null, __body, __completer, null); | 465 return thenHelper(null, body, __completer, null); |
465 }"""); | 466 }"""); |
466 | 467 |
467 testTransform(""" | 468 testTransform(""" |
468 function(f) async { | 469 function(f) async { |
469 do { | 470 do { |
470 var a = await foo(); | 471 var a = await foo(); |
471 if (a) // If with no awaits in body | 472 if (a) // If with no awaits in body |
472 break; | 473 break; |
473 else | 474 else |
474 continue; | 475 continue; |
475 } while (await foo()); | 476 } while (await foo()); |
476 } | 477 } |
477 """, """ | 478 """, """ |
478 function(f) { | 479 function(f) { |
479 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a; | 480 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a; |
480 function __body(__errorCode, __result) { | 481 function body(__errorCode, __result) { |
481 if (__errorCode === 1) { | 482 if (__errorCode === 1) { |
482 __currentError = __result; | 483 __currentError = __result; |
483 __goto = __handler; | 484 __goto = __handler; |
484 } | 485 } |
485 while (true) | 486 while (true) |
486 switch (__goto) { | 487 switch (__goto) { |
487 case 0: | 488 case 0: |
488 // Function start | 489 // Function start |
489 case 2: | 490 case 2: |
490 // do body | 491 // do body |
491 __goto = 5; | 492 __goto = 5; |
492 return thenHelper(foo(), __body, __completer); | 493 return thenHelper(foo(), body, __completer); |
493 case 5: | 494 case 5: |
494 // returning from await. | 495 // returning from await. |
495 a = __result; | 496 a = __result; |
496 if (a) { | 497 if (a) { |
497 // goto after do | 498 // goto after do |
498 __goto = 4; | 499 __goto = 4; |
499 break; | 500 break; |
500 } else { | 501 } else { |
501 // goto do condition | 502 // goto do condition |
502 __goto = 3; | 503 __goto = 3; |
503 break; | 504 break; |
504 } | 505 } |
505 case 3: | 506 case 3: |
506 // do condition | 507 // do condition |
507 __goto = 6; | 508 __goto = 6; |
508 return thenHelper(foo(), __body, __completer); | 509 return thenHelper(foo(), body, __completer); |
509 case 6: | 510 case 6: |
510 // returning from await. | 511 // returning from await. |
511 if (__result) { | 512 if (__result) { |
512 // goto do body | 513 // goto do body |
513 __goto = 2; | 514 __goto = 2; |
514 break; | 515 break; |
515 } | 516 } |
516 case 4: | 517 case 4: |
517 // after do | 518 // after do |
518 // implicit return | 519 // implicit return |
519 return thenHelper(null, 0, __completer, null); | 520 return thenHelper(null, 0, __completer, null); |
520 case 1: | 521 case 1: |
521 // rethrow | 522 // rethrow |
522 return thenHelper(__currentError, 1, __completer); | 523 return thenHelper(__currentError, 1, __completer); |
523 } | 524 } |
524 } | 525 } |
525 return thenHelper(null, __body, __completer, null); | 526 return thenHelper(null, body, __completer, null); |
526 }"""); | 527 }"""); |
527 | 528 |
528 testTransform(""" | 529 testTransform(""" |
529 function(g) async { | 530 function(g) async { |
530 for (var i = 0; i < await foo1(); i += await foo2()) { | 531 for (var i = 0; i < await foo1(); i += await foo2()) { |
531 if (foo(i)) | 532 if (foo(i)) |
532 continue; | 533 continue; |
533 else | 534 else |
534 break; | 535 break; |
535 if (!foo(i)) { // If with no else and await in body. | 536 if (!foo(i)) { // If with no else and await in body. |
536 await foo(); | 537 await foo(); |
537 return; | 538 return; |
538 } | 539 } |
539 print(await(foo(i))); | 540 print(await(foo(i))); |
540 } | 541 } |
541 } | 542 } |
542 """, """ | 543 """, """ |
543 function(g) { | 544 function(g) { |
544 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, i, __temp1; | 545 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, i, __temp1; |
545 function __body(__errorCode, __result) { | 546 function body(__errorCode, __result) { |
546 if (__errorCode === 1) { | 547 if (__errorCode === 1) { |
547 __currentError = __result; | 548 __currentError = __result; |
548 __goto = __handler; | 549 __goto = __handler; |
549 } | 550 } |
550 while (true) | 551 while (true) |
551 switch (__goto) { | 552 switch (__goto) { |
552 case 0: | 553 case 0: |
553 // Function start | 554 // Function start |
554 i = 0; | 555 i = 0; |
555 case 3: | 556 case 3: |
556 // for condition | 557 // for condition |
557 __temp1 = i; | 558 __temp1 = i; |
558 __goto = 6; | 559 __goto = 6; |
559 return thenHelper(foo1(), __body, __completer); | 560 return thenHelper(foo1(), body, __completer); |
560 case 6: | 561 case 6: |
561 // returning from await. | 562 // returning from await. |
562 if (!(__temp1 < __result)) { | 563 if (!(__temp1 < __result)) { |
563 // goto after for | 564 // goto after for |
564 __goto = 5; | 565 __goto = 5; |
565 break; | 566 break; |
566 } | 567 } |
567 if (foo(i)) { | 568 if (foo(i)) { |
568 // goto for update | 569 // goto for update |
569 __goto = 4; | 570 __goto = 4; |
570 break; | 571 break; |
571 } else { | 572 } else { |
572 // goto after for | 573 // goto after for |
573 __goto = 5; | 574 __goto = 5; |
574 break; | 575 break; |
575 } | 576 } |
576 __goto = !foo(i) ? 7 : 8; | 577 __goto = !foo(i) ? 7 : 8; |
577 break; | 578 break; |
578 case 7: | 579 case 7: |
579 // then | 580 // then |
580 __goto = 9; | 581 __goto = 9; |
581 return thenHelper(foo(), __body, __completer); | 582 return thenHelper(foo(), body, __completer); |
582 case 9: | 583 case 9: |
583 // returning from await. | 584 // returning from await. |
584 // goto return | 585 // goto return |
585 __goto = 1; | 586 __goto = 1; |
586 break; | 587 break; |
587 case 8: | 588 case 8: |
588 // join | 589 // join |
589 __temp1 = print; | 590 __temp1 = print; |
590 __goto = 10; | 591 __goto = 10; |
591 return thenHelper(foo(i), __body, __completer); | 592 return thenHelper(foo(i), body, __completer); |
592 case 10: | 593 case 10: |
593 // returning from await. | 594 // returning from await. |
594 __temp1(__result); | 595 __temp1(__result); |
595 case 4: | 596 case 4: |
596 // for update | 597 // for update |
597 __goto = 11; | 598 __goto = 11; |
598 return thenHelper(foo2(), __body, __completer); | 599 return thenHelper(foo2(), body, __completer); |
599 case 11: | 600 case 11: |
600 // returning from await. | 601 // returning from await. |
601 i += __result; | 602 i += __result; |
602 // goto for condition | 603 // goto for condition |
603 __goto = 3; | 604 __goto = 3; |
604 break; | 605 break; |
605 case 5: | 606 case 5: |
606 // after for | 607 // after for |
607 case 1: | 608 case 1: |
608 // return | 609 // return |
609 return thenHelper(__returnValue, 0, __completer, null); | 610 return thenHelper(__returnValue, 0, __completer, null); |
610 case 2: | 611 case 2: |
611 // rethrow | 612 // rethrow |
612 return thenHelper(__currentError, 1, __completer); | 613 return thenHelper(__currentError, 1, __completer); |
613 } | 614 } |
614 } | 615 } |
615 return thenHelper(null, __body, __completer, null); | 616 return thenHelper(null, body, __completer, null); |
616 }"""); | 617 }"""); |
617 | 618 |
618 testTransform(""" | 619 testTransform(""" |
619 function(a, h) async { | 620 function(a, h) async { |
620 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; | 621 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; |
621 x["a"] = 2; // Different assignments | 622 x["a"] = 2; // Different assignments |
622 (await foo()).a = 3; | 623 (await foo()).a = 3; |
623 x[await foo()] = 4; | 624 x[await foo()] = 4; |
624 x[(await foo1()).a = await foo2()] = 5; | 625 x[(await foo1()).a = await foo2()] = 5; |
625 (await foo1())[await foo2()] = await foo3(6); | 626 (await foo1())[await foo2()] = await foo3(6); |
626 } | 627 } |
627 """, """ | 628 """, """ |
628 function(a, h) { | 629 function(a, h) { |
629 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
x, __temp1, __temp2; | 630 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
x, __temp1, __temp2; |
630 function __body(__errorCode, __result) { | 631 function body(__errorCode, __result) { |
631 if (__errorCode === 1) { | 632 if (__errorCode === 1) { |
632 __currentError = __result; | 633 __currentError = __result; |
633 __goto = __handler; | 634 __goto = __handler; |
634 } | 635 } |
635 while (true) | 636 while (true) |
636 switch (__goto) { | 637 switch (__goto) { |
637 case 0: | 638 case 0: |
638 // Function start | 639 // Function start |
639 __temp1 = foo1(); | 640 __temp1 = foo1(); |
640 __goto = 2; | 641 __goto = 2; |
641 return thenHelper(foo2(), __body, __completer); | 642 return thenHelper(foo2(), body, __completer); |
642 case 2: | 643 case 2: |
643 // returning from await. | 644 // returning from await. |
644 x = {a: __temp1, b: __result, c: foo3()}; | 645 x = {a: __temp1, b: __result, c: foo3()}; |
645 x.a = 2; | 646 x.a = 2; |
646 __goto = 3; | 647 __goto = 3; |
647 return thenHelper(foo(), __body, __completer); | 648 return thenHelper(foo(), body, __completer); |
648 case 3: | 649 case 3: |
649 // returning from await. | 650 // returning from await. |
650 __result.a = 3; | 651 __result.a = 3; |
651 __temp1 = x; | 652 __temp1 = x; |
652 __goto = 4; | 653 __goto = 4; |
653 return thenHelper(foo(), __body, __completer); | 654 return thenHelper(foo(), body, __completer); |
654 case 4: | 655 case 4: |
655 // returning from await. | 656 // returning from await. |
656 __temp1[__result] = 4; | 657 __temp1[__result] = 4; |
657 __temp1 = x; | 658 __temp1 = x; |
658 __goto = 5; | 659 __goto = 5; |
659 return thenHelper(foo1(), __body, __completer); | 660 return thenHelper(foo1(), body, __completer); |
660 case 5: | 661 case 5: |
661 // returning from await. | 662 // returning from await. |
662 __temp2 = __result; | 663 __temp2 = __result; |
663 __goto = 6; | 664 __goto = 6; |
664 return thenHelper(foo2(), __body, __completer); | 665 return thenHelper(foo2(), body, __completer); |
665 case 6: | 666 case 6: |
666 // returning from await. | 667 // returning from await. |
667 __temp1[__temp2.a = __result] = 5; | 668 __temp1[__temp2.a = __result] = 5; |
668 __goto = 7; | 669 __goto = 7; |
669 return thenHelper(foo1(), __body, __completer); | 670 return thenHelper(foo1(), body, __completer); |
670 case 7: | 671 case 7: |
671 // returning from await. | 672 // returning from await. |
672 __temp1 = __result; | 673 __temp1 = __result; |
673 __goto = 8; | 674 __goto = 8; |
674 return thenHelper(foo2(), __body, __completer); | 675 return thenHelper(foo2(), body, __completer); |
675 case 8: | 676 case 8: |
676 // returning from await. | 677 // returning from await. |
677 __temp2 = __result; | 678 __temp2 = __result; |
678 __goto = 9; | 679 __goto = 9; |
679 return thenHelper(foo3(6), __body, __completer); | 680 return thenHelper(foo3(6), body, __completer); |
680 case 9: | 681 case 9: |
681 // returning from await. | 682 // returning from await. |
682 __temp1[__temp2] = __result; | 683 __temp1[__temp2] = __result; |
683 // implicit return | 684 // implicit return |
684 return thenHelper(null, 0, __completer, null); | 685 return thenHelper(null, 0, __completer, null); |
685 case 1: | 686 case 1: |
686 // rethrow | 687 // rethrow |
687 return thenHelper(__currentError, 1, __completer); | 688 return thenHelper(__currentError, 1, __completer); |
688 } | 689 } |
689 } | 690 } |
690 return thenHelper(null, __body, __completer, null); | 691 return thenHelper(null, body, __completer, null); |
691 }"""); | 692 }"""); |
692 | 693 |
693 testTransform(""" | 694 testTransform(""" |
694 function(c, i) async { | 695 function(c, i) async { |
695 try { | 696 try { |
696 var x = c ? await foo() : foo(); // conditional | 697 var x = c ? await foo() : foo(); // conditional |
697 var y = {}; | 698 var y = {}; |
698 } catch (error) { | 699 } catch (error) { |
699 try { | 700 try { |
700 x = c ? await fooError(error) : fooError(error); | 701 x = c ? await fooError(error) : fooError(error); |
701 } catch (error) { // nested error handler with overlapping name | 702 } catch (error) { // nested error handler with overlapping name |
702 y.x = foo(error); | 703 y.x = foo(error); |
703 } finally { | 704 } finally { |
704 foo(x); | 705 foo(x); |
705 } | 706 } |
706 } | 707 } |
707 } | 708 } |
708 """, """ | 709 """, """ |
709 function(c, i) { | 710 function(c, i) { |
710 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__next = [], x, y, __error, __error1; | 711 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__next = [], x, y, __error, __error1; |
711 function __body(__errorCode, __result) { | 712 function body(__errorCode, __result) { |
712 if (__errorCode === 1) { | 713 if (__errorCode === 1) { |
713 __currentError = __result; | 714 __currentError = __result; |
714 __goto = __handler; | 715 __goto = __handler; |
715 } | 716 } |
716 while (true) | 717 while (true) |
717 switch (__goto) { | 718 switch (__goto) { |
718 case 0: | 719 case 0: |
719 // Function start | 720 // Function start |
720 __handler = 3; | 721 __handler = 3; |
721 __goto = c ? 6 : 8; | 722 __goto = c ? 6 : 8; |
722 break; | 723 break; |
723 case 6: | 724 case 6: |
724 // then | 725 // then |
725 __goto = 9; | 726 __goto = 9; |
726 return thenHelper(foo(), __body, __completer); | 727 return thenHelper(foo(), body, __completer); |
727 case 9: | 728 case 9: |
728 // returning from await. | 729 // returning from await. |
729 // goto join | 730 // goto join |
730 __goto = 7; | 731 __goto = 7; |
731 break; | 732 break; |
732 case 8: | 733 case 8: |
733 // else | 734 // else |
734 __result = foo(); | 735 __result = foo(); |
735 case 7: | 736 case 7: |
736 // join | 737 // join |
737 x = __result; | 738 x = __result; |
738 y = {}; | 739 y = {}; |
739 __handler = 1; | 740 __handler = 1; |
740 // goto after finally | 741 // goto after finally |
741 __goto = 5; | 742 __goto = 5; |
742 break; | 743 break; |
743 case 3: | 744 case 3: |
744 // catch | 745 // catch |
745 __handler = 2; | 746 __handler = 2; |
746 __error = __currentError; | 747 __error = __currentError; |
747 __handler = 11; | 748 __handler = 11; |
748 __goto = c ? 14 : 16; | 749 __goto = c ? 14 : 16; |
749 break; | 750 break; |
750 case 14: | 751 case 14: |
751 // then | 752 // then |
752 __goto = 17; | 753 __goto = 17; |
753 return thenHelper(fooError(__error), __body, __completer); | 754 return thenHelper(fooError(__error), body, __completer); |
754 case 17: | 755 case 17: |
755 // returning from await. | 756 // returning from await. |
756 // goto join | 757 // goto join |
757 __goto = 15; | 758 __goto = 15; |
758 break; | 759 break; |
759 case 16: | 760 case 16: |
760 // else | 761 // else |
761 __result = fooError(__error); | 762 __result = fooError(__error); |
762 case 15: | 763 case 15: |
763 // join | 764 // join |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 break; | 798 break; |
798 case 5: | 799 case 5: |
799 // after finally | 800 // after finally |
800 // implicit return | 801 // implicit return |
801 return thenHelper(null, 0, __completer, null); | 802 return thenHelper(null, 0, __completer, null); |
802 case 1: | 803 case 1: |
803 // rethrow | 804 // rethrow |
804 return thenHelper(__currentError, 1, __completer); | 805 return thenHelper(__currentError, 1, __completer); |
805 } | 806 } |
806 } | 807 } |
807 return thenHelper(null, __body, __completer, null); | 808 return thenHelper(null, body, __completer, null); |
808 }"""); | 809 }"""); |
809 | 810 |
810 testTransform(""" | 811 testTransform(""" |
811 function(x, y, j) async { | 812 function(x, y, j) async { |
812 print(await(foo(x))); // calls | 813 print(await(foo(x))); // calls |
813 (await print)(foo(x)); | 814 (await print)(foo(x)); |
814 print(foo(await x)); | 815 print(foo(await x)); |
815 await (print(foo(await x))); | 816 await (print(foo(await x))); |
816 print(foo(x, await y, z)); | 817 print(foo(x, await y, z)); |
817 } | 818 } |
818 """, """ | 819 """, """ |
819 function(x, y, j) { | 820 function(x, y, j) { |
820 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__temp1, __temp2, __temp3; | 821 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__temp1, __temp2, __temp3; |
821 function __body(__errorCode, __result) { | 822 function body(__errorCode, __result) { |
822 if (__errorCode === 1) { | 823 if (__errorCode === 1) { |
823 __currentError = __result; | 824 __currentError = __result; |
824 __goto = __handler; | 825 __goto = __handler; |
825 } | 826 } |
826 while (true) | 827 while (true) |
827 switch (__goto) { | 828 switch (__goto) { |
828 case 0: | 829 case 0: |
829 // Function start | 830 // Function start |
830 __temp1 = print; | 831 __temp1 = print; |
831 __goto = 2; | 832 __goto = 2; |
832 return thenHelper(foo(x), __body, __completer); | 833 return thenHelper(foo(x), body, __completer); |
833 case 2: | 834 case 2: |
834 // returning from await. | 835 // returning from await. |
835 __temp1(__result); | 836 __temp1(__result); |
836 __goto = 3; | 837 __goto = 3; |
837 return thenHelper(print, __body, __completer); | 838 return thenHelper(print, body, __completer); |
838 case 3: | 839 case 3: |
839 // returning from await. | 840 // returning from await. |
840 __result(foo(x)); | 841 __result(foo(x)); |
841 __temp1 = print; | 842 __temp1 = print; |
842 __temp2 = foo; | 843 __temp2 = foo; |
843 __goto = 4; | 844 __goto = 4; |
844 return thenHelper(x, __body, __completer); | 845 return thenHelper(x, body, __completer); |
845 case 4: | 846 case 4: |
846 // returning from await. | 847 // returning from await. |
847 __temp1(__temp2(__result)); | 848 __temp1(__temp2(__result)); |
848 __temp1 = print; | 849 __temp1 = print; |
849 __temp2 = foo; | 850 __temp2 = foo; |
850 __goto = 6; | 851 __goto = 6; |
851 return thenHelper(x, __body, __completer); | 852 return thenHelper(x, body, __completer); |
852 case 6: | 853 case 6: |
853 // returning from await. | 854 // returning from await. |
854 __goto = 5; | 855 __goto = 5; |
855 return thenHelper(__temp1(__temp2(__result)), __body, __completer); | 856 return thenHelper(__temp1(__temp2(__result)), body, __completer); |
856 case 5: | 857 case 5: |
857 // returning from await. | 858 // returning from await. |
858 __temp1 = print; | 859 __temp1 = print; |
859 __temp2 = foo; | 860 __temp2 = foo; |
860 __temp3 = x; | 861 __temp3 = x; |
861 __goto = 7; | 862 __goto = 7; |
862 return thenHelper(y, __body, __completer); | 863 return thenHelper(y, body, __completer); |
863 case 7: | 864 case 7: |
864 // returning from await. | 865 // returning from await. |
865 __temp1(__temp2(__temp3, __result, z)); | 866 __temp1(__temp2(__temp3, __result, z)); |
866 // implicit return | 867 // implicit return |
867 return thenHelper(null, 0, __completer, null); | 868 return thenHelper(null, 0, __completer, null); |
868 case 1: | 869 case 1: |
869 // rethrow | 870 // rethrow |
870 return thenHelper(__currentError, 1, __completer); | 871 return thenHelper(__currentError, 1, __completer); |
871 } | 872 } |
872 } | 873 } |
873 return thenHelper(null, __body, __completer, null); | 874 return thenHelper(null, body, __completer, null); |
874 }"""); | 875 }"""); |
875 | 876 |
876 testTransform(""" | 877 testTransform(""" |
877 function(x, y, k) async { | 878 function(x, y, k) async { |
878 while (await(foo())) { | 879 while (await(foo())) { |
879 lab: { // labelled statement | 880 lab: { // labelled statement |
880 switch(y) { | 881 switch(y) { |
881 case 0: | 882 case 0: |
882 foo(); | 883 foo(); |
883 case 0: // Duplicate case | 884 case 0: // Duplicate case |
(...skipping 10 matching lines...) Expand all Loading... |
894 } | 895 } |
895 default: // defaul case | 896 default: // defaul case |
896 break lab; // break to label | 897 break lab; // break to label |
897 } | 898 } |
898 foo(); | 899 foo(); |
899 } | 900 } |
900 } | 901 } |
901 }""", """ | 902 }""", """ |
902 function(x, y, k) { | 903 function(x, y, k) { |
903 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, __temp1; | 904 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, __temp1; |
904 function __body(__errorCode, __result) { | 905 function body(__errorCode, __result) { |
905 if (__errorCode === 1) { | 906 if (__errorCode === 1) { |
906 __currentError = __result; | 907 __currentError = __result; |
907 __goto = __handler; | 908 __goto = __handler; |
908 } | 909 } |
909 while (true) | 910 while (true) |
910 switch (__goto) { | 911 switch (__goto) { |
911 case 0: | 912 case 0: |
912 // Function start | 913 // Function start |
913 case 3: | 914 case 3: |
914 // while condition | 915 // while condition |
915 __goto = 5; | 916 __goto = 5; |
916 return thenHelper(foo(), __body, __completer); | 917 return thenHelper(foo(), body, __completer); |
917 case 5: | 918 case 5: |
918 // returning from await. | 919 // returning from await. |
919 if (!__result) { | 920 if (!__result) { |
920 // goto after while | 921 // goto after while |
921 __goto = 4; | 922 __goto = 4; |
922 break; | 923 break; |
923 } | 924 } |
924 case 7: | 925 case 7: |
925 // switch | 926 // switch |
926 __temp1 = y; | 927 __temp1 = y; |
927 if (__temp1 === 0) { | 928 if (__temp1 === 0) { |
928 // goto case | 929 // goto case |
929 __goto = 9; | 930 __goto = 9; |
930 break; | 931 break; |
931 } | 932 } |
932 if (__temp1 === 0) { | 933 if (__temp1 === 0) { |
933 // goto case | 934 // goto case |
934 __goto = 10; | 935 __goto = 10; |
935 break; | 936 break; |
936 } | 937 } |
937 __goto = 12; | 938 __goto = 12; |
938 return thenHelper(bar(), __body, __completer); | 939 return thenHelper(bar(), body, __completer); |
939 case 12: | 940 case 12: |
940 // returning from await. | 941 // returning from await. |
941 if (__temp1 === __result) { | 942 if (__temp1 === __result) { |
942 // goto case | 943 // goto case |
943 __goto = 11; | 944 __goto = 11; |
944 break; | 945 break; |
945 } | 946 } |
946 if (__temp1 === x) { | 947 if (__temp1 === x) { |
947 // goto case | 948 // goto case |
948 __goto = 13; | 949 __goto = 13; |
949 break; | 950 break; |
950 } | 951 } |
951 // goto default | 952 // goto default |
952 __goto = 14; | 953 __goto = 14; |
953 break; | 954 break; |
954 case 9: | 955 case 9: |
955 // case | 956 // case |
956 foo(); | 957 foo(); |
957 case 10: | 958 case 10: |
958 // case | 959 // case |
959 __temp1 = print; | 960 __temp1 = print; |
960 __goto = 15; | 961 __goto = 15; |
961 return thenHelper(foo1(x), __body, __completer); | 962 return thenHelper(foo1(x), body, __completer); |
962 case 15: | 963 case 15: |
963 // returning from await. | 964 // returning from await. |
964 __temp1(__result); | 965 __temp1(__result); |
965 __returnValue = y; | 966 __returnValue = y; |
966 // goto return | 967 // goto return |
967 __goto = 1; | 968 __goto = 1; |
968 break; | 969 break; |
969 case 11: | 970 case 11: |
970 // case | 971 // case |
971 __temp1 = print; | 972 __temp1 = print; |
972 __goto = 16; | 973 __goto = 16; |
973 return thenHelper(foobar(x), __body, __completer); | 974 return thenHelper(foobar(x), body, __completer); |
974 case 16: | 975 case 16: |
975 // returning from await. | 976 // returning from await. |
976 __temp1(__result); | 977 __temp1(__result); |
977 __returnValue = y; | 978 __returnValue = y; |
978 // goto return | 979 // goto return |
979 __goto = 1; | 980 __goto = 1; |
980 break; | 981 break; |
981 case 13: | 982 case 13: |
982 // case | 983 // case |
983 if (a) | 984 if (a) |
(...skipping 19 matching lines...) Expand all Loading... |
1003 case 4: | 1004 case 4: |
1004 // after while | 1005 // after while |
1005 case 1: | 1006 case 1: |
1006 // return | 1007 // return |
1007 return thenHelper(__returnValue, 0, __completer, null); | 1008 return thenHelper(__returnValue, 0, __completer, null); |
1008 case 2: | 1009 case 2: |
1009 // rethrow | 1010 // rethrow |
1010 return thenHelper(__currentError, 1, __completer); | 1011 return thenHelper(__currentError, 1, __completer); |
1011 } | 1012 } |
1012 } | 1013 } |
1013 return thenHelper(null, __body, __completer, null); | 1014 return thenHelper(null, body, __completer, null); |
1014 }"""); | 1015 }"""); |
1015 testTransform(""" | 1016 testTransform(""" |
1016 function(l) async { | 1017 function(l) async { |
1017 switch(await l) { | 1018 switch(await l) { |
1018 case 1: | 1019 case 1: |
1019 print(1); | 1020 print(1); |
1020 break; | 1021 break; |
1021 case 2: | 1022 case 2: |
1022 print(1); | 1023 print(1); |
1023 // Fallthrough | 1024 // Fallthrough |
1024 default: | 1025 default: |
1025 print(2); | 1026 print(2); |
1026 break; | 1027 break; |
1027 } | 1028 } |
1028 }""", """ | 1029 }""", """ |
1029 function(l) { | 1030 function(l) { |
1030 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError; | 1031 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError; |
1031 function __body(__errorCode, __result) { | 1032 function body(__errorCode, __result) { |
1032 if (__errorCode === 1) { | 1033 if (__errorCode === 1) { |
1033 __currentError = __result; | 1034 __currentError = __result; |
1034 __goto = __handler; | 1035 __goto = __handler; |
1035 } | 1036 } |
1036 while (true) | 1037 while (true) |
1037 switch (__goto) { | 1038 switch (__goto) { |
1038 case 0: | 1039 case 0: |
1039 // Function start | 1040 // Function start |
1040 __goto = 2; | 1041 __goto = 2; |
1041 return thenHelper(l, __body, __completer); | 1042 return thenHelper(l, body, __completer); |
1042 case 2: | 1043 case 2: |
1043 // returning from await. | 1044 // returning from await. |
1044 switch (__result) { | 1045 switch (__result) { |
1045 case 1: | 1046 case 1: |
1046 print(1); | 1047 print(1); |
1047 break; | 1048 break; |
1048 case 2: | 1049 case 2: |
1049 print(1); | 1050 print(1); |
1050 default: | 1051 default: |
1051 print(2); | 1052 print(2); |
1052 break; | 1053 break; |
1053 } | 1054 } |
1054 // implicit return | 1055 // implicit return |
1055 return thenHelper(null, 0, __completer, null); | 1056 return thenHelper(null, 0, __completer, null); |
1056 case 1: | 1057 case 1: |
1057 // rethrow | 1058 // rethrow |
1058 return thenHelper(__currentError, 1, __completer); | 1059 return thenHelper(__currentError, 1, __completer); |
1059 } | 1060 } |
1060 } | 1061 } |
1061 return thenHelper(null, __body, __completer, null); | 1062 return thenHelper(null, body, __completer, null); |
1062 }"""); | 1063 }"""); |
1063 | 1064 |
1064 testTransform(""" | 1065 testTransform(""" |
1065 function(m) async { | 1066 function(m) async { |
1066 var exception = 1; | 1067 var exception = 1; |
1067 try { | 1068 try { |
1068 await 42; | 1069 await 42; |
1069 throw 42; | 1070 throw 42; |
1070 } catch (exception) { | 1071 } catch (exception) { |
1071 exception = await 10; | 1072 exception = await 10; |
1072 exception += await 10; | 1073 exception += await 10; |
1073 exception++; | 1074 exception++; |
1074 exception--; | 1075 exception--; |
1075 ++exception; | 1076 ++exception; |
1076 --exception; | 1077 --exception; |
1077 exception += 10; | 1078 exception += 10; |
1078 } | 1079 } |
1079 print(exception); | 1080 print(exception); |
1080 }""", """ | 1081 }""", """ |
1081 function(m) { | 1082 function(m) { |
1082 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__next = [], exception, __exception; | 1083 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__next = [], exception, __exception; |
1083 function __body(__errorCode, __result) { | 1084 function body(__errorCode, __result) { |
1084 if (__errorCode === 1) { | 1085 if (__errorCode === 1) { |
1085 __currentError = __result; | 1086 __currentError = __result; |
1086 __goto = __handler; | 1087 __goto = __handler; |
1087 } | 1088 } |
1088 while (true) | 1089 while (true) |
1089 switch (__goto) { | 1090 switch (__goto) { |
1090 case 0: | 1091 case 0: |
1091 // Function start | 1092 // Function start |
1092 exception = 1; | 1093 exception = 1; |
1093 __handler = 3; | 1094 __handler = 3; |
1094 __goto = 6; | 1095 __goto = 6; |
1095 return thenHelper(42, __body, __completer); | 1096 return thenHelper(42, body, __completer); |
1096 case 6: | 1097 case 6: |
1097 // returning from await. | 1098 // returning from await. |
1098 throw 42; | 1099 throw 42; |
1099 __handler = 1; | 1100 __handler = 1; |
1100 // goto after finally | 1101 // goto after finally |
1101 __goto = 5; | 1102 __goto = 5; |
1102 break; | 1103 break; |
1103 case 3: | 1104 case 3: |
1104 // catch | 1105 // catch |
1105 __handler = 2; | 1106 __handler = 2; |
1106 __exception = __currentError; | 1107 __exception = __currentError; |
1107 __goto = 7; | 1108 __goto = 7; |
1108 return thenHelper(10, __body, __completer); | 1109 return thenHelper(10, body, __completer); |
1109 case 7: | 1110 case 7: |
1110 // returning from await. | 1111 // returning from await. |
1111 __exception = __result; | 1112 __exception = __result; |
1112 __goto = 8; | 1113 __goto = 8; |
1113 return thenHelper(10, __body, __completer); | 1114 return thenHelper(10, body, __completer); |
1114 case 8: | 1115 case 8: |
1115 // returning from await. | 1116 // returning from await. |
1116 __exception += __result; | 1117 __exception += __result; |
1117 __exception++; | 1118 __exception++; |
1118 __exception--; | 1119 __exception--; |
1119 ++__exception; | 1120 ++__exception; |
1120 --__exception; | 1121 --__exception; |
1121 __exception += 10; | 1122 __exception += 10; |
1122 // goto after finally | 1123 // goto after finally |
1123 __goto = 5; | 1124 __goto = 5; |
1124 break; | 1125 break; |
1125 case 2: | 1126 case 2: |
1126 // uncaught | 1127 // uncaught |
1127 // goto rethrow | 1128 // goto rethrow |
1128 __goto = 1; | 1129 __goto = 1; |
1129 break; | 1130 break; |
1130 case 5: | 1131 case 5: |
1131 // after finally | 1132 // after finally |
1132 print(exception); | 1133 print(exception); |
1133 // implicit return | 1134 // implicit return |
1134 return thenHelper(null, 0, __completer, null); | 1135 return thenHelper(null, 0, __completer, null); |
1135 case 1: | 1136 case 1: |
1136 // rethrow | 1137 // rethrow |
1137 return thenHelper(__currentError, 1, __completer); | 1138 return thenHelper(__currentError, 1, __completer); |
1138 } | 1139 } |
1139 } | 1140 } |
1140 return thenHelper(null, __body, __completer, null); | 1141 return thenHelper(null, body, __completer, null); |
1141 }"""); | 1142 }"""); |
1142 } | 1143 } |
OLD | NEW |