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

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

Issue 953283003: Refactor rewrite_async (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: One more Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | 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 8
9 import "backend_dart/dart_printer_test.dart" show PrintDiagnosticListener; 9 import "backend_dart/dart_printer_test.dart" show PrintDiagnosticListener;
10 10
11 void testTransform(String source, String expected) { 11 void testTransform(String source, String expected) {
12 Fun fun = js(source); 12 Fun fun = js(source);
13 Fun rewritten = new AsyncRewriter( 13 Fun rewritten = new AsyncRewriter(
14 null, // The diagnostic helper should not be used in these tests. 14 null, // The diagnostic helper should not be used in these tests.
15 null, 15 null,
16 asyncHelper: new VariableUse("thenHelper"), 16 asyncHelper: new VariableUse("thenHelper"),
17 newCompleter: new VariableUse("Completer"), 17 newCompleter: new VariableUse("Completer"),
18 endOfIteration: new VariableUse("endOfIteration"),
19 newIterable: new VariableUse("Iterator"),
20 safeVariableName: (String name) => "__$name").rewrite(fun); 18 safeVariableName: (String name) => "__$name").rewrite(fun);
21 19
22 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); 20 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions();
23 SimpleJavaScriptPrintingContext context = 21 SimpleJavaScriptPrintingContext context =
24 new SimpleJavaScriptPrintingContext(); 22 new SimpleJavaScriptPrintingContext();
25 Printer printer = new Printer(options, context); 23 Printer printer = new Printer(options, context);
26 printer.visit(rewritten); 24 printer.visit(rewritten);
27 Expect.stringEquals(expected, context.getText()); 25 Expect.stringEquals(expected, context.getText());
28 } 26 }
29 27
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 continue; // Continue from finally with pending finally. 75 continue; // Continue from finally with pending finally.
78 return 2; // Return from finally with pending finally. 76 return 2; // Return from finally with pending finally.
79 } 77 }
80 } 78 }
81 } finally { 79 } finally {
82 return 3; // Return from finally with no pending finally. 80 return 3; // Return from finally with no pending finally.
83 } 81 }
84 return 4; 82 return 4;
85 }""", """ 83 }""", """
86 function(b) { 84 function(b) {
87 var __goto = 0, __completer = new Completer(), __handler = 2, __currentError, __next, __returnValue, __helper; 85 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _ _currentError, __next, __helper;
88 function __body(__errorCode, __result) { 86 function __body(__errorCode, __result) {
89 if (__errorCode === 1) { 87 if (__errorCode === 1) {
90 __currentError = __result; 88 __currentError = __result;
91 __goto = __handler; 89 __goto = __handler;
92 } 90 }
93 while (true) 91 while (true)
94 __outer1: 92 __outer1:
95 switch (__goto) { 93 switch (__goto) {
96 case 0: 94 case 0:
97 // Function start 95 // Function start
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 break; 533 break;
536 if (!foo(i)) { // If with no else and await in body. 534 if (!foo(i)) { // If with no else and await in body.
537 await foo(); 535 await foo();
538 return; 536 return;
539 } 537 }
540 print(await(foo(i))); 538 print(await(foo(i)));
541 } 539 }
542 } 540 }
543 """, """ 541 """, """
544 function(g) { 542 function(g) {
545 var __goto = 0, __completer = new Completer(), __handler = 2, __currentError, __returnValue, i, __temp1; 543 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _ _currentError, i, __temp1;
546 function __body(__errorCode, __result) { 544 function __body(__errorCode, __result) {
547 if (__errorCode === 1) { 545 if (__errorCode === 1) {
548 __currentError = __result; 546 __currentError = __result;
549 __goto = __handler; 547 __goto = __handler;
550 } 548 }
551 while (true) 549 while (true)
552 switch (__goto) { 550 switch (__goto) {
553 case 0: 551 case 0:
554 // Function start 552 // Function start
555 i = 0; 553 i = 0;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 x = c ? await fooError(error) : fooError(error); 699 x = c ? await fooError(error) : fooError(error);
702 } catch (error) { // nested error handler with overlapping name 700 } catch (error) { // nested error handler with overlapping name
703 y.x = foo(error); 701 y.x = foo(error);
704 } finally { 702 } finally {
705 foo(x); 703 foo(x);
706 } 704 }
707 } 705 }
708 } 706 }
709 """, """ 707 """, """
710 function(c, i) { 708 function(c, i) {
711 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, __next, x, y, __error1, __error2; 709 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, __next, x, y, __error, __error1;
712 function __body(__errorCode, __result) { 710 function __body(__errorCode, __result) {
713 if (__errorCode === 1) { 711 if (__errorCode === 1) {
714 __currentError = __result; 712 __currentError = __result;
715 __goto = __handler; 713 __goto = __handler;
716 } 714 }
717 while (true) 715 while (true)
718 switch (__goto) { 716 switch (__goto) {
719 case 0: 717 case 0:
720 // Function start 718 // Function start
721 __handler = 3; 719 __handler = 3;
(...skipping 15 matching lines...) Expand all
737 // join 735 // join
738 x = __result; 736 x = __result;
739 y = {}; 737 y = {};
740 __handler = 1; 738 __handler = 1;
741 // goto after finally 739 // goto after finally
742 __goto = 5; 740 __goto = 5;
743 break; 741 break;
744 case 3: 742 case 3:
745 // catch 743 // catch
746 __handler = 2; 744 __handler = 2;
747 __error1 = __currentError; 745 __error = __currentError;
748 __handler = 11; 746 __handler = 11;
749 __goto = c ? 14 : 16; 747 __goto = c ? 14 : 16;
750 break; 748 break;
751 case 14: 749 case 14:
752 // then 750 // then
753 __goto = 17; 751 __goto = 17;
754 return thenHelper(fooError(__error1), __body, __completer); 752 return thenHelper(fooError(__error), __body, __completer);
755 case 17: 753 case 17:
756 // returning from await. 754 // returning from await.
757 // goto join 755 // goto join
758 __goto = 15; 756 __goto = 15;
759 break; 757 break;
760 case 16: 758 case 16:
761 // else 759 // else
762 __result = fooError(__error1); 760 __result = fooError(__error);
763 case 15: 761 case 15:
764 // join 762 // join
765 x = __result; 763 x = __result;
766 __next = [13]; 764 __next = [13];
767 // goto finally 765 // goto finally
768 __goto = 12; 766 __goto = 12;
769 break; 767 break;
770 case 11: 768 case 11:
771 // catch 769 // catch
772 __handler = 10; 770 __handler = 10;
773 __error2 = __currentError; 771 __error1 = __currentError;
774 y.x = foo(__error2); 772 y.x = foo(__error1);
775 __next = [13]; 773 __next = [13];
776 // goto finally 774 // goto finally
777 __goto = 12; 775 __goto = 12;
778 break; 776 break;
779 case 10: 777 case 10:
780 // uncaught 778 // uncaught
781 __next = [2]; 779 __next = [2];
782 case 12: 780 case 12:
783 // finally 781 // finally
784 __handler = 2; 782 __handler = 2;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 continue; 892 continue;
895 } 893 }
896 default: // defaul case 894 default: // defaul case
897 break lab; // break to label 895 break lab; // break to label
898 } 896 }
899 foo(); 897 foo();
900 } 898 }
901 } 899 }
902 }""", """ 900 }""", """
903 function(x, y, k) { 901 function(x, y, k) {
904 var __goto = 0, __completer = new Completer(), __handler = 2, __currentError, __returnValue, __temp1; 902 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _ _currentError, __temp1;
905 function __body(__errorCode, __result) { 903 function __body(__errorCode, __result) {
906 if (__errorCode === 1) { 904 if (__errorCode === 1) {
907 __currentError = __result; 905 __currentError = __result;
908 __goto = __handler; 906 __goto = __handler;
909 } 907 }
910 while (true) 908 while (true)
911 switch (__goto) { 909 switch (__goto) {
912 case 0: 910 case 0:
913 // Function start 911 // Function start
914 case 3: 912 case 3:
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 // return 1007 // return
1010 return thenHelper(__returnValue, 0, __completer, null); 1008 return thenHelper(__returnValue, 0, __completer, null);
1011 case 2: 1009 case 2:
1012 // rethrow 1010 // rethrow
1013 return thenHelper(__currentError, 1, __completer); 1011 return thenHelper(__currentError, 1, __completer);
1014 } 1012 }
1015 } 1013 }
1016 return thenHelper(null, __body, __completer, null); 1014 return thenHelper(null, __body, __completer, null);
1017 }"""); 1015 }""");
1018 } 1016 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698