| 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 import "package:compiler/src/js_backend/js_backend.dart" show StringBackedName; |
| 9 | 9 |
| 10 void testTransform(String source, String expected, AsyncRewriterBase rewriter) { | 10 void testTransform(String source, String expected, AsyncRewriterBase rewriter) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 var closures = [new A.main_closure()], v0 = await closures, v1 = 0, v2, v3; | 57 var closures = [new A.main_closure()], v0 = await closures, v1 = 0, v2, v3; |
| 58 if (v1 < 0 || v1 >= v0.length) | 58 if (v1 < 0 || v1 >= v0.length) |
| 59 H.ioore(v0, v1); | 59 H.ioore(v0, v1); |
| 60 v2 = 4; | 60 v2 = 4; |
| 61 v3 = 2; | 61 v3 = 2; |
| 62 P.print(v0[v1].call$2(v2, v3)); | 62 P.print(v0[v1].call$2(v2, v3)); |
| 63 }""", | 63 }""", |
| 64 | 64 |
| 65 /// 01: ok | 65 /// 01: ok |
| 66 r"""function() { | 66 r"""function() { |
| 67 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, c
losures, v0, v1, v2, v3; | 67 var __goto = 0, __completer = NewCompleter(), closures, v0, v1, v2, v3; |
| 68 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 68 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 69 if (__errorCode === 1) { | 69 if (__errorCode === 1) |
| 70 __currentError = __result; | 70 return rethrowHelper(__result, __completer); |
| 71 __goto = __handler; | |
| 72 } | |
| 73 while (true) | 71 while (true) |
| 74 switch (__goto) { | 72 switch (__goto) { |
| 75 case 0: | 73 case 0: |
| 76 // Function start | 74 // Function start |
| 77 closures = [new A.main_closure()]; | 75 closures = [new A.main_closure()]; |
| 78 __goto = 2; | 76 __goto = 2; |
| 79 return awaitHelper(closures, body); | 77 return awaitHelper(closures, body); |
| 80 case 2: | 78 case 2: |
| 81 // returning from await. | 79 // returning from await. |
| 82 v0 = __result; | 80 v0 = __result; |
| 83 v1 = 0; | 81 v1 = 0; |
| 84 if (v1 < 0 || v1 >= v0.length) | 82 if (v1 < 0 || v1 >= v0.length) |
| 85 H.ioore(v0, v1); | 83 H.ioore(v0, v1); |
| 86 v2 = 4; | 84 v2 = 4; |
| 87 v3 = 2; | 85 v3 = 2; |
| 88 P.print(v0[v1].call$2(v2, v3)); | 86 P.print(v0[v1].call$2(v2, v3)); |
| 89 // implicit return | 87 // implicit return |
| 90 return returnHelper(null, __completer); | 88 return returnHelper(null, __completer); |
| 91 case 1: | |
| 92 // rethrow | |
| 93 return rethrowHelper(__currentError, __completer); | |
| 94 } | 89 } |
| 95 }); | 90 }); |
| 96 return startHelper(body, __completer); | 91 return startHelper(body, __completer); |
| 97 }""") | 92 }""") |
| 98 | 93 |
| 99 /// 01: ok | 94 /// 01: ok |
| 100 ; | 95 ; |
| 101 | 96 |
| 102 testAsyncTransform( | 97 testAsyncTransform( |
| 103 """ | 98 """ |
| 104 function(a) async { | 99 function(a) async { |
| 105 print(this.x); // Ensure `this` is translated in the helper function. | 100 print(this.x); // Ensure `this` is translated in the helper function. |
| 106 await foo(); | 101 await foo(); |
| 107 }""", | 102 }""", |
| 108 """ | 103 """ |
| 109 function(a) { | 104 function(a) { |
| 110 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
_self = this; | 105 var __goto = 0, __completer = NewCompleter(), __self = this; |
| 111 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 106 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 112 if (__errorCode === 1) { | 107 if (__errorCode === 1) |
| 113 __currentError = __result; | 108 return rethrowHelper(__result, __completer); |
| 114 __goto = __handler; | |
| 115 } | |
| 116 while (true) | 109 while (true) |
| 117 switch (__goto) { | 110 switch (__goto) { |
| 118 case 0: | 111 case 0: |
| 119 // Function start | 112 // Function start |
| 120 print(__self.x); | 113 print(__self.x); |
| 121 __goto = 2; | 114 __goto = 2; |
| 122 return awaitHelper(foo(), body); | 115 return awaitHelper(foo(), body); |
| 123 case 2: | 116 case 2: |
| 124 // returning from await. | 117 // returning from await. |
| 125 // implicit return | 118 // implicit return |
| 126 return returnHelper(null, __completer); | 119 return returnHelper(null, __completer); |
| 127 case 1: | |
| 128 // rethrow | |
| 129 return rethrowHelper(__currentError, __completer); | |
| 130 } | 120 } |
| 131 }); | 121 }); |
| 132 return startHelper(body, __completer); | 122 return startHelper(body, __completer); |
| 133 }"""); | 123 }"""); |
| 134 | 124 |
| 135 testAsyncTransform( | 125 testAsyncTransform( |
| 136 """ | 126 """ |
| 137 function(b) async { | 127 function(b) async { |
| 138 try { | 128 try { |
| 139 __outer: while (true) { // Overlapping label name. | 129 __outer: while (true) { // Overlapping label name. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 var a, b, c, d, e, f; | 254 var a, b, c, d, e, f; |
| 265 a = b++; // post- and preincrements. | 255 a = b++; // post- and preincrements. |
| 266 b = --b; | 256 b = --b; |
| 267 c = (await foo()).a++; | 257 c = (await foo()).a++; |
| 268 d = ++(await foo()).a; | 258 d = ++(await foo()).a; |
| 269 e = foo1()[await foo2()]--; | 259 e = foo1()[await foo2()]--; |
| 270 f = --foo1()[await foo2()]; | 260 f = --foo1()[await foo2()]; |
| 271 }""", | 261 }""", |
| 272 """ | 262 """ |
| 273 function(c) { | 263 function(c) { |
| 274 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, a
, b, c, d, e, f, __temp1; | 264 var __goto = 0, __completer = NewCompleter(), a, b, c, d, e, f, __temp1; |
| 275 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 265 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 276 if (__errorCode === 1) { | 266 if (__errorCode === 1) |
| 277 __currentError = __result; | 267 return rethrowHelper(__result, __completer); |
| 278 __goto = __handler; | |
| 279 } | |
| 280 while (true) | 268 while (true) |
| 281 switch (__goto) { | 269 switch (__goto) { |
| 282 case 0: | 270 case 0: |
| 283 // Function start | 271 // Function start |
| 284 a = b++; | 272 a = b++; |
| 285 b = --b; | 273 b = --b; |
| 286 __goto = 2; | 274 __goto = 2; |
| 287 return awaitHelper(foo(), body); | 275 return awaitHelper(foo(), body); |
| 288 case 2: | 276 case 2: |
| 289 // returning from await. | 277 // returning from await. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 300 // returning from await. | 288 // returning from await. |
| 301 e = __temp1[__result]--; | 289 e = __temp1[__result]--; |
| 302 __temp1 = foo1(); | 290 __temp1 = foo1(); |
| 303 __goto = 5; | 291 __goto = 5; |
| 304 return awaitHelper(foo2(), body); | 292 return awaitHelper(foo2(), body); |
| 305 case 5: | 293 case 5: |
| 306 // returning from await. | 294 // returning from await. |
| 307 f = --__temp1[__result]; | 295 f = --__temp1[__result]; |
| 308 // implicit return | 296 // implicit return |
| 309 return returnHelper(null, __completer); | 297 return returnHelper(null, __completer); |
| 310 case 1: | |
| 311 // rethrow | |
| 312 return rethrowHelper(__currentError, __completer); | |
| 313 } | 298 } |
| 314 }); | 299 }); |
| 315 return startHelper(body, __completer); | 300 return startHelper(body, __completer); |
| 316 }"""); | 301 }"""); |
| 317 | 302 |
| 318 testAsyncTransform( | 303 testAsyncTransform( |
| 319 """ | 304 """ |
| 320 function(d2) async { | 305 function(d2) async { |
| 321 var a, b, c, d, e, f, g, h; // empty initializer | 306 var a, b, c, d, e, f, g, h; // empty initializer |
| 322 a = foo1() || await foo2(); // short circuiting operators | 307 a = foo1() || await foo2(); // short circuiting operators |
| 323 b = await foo1() || foo2(); | 308 b = await foo1() || foo2(); |
| 324 c = await foo1() || foo3(await foo2()); | 309 c = await foo1() || foo3(await foo2()); |
| 325 d = foo1() || foo2(); | 310 d = foo1() || foo2(); |
| 326 e = foo1() && await foo2(); | 311 e = foo1() && await foo2(); |
| 327 f = await foo1() && foo2(); | 312 f = await foo1() && foo2(); |
| 328 g = await foo1() && await foo2(); | 313 g = await foo1() && await foo2(); |
| 329 h = foo1() && foo2(); | 314 h = foo1() && foo2(); |
| 330 }""", | 315 }""", |
| 331 """ | 316 """ |
| 332 function(d2) { | 317 function(d2) { |
| 333 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, a
, b, c, d, e, f, g, h, __temp1; | 318 var __goto = 0, __completer = NewCompleter(), a, b, c, d, e, f, g, h, __temp1; |
| 334 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 319 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 335 if (__errorCode === 1) { | 320 if (__errorCode === 1) |
| 336 __currentError = __result; | 321 return rethrowHelper(__result, __completer); |
| 337 __goto = __handler; | |
| 338 } | |
| 339 while (true) | 322 while (true) |
| 340 switch (__goto) { | 323 switch (__goto) { |
| 341 case 0: | 324 case 0: |
| 342 // Function start | 325 // Function start |
| 343 __temp1 = foo1(); | 326 __temp1 = foo1(); |
| 344 if (__temp1) | 327 if (__temp1) |
| 345 __result = __temp1; | 328 __result = __temp1; |
| 346 else { | 329 else { |
| 347 // goto then | 330 // goto then |
| 348 __goto = 2; | 331 __goto = 2; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 __goto = 17; | 418 __goto = 17; |
| 436 return awaitHelper(foo2(), body); | 419 return awaitHelper(foo2(), body); |
| 437 case 17: | 420 case 17: |
| 438 // returning from await. | 421 // returning from await. |
| 439 case 15: | 422 case 15: |
| 440 // join | 423 // join |
| 441 g = __result; | 424 g = __result; |
| 442 h = foo1() && foo2(); | 425 h = foo1() && foo2(); |
| 443 // implicit return | 426 // implicit return |
| 444 return returnHelper(null, __completer); | 427 return returnHelper(null, __completer); |
| 445 case 1: | |
| 446 // rethrow | |
| 447 return rethrowHelper(__currentError, __completer); | |
| 448 } | 428 } |
| 449 }); | 429 }); |
| 450 return startHelper(body, __completer); | 430 return startHelper(body, __completer); |
| 451 }"""); | 431 }"""); |
| 452 | 432 |
| 453 testAsyncTransform( | 433 testAsyncTransform( |
| 454 """ | 434 """ |
| 455 function(x, y) async { | 435 function(x, y) async { |
| 456 while (true) { | 436 while (true) { |
| 457 switch(y) { // Switch with no awaits in case key expressions | 437 switch(y) { // Switch with no awaits in case key expressions |
| 458 case 0: | 438 case 0: |
| 459 case 1: | 439 case 1: |
| 460 await foo(); | 440 await foo(); |
| 461 continue; // Continue the loop, not the switch | 441 continue; // Continue the loop, not the switch |
| 462 case 1: // Duplicate case | 442 case 1: // Duplicate case |
| 463 await foo(); | 443 await foo(); |
| 464 break; // Break the switch | 444 break; // Break the switch |
| 465 case 2: | 445 case 2: |
| 466 foo(); // No default | 446 foo(); // No default |
| 467 } | 447 } |
| 468 } | 448 } |
| 469 }""", | 449 }""", |
| 470 """ | 450 """ |
| 471 function(x, y) { | 451 function(x, y) { |
| 472 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError; | 452 var __goto = 0, __completer = NewCompleter(); |
| 473 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 453 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 474 if (__errorCode === 1) { | 454 if (__errorCode === 1) |
| 475 __currentError = __result; | 455 return rethrowHelper(__result, __completer); |
| 476 __goto = __handler; | |
| 477 } | |
| 478 while (true) | 456 while (true) |
| 479 switch (__goto) { | 457 switch (__goto) { |
| 480 case 0: | 458 case 0: |
| 481 // Function start | 459 // Function start |
| 482 case 2: | 460 case 2: |
| 483 // while condition | 461 // while condition |
| 484 case 4: | 462 case 4: |
| 485 // switch | 463 // switch |
| 486 switch (y) { | 464 switch (y) { |
| 487 case 0: | 465 case 0: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 foo(); | 509 foo(); |
| 532 case 5: | 510 case 5: |
| 533 // after switch | 511 // after switch |
| 534 // goto while condition | 512 // goto while condition |
| 535 __goto = 2; | 513 __goto = 2; |
| 536 break; | 514 break; |
| 537 case 3: | 515 case 3: |
| 538 // after while | 516 // after while |
| 539 // implicit return | 517 // implicit return |
| 540 return returnHelper(null, __completer); | 518 return returnHelper(null, __completer); |
| 541 case 1: | |
| 542 // rethrow | |
| 543 return rethrowHelper(__currentError, __completer); | |
| 544 } | 519 } |
| 545 }); | 520 }); |
| 546 return startHelper(body, __completer); | 521 return startHelper(body, __completer); |
| 547 }"""); | 522 }"""); |
| 548 | 523 |
| 549 testAsyncTransform( | 524 testAsyncTransform( |
| 550 """ | 525 """ |
| 551 function(f) async { | 526 function(f) async { |
| 552 do { | 527 do { |
| 553 var a = await foo(); | 528 var a = await foo(); |
| 554 if (a) // If with no awaits in body | 529 if (a) // If with no awaits in body |
| 555 break; | 530 break; |
| 556 else | 531 else |
| 557 continue; | 532 continue; |
| 558 } while (await foo()); | 533 } while (await foo()); |
| 559 } | 534 } |
| 560 """, | 535 """, |
| 561 """ | 536 """ |
| 562 function(f) { | 537 function(f) { |
| 563 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, a
; | 538 var __goto = 0, __completer = NewCompleter(), a; |
| 564 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 539 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 565 if (__errorCode === 1) { | 540 if (__errorCode === 1) |
| 566 __currentError = __result; | 541 return rethrowHelper(__result, __completer); |
| 567 __goto = __handler; | |
| 568 } | |
| 569 while (true) | 542 while (true) |
| 570 switch (__goto) { | 543 switch (__goto) { |
| 571 case 0: | 544 case 0: |
| 572 // Function start | 545 // Function start |
| 573 case 2: | 546 case 2: |
| 574 // do body | 547 // do body |
| 575 __goto = 5; | 548 __goto = 5; |
| 576 return awaitHelper(foo(), body); | 549 return awaitHelper(foo(), body); |
| 577 case 5: | 550 case 5: |
| 578 // returning from await. | 551 // returning from await. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 594 // returning from await. | 567 // returning from await. |
| 595 if (__result) { | 568 if (__result) { |
| 596 // goto do body | 569 // goto do body |
| 597 __goto = 2; | 570 __goto = 2; |
| 598 break; | 571 break; |
| 599 } | 572 } |
| 600 case 4: | 573 case 4: |
| 601 // after do | 574 // after do |
| 602 // implicit return | 575 // implicit return |
| 603 return returnHelper(null, __completer); | 576 return returnHelper(null, __completer); |
| 604 case 1: | |
| 605 // rethrow | |
| 606 return rethrowHelper(__currentError, __completer); | |
| 607 } | 577 } |
| 608 }); | 578 }); |
| 609 return startHelper(body, __completer); | 579 return startHelper(body, __completer); |
| 610 }"""); | 580 }"""); |
| 611 | 581 |
| 612 testAsyncTransform( | 582 testAsyncTransform( |
| 613 """ | 583 """ |
| 614 function(g) async { | 584 function(g) async { |
| 615 for (var i = 0; i < await foo1(); i += await foo2()) { | 585 for (var i = 0; i < await foo1(); i += await foo2()) { |
| 616 if (foo(i)) | 586 if (foo(i)) |
| 617 continue; | 587 continue; |
| 618 else | 588 else |
| 619 break; | 589 break; |
| 620 if (!foo(i)) { // If with no else and await in body. | 590 if (!foo(i)) { // If with no else and await in body. |
| 621 await foo(); | 591 await foo(); |
| 622 return; | 592 return; |
| 623 } | 593 } |
| 624 print(await(foo(i))); | 594 print(await(foo(i))); |
| 625 } | 595 } |
| 626 } | 596 } |
| 627 """, | 597 """, |
| 628 """ | 598 """ |
| 629 function(g) { | 599 function(g) { |
| 630 var __goto = 0, __completer = NewCompleter(), __returnValue, __handler = 2, __
currentError, i, __temp1; | 600 var __goto = 0, __completer = NewCompleter(), __returnValue, i, __temp1; |
| 631 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 601 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 632 if (__errorCode === 1) { | 602 if (__errorCode === 1) |
| 633 __currentError = __result; | 603 return rethrowHelper(__result, __completer); |
| 634 __goto = __handler; | |
| 635 } | |
| 636 while (true) | 604 while (true) |
| 637 switch (__goto) { | 605 switch (__goto) { |
| 638 case 0: | 606 case 0: |
| 639 // Function start | 607 // Function start |
| 640 i = 0; | 608 i = 0; |
| 641 case 3: | 609 case 3: |
| 642 // for condition | 610 // for condition |
| 643 __temp1 = i; | 611 __temp1 = i; |
| 644 __goto = 6; | 612 __goto = 6; |
| 645 return awaitHelper(foo1(), body); | 613 return awaitHelper(foo1(), body); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 // returning from await. | 654 // returning from await. |
| 687 i += __result; | 655 i += __result; |
| 688 // goto for condition | 656 // goto for condition |
| 689 __goto = 3; | 657 __goto = 3; |
| 690 break; | 658 break; |
| 691 case 5: | 659 case 5: |
| 692 // after for | 660 // after for |
| 693 case 1: | 661 case 1: |
| 694 // return | 662 // return |
| 695 return returnHelper(__returnValue, __completer); | 663 return returnHelper(__returnValue, __completer); |
| 696 case 2: | |
| 697 // rethrow | |
| 698 return rethrowHelper(__currentError, __completer); | |
| 699 } | 664 } |
| 700 }); | 665 }); |
| 701 return startHelper(body, __completer); | 666 return startHelper(body, __completer); |
| 702 }"""); | 667 }"""); |
| 703 | 668 |
| 704 testAsyncTransform( | 669 testAsyncTransform( |
| 705 """ | 670 """ |
| 706 function(a, h) async { | 671 function(a, h) async { |
| 707 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; | 672 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; |
| 708 x["a"] = 2; // Different assignments | 673 x["a"] = 2; // Different assignments |
| 709 (await foo()).a = 3; | 674 (await foo()).a = 3; |
| 710 x[await foo()] = 4; | 675 x[await foo()] = 4; |
| 711 x[(await foo1()).a = await foo2()] = 5; | 676 x[(await foo1()).a = await foo2()] = 5; |
| 712 (await foo1())[await foo2()] = await foo3(6); | 677 (await foo1())[await foo2()] = await foo3(6); |
| 713 } | 678 } |
| 714 """, | 679 """, |
| 715 """ | 680 """ |
| 716 function(a, h) { | 681 function(a, h) { |
| 717 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, x
, __temp1, __temp2; | 682 var __goto = 0, __completer = NewCompleter(), x, __temp1, __temp2; |
| 718 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 683 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 719 if (__errorCode === 1) { | 684 if (__errorCode === 1) |
| 720 __currentError = __result; | 685 return rethrowHelper(__result, __completer); |
| 721 __goto = __handler; | |
| 722 } | |
| 723 while (true) | 686 while (true) |
| 724 switch (__goto) { | 687 switch (__goto) { |
| 725 case 0: | 688 case 0: |
| 726 // Function start | 689 // Function start |
| 727 __temp1 = foo1(); | 690 __temp1 = foo1(); |
| 728 __goto = 2; | 691 __goto = 2; |
| 729 return awaitHelper(foo2(), body); | 692 return awaitHelper(foo2(), body); |
| 730 case 2: | 693 case 2: |
| 731 // returning from await. | 694 // returning from await. |
| 732 x = {a: __temp1, b: __result, c: foo3()}; | 695 x = {a: __temp1, b: __result, c: foo3()}; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 763 case 8: | 726 case 8: |
| 764 // returning from await. | 727 // returning from await. |
| 765 __temp2 = __result; | 728 __temp2 = __result; |
| 766 __goto = 9; | 729 __goto = 9; |
| 767 return awaitHelper(foo3(6), body); | 730 return awaitHelper(foo3(6), body); |
| 768 case 9: | 731 case 9: |
| 769 // returning from await. | 732 // returning from await. |
| 770 __temp1[__temp2] = __result; | 733 __temp1[__temp2] = __result; |
| 771 // implicit return | 734 // implicit return |
| 772 return returnHelper(null, __completer); | 735 return returnHelper(null, __completer); |
| 773 case 1: | |
| 774 // rethrow | |
| 775 return rethrowHelper(__currentError, __completer); | |
| 776 } | 736 } |
| 777 }); | 737 }); |
| 778 return startHelper(body, __completer); | 738 return startHelper(body, __completer); |
| 779 }"""); | 739 }"""); |
| 780 | 740 |
| 781 testAsyncTransform( | 741 testAsyncTransform( |
| 782 """ | 742 """ |
| 783 function(c, i) async { | 743 function(c, i) async { |
| 784 try { | 744 try { |
| 785 var x = c ? await foo() : foo(); // conditional | 745 var x = c ? await foo() : foo(); // conditional |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 function(x, y, j) async { | 862 function(x, y, j) async { |
| 903 print(await(foo(x))); // calls | 863 print(await(foo(x))); // calls |
| 904 (await print)(foo(x)); | 864 (await print)(foo(x)); |
| 905 print(foo(await x)); | 865 print(foo(await x)); |
| 906 await (print(foo(await x))); | 866 await (print(foo(await x))); |
| 907 print(foo(x, await y, z)); | 867 print(foo(x, await y, z)); |
| 908 } | 868 } |
| 909 """, | 869 """, |
| 910 """ | 870 """ |
| 911 function(x, y, j) { | 871 function(x, y, j) { |
| 912 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
_temp1, __temp2, __temp3; | 872 var __goto = 0, __completer = NewCompleter(), __temp1, __temp2, __temp3; |
| 913 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 873 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 914 if (__errorCode === 1) { | 874 if (__errorCode === 1) |
| 915 __currentError = __result; | 875 return rethrowHelper(__result, __completer); |
| 916 __goto = __handler; | |
| 917 } | |
| 918 while (true) | 876 while (true) |
| 919 switch (__goto) { | 877 switch (__goto) { |
| 920 case 0: | 878 case 0: |
| 921 // Function start | 879 // Function start |
| 922 __temp1 = print; | 880 __temp1 = print; |
| 923 __goto = 2; | 881 __goto = 2; |
| 924 return awaitHelper(foo(x), body); | 882 return awaitHelper(foo(x), body); |
| 925 case 2: | 883 case 2: |
| 926 // returning from await. | 884 // returning from await. |
| 927 __temp1(__result); | 885 __temp1(__result); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 950 __temp1 = print; | 908 __temp1 = print; |
| 951 __temp2 = foo; | 909 __temp2 = foo; |
| 952 __temp3 = x; | 910 __temp3 = x; |
| 953 __goto = 7; | 911 __goto = 7; |
| 954 return awaitHelper(y, body); | 912 return awaitHelper(y, body); |
| 955 case 7: | 913 case 7: |
| 956 // returning from await. | 914 // returning from await. |
| 957 __temp1(__temp2(__temp3, __result, z)); | 915 __temp1(__temp2(__temp3, __result, z)); |
| 958 // implicit return | 916 // implicit return |
| 959 return returnHelper(null, __completer); | 917 return returnHelper(null, __completer); |
| 960 case 1: | |
| 961 // rethrow | |
| 962 return rethrowHelper(__currentError, __completer); | |
| 963 } | 918 } |
| 964 }); | 919 }); |
| 965 return startHelper(body, __completer); | 920 return startHelper(body, __completer); |
| 966 }"""); | 921 }"""); |
| 967 | 922 |
| 968 testAsyncTransform( | 923 testAsyncTransform( |
| 969 """ | 924 """ |
| 970 function(x, y, k) async { | 925 function(x, y, k) async { |
| 971 while (await(foo())) { | 926 while (await(foo())) { |
| 972 lab: { // labelled statement | 927 lab: { // labelled statement |
| (...skipping 14 matching lines...) Expand all Loading... |
| 987 } | 942 } |
| 988 default: // default case | 943 default: // default case |
| 989 break lab; // break to label | 944 break lab; // break to label |
| 990 } | 945 } |
| 991 foo(); | 946 foo(); |
| 992 } | 947 } |
| 993 } | 948 } |
| 994 }""", | 949 }""", |
| 995 """ | 950 """ |
| 996 function(x, y, k) { | 951 function(x, y, k) { |
| 997 var __goto = 0, __completer = NewCompleter(), __returnValue, __handler = 2, __
currentError, __temp1; | 952 var __goto = 0, __completer = NewCompleter(), __returnValue, __temp1; |
| 998 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 953 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 999 if (__errorCode === 1) { | 954 if (__errorCode === 1) |
| 1000 __currentError = __result; | 955 return rethrowHelper(__result, __completer); |
| 1001 __goto = __handler; | |
| 1002 } | |
| 1003 while (true) | 956 while (true) |
| 1004 switch (__goto) { | 957 switch (__goto) { |
| 1005 case 0: | 958 case 0: |
| 1006 // Function start | 959 // Function start |
| 1007 case 3: | 960 case 3: |
| 1008 // while condition | 961 // while condition |
| 1009 __goto = 5; | 962 __goto = 5; |
| 1010 return awaitHelper(foo(), body); | 963 return awaitHelper(foo(), body); |
| 1011 case 5: | 964 case 5: |
| 1012 // returning from await. | 965 // returning from await. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 case 6: | 1045 case 6: |
| 1093 // break lab | 1046 // break lab |
| 1094 // goto while condition | 1047 // goto while condition |
| 1095 __goto = 3; | 1048 __goto = 3; |
| 1096 break; | 1049 break; |
| 1097 case 4: | 1050 case 4: |
| 1098 // after while | 1051 // after while |
| 1099 case 1: | 1052 case 1: |
| 1100 // return | 1053 // return |
| 1101 return returnHelper(__returnValue, __completer); | 1054 return returnHelper(__returnValue, __completer); |
| 1102 case 2: | |
| 1103 // rethrow | |
| 1104 return rethrowHelper(__currentError, __completer); | |
| 1105 } | 1055 } |
| 1106 }); | 1056 }); |
| 1107 return startHelper(body, __completer); | 1057 return startHelper(body, __completer); |
| 1108 }"""); | 1058 }"""); |
| 1109 | 1059 |
| 1110 testAsyncTransform( | 1060 testAsyncTransform( |
| 1111 """ | 1061 """ |
| 1112 function(l) async { | 1062 function(l) async { |
| 1113 switch(await l) { | 1063 switch(await l) { |
| 1114 case 1: | 1064 case 1: |
| 1115 print(1); | 1065 print(1); |
| 1116 break; | 1066 break; |
| 1117 case 2: | 1067 case 2: |
| 1118 print(1); | 1068 print(1); |
| 1119 // Fallthrough | 1069 // Fallthrough |
| 1120 default: | 1070 default: |
| 1121 print(2); | 1071 print(2); |
| 1122 break; | 1072 break; |
| 1123 } | 1073 } |
| 1124 }""", | 1074 }""", |
| 1125 """ | 1075 """ |
| 1126 function(l) { | 1076 function(l) { |
| 1127 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError; | 1077 var __goto = 0, __completer = NewCompleter(); |
| 1128 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 1078 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 1129 if (__errorCode === 1) { | 1079 if (__errorCode === 1) |
| 1130 __currentError = __result; | 1080 return rethrowHelper(__result, __completer); |
| 1131 __goto = __handler; | |
| 1132 } | |
| 1133 while (true) | 1081 while (true) |
| 1134 switch (__goto) { | 1082 switch (__goto) { |
| 1135 case 0: | 1083 case 0: |
| 1136 // Function start | 1084 // Function start |
| 1137 __goto = 2; | 1085 __goto = 2; |
| 1138 return awaitHelper(l, body); | 1086 return awaitHelper(l, body); |
| 1139 case 2: | 1087 case 2: |
| 1140 // returning from await. | 1088 // returning from await. |
| 1141 switch (__result) { | 1089 switch (__result) { |
| 1142 case 1: | 1090 case 1: |
| 1143 print(1); | 1091 print(1); |
| 1144 break; | 1092 break; |
| 1145 case 2: | 1093 case 2: |
| 1146 print(1); | 1094 print(1); |
| 1147 default: | 1095 default: |
| 1148 print(2); | 1096 print(2); |
| 1149 break; | 1097 break; |
| 1150 } | 1098 } |
| 1151 // implicit return | 1099 // implicit return |
| 1152 return returnHelper(null, __completer); | 1100 return returnHelper(null, __completer); |
| 1153 case 1: | |
| 1154 // rethrow | |
| 1155 return rethrowHelper(__currentError, __completer); | |
| 1156 } | 1101 } |
| 1157 }); | 1102 }); |
| 1158 return startHelper(body, __completer); | 1103 return startHelper(body, __completer); |
| 1159 }"""); | 1104 }"""); |
| 1160 | 1105 |
| 1161 testAsyncTransform( | 1106 testAsyncTransform( |
| 1162 """ | 1107 """ |
| 1163 function(m) async { | 1108 function(m) async { |
| 1164 var exception = 1; | 1109 var exception = 1; |
| 1165 try { | 1110 try { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 // return | 1213 // return |
| 1269 return endOfIteration(); | 1214 return endOfIteration(); |
| 1270 case 2: | 1215 case 2: |
| 1271 // rethrow | 1216 // rethrow |
| 1272 return uncaughtError(__currentError); | 1217 return uncaughtError(__currentError); |
| 1273 } | 1218 } |
| 1274 }; | 1219 }; |
| 1275 }); | 1220 }); |
| 1276 }"""); | 1221 }"""); |
| 1277 } | 1222 } |
| OLD | NEW |