| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    87           // implicit return |    87           // implicit return | 
|    88           return returnHelper(null, __completer); |    88           return returnHelper(null, __completer); | 
|    89       } |    89       } | 
|    90   }); |    90   }); | 
|    91   return startHelper(body, __completer); |    91   return startHelper(body, __completer); | 
|    92 }""") |    92 }""") | 
|    93  |    93  | 
|    94       /// 01: ok |    94       /// 01: ok | 
|    95       ; |    95       ; | 
|    96  |    96  | 
|    97   testAsyncTransform( |    97   testAsyncTransform(""" | 
|    98       """ |  | 
|    99 function(a) async { |    98 function(a) async { | 
|   100   print(this.x); // Ensure `this` is translated in the helper function. |    99   print(this.x); // Ensure `this` is translated in the helper function. | 
|   101   await foo(); |   100   await foo(); | 
|   102 }""", |   101 }""", """ | 
|   103       """ |  | 
|   104 function(a) { |   102 function(a) { | 
|   105   var __goto = 0, __completer = NewCompleter(), __self = this; |   103   var __goto = 0, __completer = NewCompleter(), __self = this; | 
|   106   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   104   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   107     if (__errorCode === 1) |   105     if (__errorCode === 1) | 
|   108       return rethrowHelper(__result, __completer); |   106       return rethrowHelper(__result, __completer); | 
|   109     while (true) |   107     while (true) | 
|   110       switch (__goto) { |   108       switch (__goto) { | 
|   111         case 0: |   109         case 0: | 
|   112           // Function start |   110           // Function start | 
|   113           print(__self.x); |   111           print(__self.x); | 
|   114           __goto = 2; |   112           __goto = 2; | 
|   115           return awaitHelper(foo(), body); |   113           return awaitHelper(foo(), body); | 
|   116         case 2: |   114         case 2: | 
|   117           // returning from await. |   115           // returning from await. | 
|   118           // implicit return |   116           // implicit return | 
|   119           return returnHelper(null, __completer); |   117           return returnHelper(null, __completer); | 
|   120       } |   118       } | 
|   121   }); |   119   }); | 
|   122   return startHelper(body, __completer); |   120   return startHelper(body, __completer); | 
|   123 }"""); |   121 }"""); | 
|   124  |   122  | 
|   125   testAsyncTransform( |   123   testAsyncTransform(""" | 
|   126       """ |  | 
|   127   function(b) async { |   124   function(b) async { | 
|   128     try { |   125     try { | 
|   129       __outer: while (true) { // Overlapping label name. |   126       __outer: while (true) { // Overlapping label name. | 
|   130         try { |   127         try { | 
|   131           inner: while (true) { |   128           inner: while (true) { | 
|   132             break __outer; // Break from untranslated loop to translated target. |   129             break __outer; // Break from untranslated loop to translated target. | 
|   133             break; // break to untranslated target. |   130             break; // break to untranslated target. | 
|   134           } |   131           } | 
|   135           while (true) { |   132           while (true) { | 
|   136             return; // Return via finallies. |   133             return; // Return via finallies. | 
|   137           } |   134           } | 
|   138           var __helper = await foo(); // Overlapping variable name. |   135           var __helper = await foo(); // Overlapping variable name. | 
|   139         } finally { |   136         } finally { | 
|   140           foo(); |   137           foo(); | 
|   141           continue; // Continue from finally with pending finally. |   138           continue; // Continue from finally with pending finally. | 
|   142           return 2; // Return from finally with pending finally. |   139           return 2; // Return from finally with pending finally. | 
|   143         } |   140         } | 
|   144       } |   141       } | 
|   145     } finally { |   142     } finally { | 
|   146       return 3; // Return from finally with no pending finally. |   143       return 3; // Return from finally with no pending finally. | 
|   147     } |   144     } | 
|   148     return 4; |   145     return 4; | 
|   149   }""", |   146   }""", """ | 
|   150       """ |  | 
|   151 function(b) { |   147 function(b) { | 
|   152   var __goto = 0, __completer = NewCompleter(), __returnValue, __handler = 2, __
      currentError, __next = [], __helper; |   148   var __goto = 0, __completer = NewCompleter(), __returnValue, __handler = 2, __
      currentError, __next = [], __helper; | 
|   153   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   149   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   154     if (__errorCode === 1) { |   150     if (__errorCode === 1) { | 
|   155       __currentError = __result; |   151       __currentError = __result; | 
|   156       __goto = __handler; |   152       __goto = __handler; | 
|   157     } |   153     } | 
|   158     while (true) |   154     while (true) | 
|   159       __outer1: |   155       __outer1: | 
|   160         switch (__goto) { |   156         switch (__goto) { | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   241             // return |   237             // return | 
|   242             return returnHelper(__returnValue, __completer); |   238             return returnHelper(__returnValue, __completer); | 
|   243           case 2: |   239           case 2: | 
|   244             // rethrow |   240             // rethrow | 
|   245             return rethrowHelper(__currentError, __completer); |   241             return rethrowHelper(__currentError, __completer); | 
|   246         } |   242         } | 
|   247   }); |   243   }); | 
|   248   return startHelper(body, __completer); |   244   return startHelper(body, __completer); | 
|   249 }"""); |   245 }"""); | 
|   250  |   246  | 
|   251   testAsyncTransform( |   247   testAsyncTransform(""" | 
|   252       """ |  | 
|   253 function(c) async { |   248 function(c) async { | 
|   254   var a, b, c, d, e, f; |   249   var a, b, c, d, e, f; | 
|   255   a = b++; // post- and preincrements. |   250   a = b++; // post- and preincrements. | 
|   256   b = --b; |   251   b = --b; | 
|   257   c = (await foo()).a++; |   252   c = (await foo()).a++; | 
|   258   d = ++(await foo()).a; |   253   d = ++(await foo()).a; | 
|   259   e = foo1()[await foo2()]--; |   254   e = foo1()[await foo2()]--; | 
|   260   f = --foo1()[await foo2()]; |   255   f = --foo1()[await foo2()]; | 
|   261 }""", |   256 }""", """ | 
|   262       """ |  | 
|   263 function(c) { |   257 function(c) { | 
|   264   var __goto = 0, __completer = NewCompleter(), a, b, c, d, e, f, __temp1; |   258   var __goto = 0, __completer = NewCompleter(), a, b, c, d, e, f, __temp1; | 
|   265   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   259   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   266     if (__errorCode === 1) |   260     if (__errorCode === 1) | 
|   267       return rethrowHelper(__result, __completer); |   261       return rethrowHelper(__result, __completer); | 
|   268     while (true) |   262     while (true) | 
|   269       switch (__goto) { |   263       switch (__goto) { | 
|   270         case 0: |   264         case 0: | 
|   271           // Function start |   265           // Function start | 
|   272           a = b++; |   266           a = b++; | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|   293         case 5: |   287         case 5: | 
|   294           // returning from await. |   288           // returning from await. | 
|   295           f = --__temp1[__result]; |   289           f = --__temp1[__result]; | 
|   296           // implicit return |   290           // implicit return | 
|   297           return returnHelper(null, __completer); |   291           return returnHelper(null, __completer); | 
|   298       } |   292       } | 
|   299   }); |   293   }); | 
|   300   return startHelper(body, __completer); |   294   return startHelper(body, __completer); | 
|   301 }"""); |   295 }"""); | 
|   302  |   296  | 
|   303   testAsyncTransform( |   297   testAsyncTransform(""" | 
|   304       """ |  | 
|   305   function(d2) async { |   298   function(d2) async { | 
|   306     var a, b, c, d, e, f, g, h; // empty initializer |   299     var a, b, c, d, e, f, g, h; // empty initializer | 
|   307     a = foo1() || await foo2(); // short circuiting operators |   300     a = foo1() || await foo2(); // short circuiting operators | 
|   308     b = await foo1() || foo2(); |   301     b = await foo1() || foo2(); | 
|   309     c = await foo1() || foo3(await foo2()); |   302     c = await foo1() || foo3(await foo2()); | 
|   310     d = foo1() || foo2(); |   303     d = foo1() || foo2(); | 
|   311     e = foo1() && await foo2(); |   304     e = foo1() && await foo2(); | 
|   312     f = await foo1() && foo2(); |   305     f = await foo1() && foo2(); | 
|   313     g = await foo1() && await foo2(); |   306     g = await foo1() && await foo2(); | 
|   314     h = foo1() && foo2(); |   307     h = foo1() && foo2(); | 
|   315   }""", |   308   }""", """ | 
|   316       """ |  | 
|   317 function(d2) { |   309 function(d2) { | 
|   318   var __goto = 0, __completer = NewCompleter(), a, b, c, d, e, f, g, h, __temp1; |   310   var __goto = 0, __completer = NewCompleter(), a, b, c, d, e, f, g, h, __temp1; | 
|   319   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   311   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   320     if (__errorCode === 1) |   312     if (__errorCode === 1) | 
|   321       return rethrowHelper(__result, __completer); |   313       return rethrowHelper(__result, __completer); | 
|   322     while (true) |   314     while (true) | 
|   323       switch (__goto) { |   315       switch (__goto) { | 
|   324         case 0: |   316         case 0: | 
|   325           // Function start |   317           // Function start | 
|   326           __temp1 = foo1(); |   318           __temp1 = foo1(); | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   423           // join |   415           // join | 
|   424           g = __result; |   416           g = __result; | 
|   425           h = foo1() && foo2(); |   417           h = foo1() && foo2(); | 
|   426           // implicit return |   418           // implicit return | 
|   427           return returnHelper(null, __completer); |   419           return returnHelper(null, __completer); | 
|   428       } |   420       } | 
|   429   }); |   421   }); | 
|   430   return startHelper(body, __completer); |   422   return startHelper(body, __completer); | 
|   431 }"""); |   423 }"""); | 
|   432  |   424  | 
|   433   testAsyncTransform( |   425   testAsyncTransform(""" | 
|   434       """ |  | 
|   435 function(x, y) async { |   426 function(x, y) async { | 
|   436   while (true) { |   427   while (true) { | 
|   437     switch(y) { // Switch with no awaits in case key expressions |   428     switch(y) { // Switch with no awaits in case key expressions | 
|   438       case 0: |   429       case 0: | 
|   439       case 1:  |   430       case 1:  | 
|   440         await foo(); |   431         await foo(); | 
|   441         continue; // Continue the loop, not the switch |   432         continue; // Continue the loop, not the switch | 
|   442       case 1: // Duplicate case |   433       case 1: // Duplicate case | 
|   443         await foo(); |   434         await foo(); | 
|   444         break; // Break the switch |   435         break; // Break the switch | 
|   445       case 2: |   436       case 2: | 
|   446         foo(); // No default |   437         foo(); // No default | 
|   447     } |   438     } | 
|   448   } |   439   } | 
|   449 }""", |   440 }""", """ | 
|   450       """ |  | 
|   451 function(x, y) { |   441 function(x, y) { | 
|   452   var __goto = 0, __completer = NewCompleter(); |   442   var __goto = 0, __completer = NewCompleter(); | 
|   453   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   443   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   454     if (__errorCode === 1) |   444     if (__errorCode === 1) | 
|   455       return rethrowHelper(__result, __completer); |   445       return rethrowHelper(__result, __completer); | 
|   456     while (true) |   446     while (true) | 
|   457       switch (__goto) { |   447       switch (__goto) { | 
|   458         case 0: |   448         case 0: | 
|   459           // Function start |   449           // Function start | 
|   460         case 2: |   450         case 2: | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   514           break; |   504           break; | 
|   515         case 3: |   505         case 3: | 
|   516           // after while |   506           // after while | 
|   517           // implicit return |   507           // implicit return | 
|   518           return returnHelper(null, __completer); |   508           return returnHelper(null, __completer); | 
|   519       } |   509       } | 
|   520   }); |   510   }); | 
|   521   return startHelper(body, __completer); |   511   return startHelper(body, __completer); | 
|   522 }"""); |   512 }"""); | 
|   523  |   513  | 
|   524   testAsyncTransform( |   514   testAsyncTransform(""" | 
|   525       """ |  | 
|   526   function(f) async { |   515   function(f) async { | 
|   527     do { |   516     do { | 
|   528       var a = await foo(); |   517       var a = await foo(); | 
|   529       if (a) // If with no awaits in body |   518       if (a) // If with no awaits in body | 
|   530         break; |   519         break; | 
|   531       else |   520       else | 
|   532         continue; |   521         continue; | 
|   533     } while (await foo()); |   522     } while (await foo()); | 
|   534   } |   523   } | 
|   535   """, |   524   """, """ | 
|   536       """ |  | 
|   537 function(f) { |   525 function(f) { | 
|   538   var __goto = 0, __completer = NewCompleter(), a; |   526   var __goto = 0, __completer = NewCompleter(), a; | 
|   539   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   527   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   540     if (__errorCode === 1) |   528     if (__errorCode === 1) | 
|   541       return rethrowHelper(__result, __completer); |   529       return rethrowHelper(__result, __completer); | 
|   542     while (true) |   530     while (true) | 
|   543       switch (__goto) { |   531       switch (__goto) { | 
|   544         case 0: |   532         case 0: | 
|   545           // Function start |   533           // Function start | 
|   546         case 2: |   534         case 2: | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|   572           } |   560           } | 
|   573         case 4: |   561         case 4: | 
|   574           // after do |   562           // after do | 
|   575           // implicit return |   563           // implicit return | 
|   576           return returnHelper(null, __completer); |   564           return returnHelper(null, __completer); | 
|   577       } |   565       } | 
|   578   }); |   566   }); | 
|   579   return startHelper(body, __completer); |   567   return startHelper(body, __completer); | 
|   580 }"""); |   568 }"""); | 
|   581  |   569  | 
|   582   testAsyncTransform( |   570   testAsyncTransform(""" | 
|   583       """ |  | 
|   584 function(g) async { |   571 function(g) async { | 
|   585   for (var i = 0; i < await foo1(); i += await foo2()) { |   572   for (var i = 0; i < await foo1(); i += await foo2()) { | 
|   586     if (foo(i)) |   573     if (foo(i)) | 
|   587       continue; |   574       continue; | 
|   588     else |   575     else | 
|   589       break; |   576       break; | 
|   590     if (!foo(i)) { // If with no else and await in body. |   577     if (!foo(i)) { // If with no else and await in body. | 
|   591       await foo(); |   578       await foo(); | 
|   592       return; |   579       return; | 
|   593     } |   580     } | 
|   594     print(await(foo(i))); |   581     print(await(foo(i))); | 
|   595   }  |   582   }  | 
|   596 } |   583 } | 
|   597 """, |   584 """, """ | 
|   598       """ |  | 
|   599 function(g) { |   585 function(g) { | 
|   600   var __goto = 0, __completer = NewCompleter(), __returnValue, i, __temp1; |   586   var __goto = 0, __completer = NewCompleter(), __returnValue, i, __temp1; | 
|   601   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   587   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   602     if (__errorCode === 1) |   588     if (__errorCode === 1) | 
|   603       return rethrowHelper(__result, __completer); |   589       return rethrowHelper(__result, __completer); | 
|   604     while (true) |   590     while (true) | 
|   605       switch (__goto) { |   591       switch (__goto) { | 
|   606         case 0: |   592         case 0: | 
|   607           // Function start |   593           // Function start | 
|   608           i = 0; |   594           i = 0; | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   659         case 5: |   645         case 5: | 
|   660           // after for |   646           // after for | 
|   661         case 1: |   647         case 1: | 
|   662           // return |   648           // return | 
|   663           return returnHelper(__returnValue, __completer); |   649           return returnHelper(__returnValue, __completer); | 
|   664       } |   650       } | 
|   665   }); |   651   }); | 
|   666   return startHelper(body, __completer); |   652   return startHelper(body, __completer); | 
|   667 }"""); |   653 }"""); | 
|   668  |   654  | 
|   669   testAsyncTransform( |   655   testAsyncTransform(""" | 
|   670       """ |  | 
|   671   function(a, h) async { |   656   function(a, h) async { | 
|   672     var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; |   657     var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; | 
|   673     x["a"] = 2; // Different assignments |   658     x["a"] = 2; // Different assignments | 
|   674     (await foo()).a = 3; |   659     (await foo()).a = 3; | 
|   675     x[await foo()] = 4; |   660     x[await foo()] = 4; | 
|   676     x[(await foo1()).a = await foo2()] = 5; |   661     x[(await foo1()).a = await foo2()] = 5; | 
|   677     (await foo1())[await foo2()] = await foo3(6); |   662     (await foo1())[await foo2()] = await foo3(6); | 
|   678   } |   663   } | 
|   679   """, |   664   """, """ | 
|   680       """ |  | 
|   681 function(a, h) { |   665 function(a, h) { | 
|   682   var __goto = 0, __completer = NewCompleter(), x, __temp1, __temp2; |   666   var __goto = 0, __completer = NewCompleter(), x, __temp1, __temp2; | 
|   683   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   667   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   684     if (__errorCode === 1) |   668     if (__errorCode === 1) | 
|   685       return rethrowHelper(__result, __completer); |   669       return rethrowHelper(__result, __completer); | 
|   686     while (true) |   670     while (true) | 
|   687       switch (__goto) { |   671       switch (__goto) { | 
|   688         case 0: |   672         case 0: | 
|   689           // Function start |   673           // Function start | 
|   690           __temp1 = foo1(); |   674           __temp1 = foo1(); | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   731         case 9: |   715         case 9: | 
|   732           // returning from await. |   716           // returning from await. | 
|   733           __temp1[__temp2] = __result; |   717           __temp1[__temp2] = __result; | 
|   734           // implicit return |   718           // implicit return | 
|   735           return returnHelper(null, __completer); |   719           return returnHelper(null, __completer); | 
|   736       } |   720       } | 
|   737   }); |   721   }); | 
|   738   return startHelper(body, __completer); |   722   return startHelper(body, __completer); | 
|   739 }"""); |   723 }"""); | 
|   740  |   724  | 
|   741   testAsyncTransform( |   725   testAsyncTransform(""" | 
|   742       """ |  | 
|   743 function(c, i) async { |   726 function(c, i) async { | 
|   744   try { |   727   try { | 
|   745     var x = c ? await foo() : foo(); // conditional |   728     var x = c ? await foo() : foo(); // conditional | 
|   746     var y = {}; |   729     var y = {}; | 
|   747   } catch (error) { |   730   } catch (error) { | 
|   748     try { |   731     try { | 
|   749       x = c ? await fooError(error) : fooError(error); |   732       x = c ? await fooError(error) : fooError(error); | 
|   750     } catch (error) { // nested error handler with overlapping name |   733     } catch (error) { // nested error handler with overlapping name | 
|   751       y.x = foo(error); |   734       y.x = foo(error); | 
|   752     } finally { |   735     } finally { | 
|   753       foo(x); |   736       foo(x); | 
|   754     } |   737     } | 
|   755   } |   738   } | 
|   756 } |   739 } | 
|   757 """, |   740 """, """ | 
|   758       """ |  | 
|   759 function(c, i) { |   741 function(c, i) { | 
|   760   var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
      _next = [], x, y, __error, __error1; |   742   var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
      _next = [], x, y, __error, __error1; | 
|   761   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   743   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   762     if (__errorCode === 1) { |   744     if (__errorCode === 1) { | 
|   763       __currentError = __result; |   745       __currentError = __result; | 
|   764       __goto = __handler; |   746       __goto = __handler; | 
|   765     } |   747     } | 
|   766     while (true) |   748     while (true) | 
|   767       switch (__goto) { |   749       switch (__goto) { | 
|   768         case 0: |   750         case 0: | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   850           // implicit return |   832           // implicit return | 
|   851           return returnHelper(null, __completer); |   833           return returnHelper(null, __completer); | 
|   852         case 1: |   834         case 1: | 
|   853           // rethrow |   835           // rethrow | 
|   854           return rethrowHelper(__currentError, __completer); |   836           return rethrowHelper(__currentError, __completer); | 
|   855       } |   837       } | 
|   856   }); |   838   }); | 
|   857   return startHelper(body, __completer); |   839   return startHelper(body, __completer); | 
|   858 }"""); |   840 }"""); | 
|   859  |   841  | 
|   860   testAsyncTransform( |   842   testAsyncTransform(""" | 
|   861       """ |  | 
|   862   function(x, y, j) async { |   843   function(x, y, j) async { | 
|   863     print(await(foo(x))); // calls |   844     print(await(foo(x))); // calls | 
|   864     (await print)(foo(x)); |   845     (await print)(foo(x)); | 
|   865     print(foo(await x)); |   846     print(foo(await x)); | 
|   866     await (print(foo(await x))); |   847     await (print(foo(await x))); | 
|   867     print(foo(x, await y, z)); |   848     print(foo(x, await y, z)); | 
|   868   } |   849   } | 
|   869   """, |   850   """, """ | 
|   870       """ |  | 
|   871 function(x, y, j) { |   851 function(x, y, j) { | 
|   872   var __goto = 0, __completer = NewCompleter(), __temp1, __temp2, __temp3; |   852   var __goto = 0, __completer = NewCompleter(), __temp1, __temp2, __temp3; | 
|   873   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   853   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   874     if (__errorCode === 1) |   854     if (__errorCode === 1) | 
|   875       return rethrowHelper(__result, __completer); |   855       return rethrowHelper(__result, __completer); | 
|   876     while (true) |   856     while (true) | 
|   877       switch (__goto) { |   857       switch (__goto) { | 
|   878         case 0: |   858         case 0: | 
|   879           // Function start |   859           // Function start | 
|   880           __temp1 = print; |   860           __temp1 = print; | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   913         case 7: |   893         case 7: | 
|   914           // returning from await. |   894           // returning from await. | 
|   915           __temp1(__temp2(__temp3, __result, z)); |   895           __temp1(__temp2(__temp3, __result, z)); | 
|   916           // implicit return |   896           // implicit return | 
|   917           return returnHelper(null, __completer); |   897           return returnHelper(null, __completer); | 
|   918       } |   898       } | 
|   919   }); |   899   }); | 
|   920   return startHelper(body, __completer); |   900   return startHelper(body, __completer); | 
|   921 }"""); |   901 }"""); | 
|   922  |   902  | 
|   923   testAsyncTransform( |   903   testAsyncTransform(""" | 
|   924       """ |  | 
|   925 function(x, y, k) async { |   904 function(x, y, k) async { | 
|   926   while (await(foo())) { |   905   while (await(foo())) { | 
|   927     lab: { // labelled statement |   906     lab: { // labelled statement | 
|   928       switch(y) { |   907       switch(y) { | 
|   929       case 0: |   908       case 0: | 
|   930         foo(); |   909         foo(); | 
|   931       case 0: // Duplicate case |   910       case 0: // Duplicate case | 
|   932         print(await foo1(x)); |   911         print(await foo1(x)); | 
|   933         return y; |   912         return y; | 
|   934       case await bar(): // await in case |   913       case await bar(): // await in case | 
|   935         print(await foobar(x)); |   914         print(await foobar(x)); | 
|   936         return y; |   915         return y; | 
|   937       case x: |   916       case x: | 
|   938         if (a) { |   917         if (a) { | 
|   939           throw new Error(); |   918           throw new Error(); | 
|   940         } else { |   919         } else { | 
|   941           continue; |   920           continue; | 
|   942         } |   921         } | 
|   943       default: // default case |   922       default: // default case | 
|   944         break lab; // break to label |   923         break lab; // break to label | 
|   945       } |   924       } | 
|   946       foo(); |   925       foo(); | 
|   947     } |   926     } | 
|   948   } |   927   } | 
|   949 }""", |   928 }""", """ | 
|   950       """ |  | 
|   951 function(x, y, k) { |   929 function(x, y, k) { | 
|   952   var __goto = 0, __completer = NewCompleter(), __returnValue, __temp1; |   930   var __goto = 0, __completer = NewCompleter(), __returnValue, __temp1; | 
|   953   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |   931   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|   954     if (__errorCode === 1) |   932     if (__errorCode === 1) | 
|   955       return rethrowHelper(__result, __completer); |   933       return rethrowHelper(__result, __completer); | 
|   956     while (true) |   934     while (true) | 
|   957       switch (__goto) { |   935       switch (__goto) { | 
|   958         case 0: |   936         case 0: | 
|   959           // Function start |   937           // Function start | 
|   960         case 3: |   938         case 3: | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1050         case 4: |  1028         case 4: | 
|  1051           // after while |  1029           // after while | 
|  1052         case 1: |  1030         case 1: | 
|  1053           // return |  1031           // return | 
|  1054           return returnHelper(__returnValue, __completer); |  1032           return returnHelper(__returnValue, __completer); | 
|  1055       } |  1033       } | 
|  1056   }); |  1034   }); | 
|  1057   return startHelper(body, __completer); |  1035   return startHelper(body, __completer); | 
|  1058 }"""); |  1036 }"""); | 
|  1059  |  1037  | 
|  1060   testAsyncTransform( |  1038   testAsyncTransform(""" | 
|  1061       """ |  | 
|  1062   function(l) async { |  1039   function(l) async { | 
|  1063     switch(await l) { |  1040     switch(await l) { | 
|  1064       case 1: |  1041       case 1: | 
|  1065         print(1); |  1042         print(1); | 
|  1066         break; |  1043         break; | 
|  1067       case 2: |  1044       case 2: | 
|  1068         print(1); |  1045         print(1); | 
|  1069         // Fallthrough |  1046         // Fallthrough | 
|  1070       default: |  1047       default: | 
|  1071         print(2); |  1048         print(2); | 
|  1072         break; |  1049         break; | 
|  1073     } |  1050     } | 
|  1074   }""", |  1051   }""", """ | 
|  1075       """ |  | 
|  1076 function(l) { |  1052 function(l) { | 
|  1077   var __goto = 0, __completer = NewCompleter(); |  1053   var __goto = 0, __completer = NewCompleter(); | 
|  1078   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |  1054   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|  1079     if (__errorCode === 1) |  1055     if (__errorCode === 1) | 
|  1080       return rethrowHelper(__result, __completer); |  1056       return rethrowHelper(__result, __completer); | 
|  1081     while (true) |  1057     while (true) | 
|  1082       switch (__goto) { |  1058       switch (__goto) { | 
|  1083         case 0: |  1059         case 0: | 
|  1084           // Function start |  1060           // Function start | 
|  1085           __goto = 2; |  1061           __goto = 2; | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  1096               print(2); |  1072               print(2); | 
|  1097               break; |  1073               break; | 
|  1098           } |  1074           } | 
|  1099           // implicit return |  1075           // implicit return | 
|  1100           return returnHelper(null, __completer); |  1076           return returnHelper(null, __completer); | 
|  1101       } |  1077       } | 
|  1102   }); |  1078   }); | 
|  1103   return startHelper(body, __completer); |  1079   return startHelper(body, __completer); | 
|  1104 }"""); |  1080 }"""); | 
|  1105  |  1081  | 
|  1106   testAsyncTransform( |  1082   testAsyncTransform(""" | 
|  1107       """ |  | 
|  1108   function(m) async { |  1083   function(m) async { | 
|  1109     var exception = 1; |  1084     var exception = 1; | 
|  1110     try { |  1085     try { | 
|  1111       await 42; |  1086       await 42; | 
|  1112       throw 42; |  1087       throw 42; | 
|  1113     } catch (exception) { |  1088     } catch (exception) { | 
|  1114       exception = await 10; |  1089       exception = await 10; | 
|  1115       exception += await 10; |  1090       exception += await 10; | 
|  1116       exception++; |  1091       exception++; | 
|  1117       exception--; |  1092       exception--; | 
|  1118       ++exception; |  1093       ++exception; | 
|  1119       --exception; |  1094       --exception; | 
|  1120       exception += 10; |  1095       exception += 10; | 
|  1121     } |  1096     } | 
|  1122     print(exception); |  1097     print(exception); | 
|  1123   }""", |  1098   }""", """ | 
|  1124       """ |  | 
|  1125 function(m) { |  1099 function(m) { | 
|  1126   var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
      _next = [], exception, __exception; |  1100   var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
      _next = [], exception, __exception; | 
|  1127   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |  1101   var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 
|  1128     if (__errorCode === 1) { |  1102     if (__errorCode === 1) { | 
|  1129       __currentError = __result; |  1103       __currentError = __result; | 
|  1130       __goto = __handler; |  1104       __goto = __handler; | 
|  1131     } |  1105     } | 
|  1132     while (true) |  1106     while (true) | 
|  1133       switch (__goto) { |  1107       switch (__goto) { | 
|  1134         case 0: |  1108         case 0: | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1177           // implicit return |  1151           // implicit return | 
|  1178           return returnHelper(null, __completer); |  1152           return returnHelper(null, __completer); | 
|  1179         case 1: |  1153         case 1: | 
|  1180           // rethrow |  1154           // rethrow | 
|  1181           return rethrowHelper(__currentError, __completer); |  1155           return rethrowHelper(__currentError, __completer); | 
|  1182       } |  1156       } | 
|  1183   }); |  1157   }); | 
|  1184   return startHelper(body, __completer); |  1158   return startHelper(body, __completer); | 
|  1185 }"""); |  1159 }"""); | 
|  1186  |  1160  | 
|  1187   testSyncStarTransform( |  1161   testSyncStarTransform(""" | 
|  1188       """ |  | 
|  1189 function(a) sync* { |  1162 function(a) sync* { | 
|  1190   // Ensure that return of a value is treated as first evaluating the value, and |  1163   // Ensure that return of a value is treated as first evaluating the value, and | 
|  1191   // then returning. |  1164   // then returning. | 
|  1192   return foo(); |  1165   return foo(); | 
|  1193 }""", |  1166 }""", """ | 
|  1194       """ |  | 
|  1195 function(__a) { |  1167 function(__a) { | 
|  1196   return NewIterable(function() { |  1168   return NewIterable(function() { | 
|  1197     var a = __a; |  1169     var a = __a; | 
|  1198     var __goto = 0, __handler = 2, __currentError; |  1170     var __goto = 0, __handler = 2, __currentError; | 
|  1199     return function body(__errorCode, __result) { |  1171     return function body(__errorCode, __result) { | 
|  1200       if (__errorCode === 1) { |  1172       if (__errorCode === 1) { | 
|  1201         __currentError = __result; |  1173         __currentError = __result; | 
|  1202         __goto = __handler; |  1174         __goto = __handler; | 
|  1203       } |  1175       } | 
|  1204       while (true) |  1176       while (true) | 
|  1205         switch (__goto) { |  1177         switch (__goto) { | 
|  1206           case 0: |  1178           case 0: | 
|  1207             // Function start |  1179             // Function start | 
|  1208             foo(); |  1180             foo(); | 
|  1209             // goto return |  1181             // goto return | 
|  1210             __goto = 1; |  1182             __goto = 1; | 
|  1211             break; |  1183             break; | 
|  1212           case 1: |  1184           case 1: | 
|  1213             // return |  1185             // return | 
|  1214             return endOfIteration(); |  1186             return endOfIteration(); | 
|  1215           case 2: |  1187           case 2: | 
|  1216             // rethrow |  1188             // rethrow | 
|  1217             return uncaughtError(__currentError); |  1189             return uncaughtError(__currentError); | 
|  1218         } |  1190         } | 
|  1219     }; |  1191     }; | 
|  1220   }); |  1192   }); | 
|  1221 }"""); |  1193 }"""); | 
|  1222 } |  1194 } | 
| OLD | NEW |