Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: tests/compiler/dart2js/async_await_js_transform_test.dart

Issue 2335583003: Update tests. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 case 2: 70 case 2:
71 // returning from await. 71 // returning from await.
72 v0 = __result; 72 v0 = __result;
73 v1 = 0; 73 v1 = 0;
74 if (v1 < 0 || v1 >= v0.length) 74 if (v1 < 0 || v1 >= v0.length)
75 H.ioore(v0, v1); 75 H.ioore(v0, v1);
76 v2 = 4; 76 v2 = 4;
77 v3 = 2; 77 v3 = 2;
78 P.print(v0[v1].call$2(v2, v3)); 78 P.print(v0[v1].call$2(v2, v3));
79 // implicit return 79 // implicit return
80 return thenHelper(null, 0, __completer, null); 80 return thenHelper(null, 0, __completer);
81 case 1: 81 case 1:
82 // rethrow 82 // rethrow
83 return thenHelper(__currentError, 1, __completer); 83 return thenHelper(__currentError, 1, __completer);
84 } 84 }
85 }); 85 });
86 return thenHelper(null, body, __completer, null); 86 return thenHelper(null, body, __completer);
87 }""" 87 }"""
88 ) /// 01: ok 88 ) /// 01: ok
89 ; 89 ;
90 90
91 testAsyncTransform(""" 91 testAsyncTransform("""
92 function(a) async { 92 function(a) async {
93 print(this.x); // Ensure `this` is translated in the helper function. 93 print(this.x); // Ensure `this` is translated in the helper function.
94 await foo(); 94 await foo();
95 }""", """ 95 }""", """
96 function(a) { 96 function(a) {
97 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, __self = this; 97 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, __self = this;
98 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { 98 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) {
99 if (__errorCode === 1) { 99 if (__errorCode === 1) {
100 __currentError = __result; 100 __currentError = __result;
101 __goto = __handler; 101 __goto = __handler;
102 } 102 }
103 while (true) 103 while (true)
104 switch (__goto) { 104 switch (__goto) {
105 case 0: 105 case 0:
106 // Function start 106 // Function start
107 print(__self.x); 107 print(__self.x);
108 __goto = 2; 108 __goto = 2;
109 return thenHelper(foo(), body, __completer); 109 return thenHelper(foo(), body, __completer);
110 case 2: 110 case 2:
111 // returning from await. 111 // returning from await.
112 // implicit return 112 // implicit return
113 return thenHelper(null, 0, __completer, null); 113 return thenHelper(null, 0, __completer);
114 case 1: 114 case 1:
115 // rethrow 115 // rethrow
116 return thenHelper(__currentError, 1, __completer); 116 return thenHelper(__currentError, 1, __completer);
117 } 117 }
118 }); 118 });
119 return thenHelper(null, body, __completer, null); 119 return thenHelper(null, body, __completer);
120 }"""); 120 }""");
121 121
122 testAsyncTransform(""" 122 testAsyncTransform("""
123 function(b) async { 123 function(b) async {
124 try { 124 try {
125 __outer: while (true) { // Overlapping label name. 125 __outer: while (true) { // Overlapping label name.
126 try { 126 try {
127 inner: while (true) { 127 inner: while (true) {
128 break __outer; // Break from untranslated loop to translated target. 128 break __outer; // Break from untranslated loop to translated target.
129 break; // break to untranslated target. 129 break; // break to untranslated target.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 __goto = __next.pop(); 227 __goto = __next.pop();
228 break; 228 break;
229 case 5: 229 case 5:
230 // after finally 230 // after finally
231 __returnValue = 4; 231 __returnValue = 4;
232 // goto return 232 // goto return
233 __goto = 1; 233 __goto = 1;
234 break; 234 break;
235 case 1: 235 case 1:
236 // return 236 // return
237 return thenHelper(__returnValue, 0, __completer, null); 237 return thenHelper(__returnValue, 0, __completer);
238 case 2: 238 case 2:
239 // rethrow 239 // rethrow
240 return thenHelper(__currentError, 1, __completer); 240 return thenHelper(__currentError, 1, __completer);
241 } 241 }
242 }); 242 });
243 return thenHelper(null, body, __completer, null); 243 return thenHelper(null, body, __completer);
244 }"""); 244 }""");
245 245
246 testAsyncTransform(""" 246 testAsyncTransform("""
247 function(c) async { 247 function(c) async {
248 var a, b, c, d, e, f; 248 var a, b, c, d, e, f;
249 a = b++; // post- and preincrements. 249 a = b++; // post- and preincrements.
250 b = --b; 250 b = --b;
251 c = (await foo()).a++; 251 c = (await foo()).a++;
252 d = ++(await foo()).a; 252 d = ++(await foo()).a;
253 e = foo1()[await foo2()]--; 253 e = foo1()[await foo2()]--;
(...skipping 28 matching lines...) Expand all
282 case 4: 282 case 4:
283 // returning from await. 283 // returning from await.
284 e = __temp1[__result]--; 284 e = __temp1[__result]--;
285 __temp1 = foo1(); 285 __temp1 = foo1();
286 __goto = 5; 286 __goto = 5;
287 return thenHelper(foo2(), body, __completer); 287 return thenHelper(foo2(), body, __completer);
288 case 5: 288 case 5:
289 // returning from await. 289 // returning from await.
290 f = --__temp1[__result]; 290 f = --__temp1[__result];
291 // implicit return 291 // implicit return
292 return thenHelper(null, 0, __completer, null); 292 return thenHelper(null, 0, __completer);
293 case 1: 293 case 1:
294 // rethrow 294 // rethrow
295 return thenHelper(__currentError, 1, __completer); 295 return thenHelper(__currentError, 1, __completer);
296 } 296 }
297 }); 297 });
298 return thenHelper(null, body, __completer, null); 298 return thenHelper(null, body, __completer);
299 }"""); 299 }""");
300 300
301 testAsyncTransform(""" 301 testAsyncTransform("""
302 function(d2) async { 302 function(d2) async {
303 var a, b, c, d, e, f, g, h; // empty initializer 303 var a, b, c, d, e, f, g, h; // empty initializer
304 a = foo1() || await foo2(); // short circuiting operators 304 a = foo1() || await foo2(); // short circuiting operators
305 b = await foo1() || foo2(); 305 b = await foo1() || foo2();
306 c = await foo1() || foo3(await foo2()); 306 c = await foo1() || foo3(await foo2());
307 d = foo1() || foo2(); 307 d = foo1() || foo2();
308 e = foo1() && await foo2(); 308 e = foo1() && await foo2();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // then 415 // then
416 __goto = 17; 416 __goto = 17;
417 return thenHelper(foo2(), body, __completer); 417 return thenHelper(foo2(), body, __completer);
418 case 17: 418 case 17:
419 // returning from await. 419 // returning from await.
420 case 15: 420 case 15:
421 // join 421 // join
422 g = __result; 422 g = __result;
423 h = foo1() && foo2(); 423 h = foo1() && foo2();
424 // implicit return 424 // implicit return
425 return thenHelper(null, 0, __completer, null); 425 return thenHelper(null, 0, __completer);
426 case 1: 426 case 1:
427 // rethrow 427 // rethrow
428 return thenHelper(__currentError, 1, __completer); 428 return thenHelper(__currentError, 1, __completer);
429 } 429 }
430 }); 430 });
431 return thenHelper(null, body, __completer, null); 431 return thenHelper(null, body, __completer);
432 }"""); 432 }""");
433 433
434 testAsyncTransform(""" 434 testAsyncTransform("""
435 function(x, y) async { 435 function(x, y) async {
436 while (true) { 436 while (true) {
437 switch(y) { // Switch with no awaits in case key expressions 437 switch(y) { // Switch with no awaits in case key expressions
438 case 0: 438 case 0:
439 case 1: 439 case 1:
440 await foo(); 440 await foo();
441 continue; // Continue the loop, not the switch 441 continue; // Continue the loop, not the switch
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 // case 509 // case
510 foo(); 510 foo();
511 case 5: 511 case 5:
512 // after switch 512 // after switch
513 // goto while condition 513 // goto while condition
514 __goto = 2; 514 __goto = 2;
515 break; 515 break;
516 case 3: 516 case 3:
517 // after while 517 // after while
518 // implicit return 518 // implicit return
519 return thenHelper(null, 0, __completer, null); 519 return thenHelper(null, 0, __completer);
520 case 1: 520 case 1:
521 // rethrow 521 // rethrow
522 return thenHelper(__currentError, 1, __completer); 522 return thenHelper(__currentError, 1, __completer);
523 } 523 }
524 }); 524 });
525 return thenHelper(null, body, __completer, null); 525 return thenHelper(null, body, __completer);
526 }"""); 526 }""");
527 527
528 testAsyncTransform(""" 528 testAsyncTransform("""
529 function(f) async { 529 function(f) async {
530 do { 530 do {
531 var a = await foo(); 531 var a = await foo();
532 if (a) // If with no awaits in body 532 if (a) // If with no awaits in body
533 break; 533 break;
534 else 534 else
535 continue; 535 continue;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 case 6: 570 case 6:
571 // returning from await. 571 // returning from await.
572 if (__result) { 572 if (__result) {
573 // goto do body 573 // goto do body
574 __goto = 2; 574 __goto = 2;
575 break; 575 break;
576 } 576 }
577 case 4: 577 case 4:
578 // after do 578 // after do
579 // implicit return 579 // implicit return
580 return thenHelper(null, 0, __completer, null); 580 return thenHelper(null, 0, __completer);
581 case 1: 581 case 1:
582 // rethrow 582 // rethrow
583 return thenHelper(__currentError, 1, __completer); 583 return thenHelper(__currentError, 1, __completer);
584 } 584 }
585 }); 585 });
586 return thenHelper(null, body, __completer, null); 586 return thenHelper(null, body, __completer);
587 }"""); 587 }""");
588 588
589 testAsyncTransform(""" 589 testAsyncTransform("""
590 function(g) async { 590 function(g) async {
591 for (var i = 0; i < await foo1(); i += await foo2()) { 591 for (var i = 0; i < await foo1(); i += await foo2()) {
592 if (foo(i)) 592 if (foo(i))
593 continue; 593 continue;
594 else 594 else
595 break; 595 break;
596 if (!foo(i)) { // If with no else and await in body. 596 if (!foo(i)) { // If with no else and await in body.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 case 11: 660 case 11:
661 // returning from await. 661 // returning from await.
662 i += __result; 662 i += __result;
663 // goto for condition 663 // goto for condition
664 __goto = 3; 664 __goto = 3;
665 break; 665 break;
666 case 5: 666 case 5:
667 // after for 667 // after for
668 case 1: 668 case 1:
669 // return 669 // return
670 return thenHelper(__returnValue, 0, __completer, null); 670 return thenHelper(__returnValue, 0, __completer);
671 case 2: 671 case 2:
672 // rethrow 672 // rethrow
673 return thenHelper(__currentError, 1, __completer); 673 return thenHelper(__currentError, 1, __completer);
674 } 674 }
675 }); 675 });
676 return thenHelper(null, body, __completer, null); 676 return thenHelper(null, body, __completer);
677 }"""); 677 }""");
678 678
679 testAsyncTransform(""" 679 testAsyncTransform("""
680 function(a, h) async { 680 function(a, h) async {
681 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; 681 var x = {"a": foo1(), "b": await foo2(), "c": foo3()};
682 x["a"] = 2; // Different assignments 682 x["a"] = 2; // Different assignments
683 (await foo()).a = 3; 683 (await foo()).a = 3;
684 x[await foo()] = 4; 684 x[await foo()] = 4;
685 x[(await foo1()).a = await foo2()] = 5; 685 x[(await foo1()).a = await foo2()] = 5;
686 (await foo1())[await foo2()] = await foo3(6); 686 (await foo1())[await foo2()] = await foo3(6);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 return thenHelper(foo2(), body, __completer); 735 return thenHelper(foo2(), body, __completer);
736 case 8: 736 case 8:
737 // returning from await. 737 // returning from await.
738 __temp2 = __result; 738 __temp2 = __result;
739 __goto = 9; 739 __goto = 9;
740 return thenHelper(foo3(6), body, __completer); 740 return thenHelper(foo3(6), body, __completer);
741 case 9: 741 case 9:
742 // returning from await. 742 // returning from await.
743 __temp1[__temp2] = __result; 743 __temp1[__temp2] = __result;
744 // implicit return 744 // implicit return
745 return thenHelper(null, 0, __completer, null); 745 return thenHelper(null, 0, __completer);
746 case 1: 746 case 1:
747 // rethrow 747 // rethrow
748 return thenHelper(__currentError, 1, __completer); 748 return thenHelper(__currentError, 1, __completer);
749 } 749 }
750 }); 750 });
751 return thenHelper(null, body, __completer, null); 751 return thenHelper(null, body, __completer);
752 }"""); 752 }""");
753 753
754 testAsyncTransform(""" 754 testAsyncTransform("""
755 function(c, i) async { 755 function(c, i) async {
756 try { 756 try {
757 var x = c ? await foo() : foo(); // conditional 757 var x = c ? await foo() : foo(); // conditional
758 var y = {}; 758 var y = {};
759 } catch (error) { 759 } catch (error) {
760 try { 760 try {
761 x = c ? await fooError(error) : fooError(error); 761 x = c ? await fooError(error) : fooError(error);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 __goto = 5; 852 __goto = 5;
853 break; 853 break;
854 case 2: 854 case 2:
855 // uncaught 855 // uncaught
856 // goto rethrow 856 // goto rethrow
857 __goto = 1; 857 __goto = 1;
858 break; 858 break;
859 case 5: 859 case 5:
860 // after finally 860 // after finally
861 // implicit return 861 // implicit return
862 return thenHelper(null, 0, __completer, null); 862 return thenHelper(null, 0, __completer);
863 case 1: 863 case 1:
864 // rethrow 864 // rethrow
865 return thenHelper(__currentError, 1, __completer); 865 return thenHelper(__currentError, 1, __completer);
866 } 866 }
867 }); 867 });
868 return thenHelper(null, body, __completer, null); 868 return thenHelper(null, body, __completer);
869 }"""); 869 }""");
870 870
871 testAsyncTransform(""" 871 testAsyncTransform("""
872 function(x, y, j) async { 872 function(x, y, j) async {
873 print(await(foo(x))); // calls 873 print(await(foo(x))); // calls
874 (await print)(foo(x)); 874 (await print)(foo(x));
875 print(foo(await x)); 875 print(foo(await x));
876 await (print(foo(await x))); 876 await (print(foo(await x)));
877 print(foo(x, await y, z)); 877 print(foo(x, await y, z));
878 } 878 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 // returning from await. 918 // returning from await.
919 __temp1 = print; 919 __temp1 = print;
920 __temp2 = foo; 920 __temp2 = foo;
921 __temp3 = x; 921 __temp3 = x;
922 __goto = 7; 922 __goto = 7;
923 return thenHelper(y, body, __completer); 923 return thenHelper(y, body, __completer);
924 case 7: 924 case 7:
925 // returning from await. 925 // returning from await.
926 __temp1(__temp2(__temp3, __result, z)); 926 __temp1(__temp2(__temp3, __result, z));
927 // implicit return 927 // implicit return
928 return thenHelper(null, 0, __completer, null); 928 return thenHelper(null, 0, __completer);
929 case 1: 929 case 1:
930 // rethrow 930 // rethrow
931 return thenHelper(__currentError, 1, __completer); 931 return thenHelper(__currentError, 1, __completer);
932 } 932 }
933 }); 933 });
934 return thenHelper(null, body, __completer, null); 934 return thenHelper(null, body, __completer);
935 }"""); 935 }""");
936 936
937 testAsyncTransform(""" 937 testAsyncTransform("""
938 function(x, y, k) async { 938 function(x, y, k) async {
939 while (await(foo())) { 939 while (await(foo())) {
940 lab: { // labelled statement 940 lab: { // labelled statement
941 switch(y) { 941 switch(y) {
942 case 0: 942 case 0:
943 foo(); 943 foo();
944 case 0: // Duplicate case 944 case 0: // Duplicate case
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 foo(); 1058 foo();
1059 case 6: 1059 case 6:
1060 // break lab 1060 // break lab
1061 // goto while condition 1061 // goto while condition
1062 __goto = 3; 1062 __goto = 3;
1063 break; 1063 break;
1064 case 4: 1064 case 4:
1065 // after while 1065 // after while
1066 case 1: 1066 case 1:
1067 // return 1067 // return
1068 return thenHelper(__returnValue, 0, __completer, null); 1068 return thenHelper(__returnValue, 0, __completer);
1069 case 2: 1069 case 2:
1070 // rethrow 1070 // rethrow
1071 return thenHelper(__currentError, 1, __completer); 1071 return thenHelper(__currentError, 1, __completer);
1072 } 1072 }
1073 }); 1073 });
1074 return thenHelper(null, body, __completer, null); 1074 return thenHelper(null, body, __completer);
1075 }"""); 1075 }""");
1076 1076
1077 testAsyncTransform(""" 1077 testAsyncTransform("""
1078 function(l) async { 1078 function(l) async {
1079 switch(await l) { 1079 switch(await l) {
1080 case 1: 1080 case 1:
1081 print(1); 1081 print(1);
1082 break; 1082 break;
1083 case 2: 1083 case 2:
1084 print(1); 1084 print(1);
(...skipping 22 matching lines...) Expand all
1107 case 1: 1107 case 1:
1108 print(1); 1108 print(1);
1109 break; 1109 break;
1110 case 2: 1110 case 2:
1111 print(1); 1111 print(1);
1112 default: 1112 default:
1113 print(2); 1113 print(2);
1114 break; 1114 break;
1115 } 1115 }
1116 // implicit return 1116 // implicit return
1117 return thenHelper(null, 0, __completer, null); 1117 return thenHelper(null, 0, __completer);
1118 case 1: 1118 case 1:
1119 // rethrow 1119 // rethrow
1120 return thenHelper(__currentError, 1, __completer); 1120 return thenHelper(__currentError, 1, __completer);
1121 } 1121 }
1122 }); 1122 });
1123 return thenHelper(null, body, __completer, null); 1123 return thenHelper(null, body, __completer);
1124 }"""); 1124 }""");
1125 1125
1126 testAsyncTransform(""" 1126 testAsyncTransform("""
1127 function(m) async { 1127 function(m) async {
1128 var exception = 1; 1128 var exception = 1;
1129 try { 1129 try {
1130 await 42; 1130 await 42;
1131 throw 42; 1131 throw 42;
1132 } catch (exception) { 1132 } catch (exception) {
1133 exception = await 10; 1133 exception = await 10;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 break; 1186 break;
1187 case 2: 1187 case 2:
1188 // uncaught 1188 // uncaught
1189 // goto rethrow 1189 // goto rethrow
1190 __goto = 1; 1190 __goto = 1;
1191 break; 1191 break;
1192 case 5: 1192 case 5:
1193 // after finally 1193 // after finally
1194 print(exception); 1194 print(exception);
1195 // implicit return 1195 // implicit return
1196 return thenHelper(null, 0, __completer, null); 1196 return thenHelper(null, 0, __completer);
1197 case 1: 1197 case 1:
1198 // rethrow 1198 // rethrow
1199 return thenHelper(__currentError, 1, __completer); 1199 return thenHelper(__currentError, 1, __completer);
1200 } 1200 }
1201 }); 1201 });
1202 return thenHelper(null, body, __completer, null); 1202 return thenHelper(null, body, __completer);
1203 }"""); 1203 }""");
1204 1204
1205 testSyncStarTransform(""" 1205 testSyncStarTransform("""
1206 function(a) sync* { 1206 function(a) sync* {
1207 // Ensure that return of a value is treated as first evaluating the value, and 1207 // Ensure that return of a value is treated as first evaluating the value, and
1208 // then returning. 1208 // then returning.
1209 return foo(); 1209 return foo();
1210 }""", """ 1210 }""", """
1211 function(__a) { 1211 function(__a) {
1212 return new newIterable(function() { 1212 return new newIterable(function() {
(...skipping 16 matching lines...) Expand all
1229 // return 1229 // return
1230 return endOfIteration(); 1230 return endOfIteration();
1231 case 2: 1231 case 2:
1232 // rethrow 1232 // rethrow
1233 return uncaughtError(__currentError); 1233 return uncaughtError(__currentError);
1234 } 1234 }
1235 }; 1235 };
1236 }); 1236 });
1237 }"""); 1237 }""");
1238 } 1238 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698