| 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) { |
| 11 Fun fun = js(source); | 11 Fun fun = js(source); |
| 12 Fun rewritten = rewriter.rewrite(fun); | 12 Fun rewritten = rewriter.rewrite(fun); |
| 13 | 13 |
| 14 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); | 14 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); |
| 15 SimpleJavaScriptPrintingContext context = | 15 SimpleJavaScriptPrintingContext context = |
| 16 new SimpleJavaScriptPrintingContext(); | 16 new SimpleJavaScriptPrintingContext(); |
| 17 Printer printer = new Printer(options, context); | 17 Printer printer = new Printer(options, context); |
| 18 printer.visit(rewritten); | 18 printer.visit(rewritten); |
| 19 Expect.stringEquals(expected, context.getText()); | 19 Expect.stringEquals(expected, context.getText()); |
| 20 } | 20 } |
| 21 | 21 |
| 22 void testAsyncTransform(String source, String expected) { | 22 void testAsyncTransform(String source, String expected) { |
| 23 testTransform(source, expected, new AsyncRewriter( | 23 testTransform( |
| 24 null, // The diagnostic helper should not be used in these tests. | 24 source, |
| 25 null, | 25 expected, |
| 26 asyncHelper: new VariableUse("thenHelper"), | 26 new AsyncRewriter( |
| 27 newCompleter: new VariableUse("Completer"), | 27 null, // The diagnostic helper should not be used in these tests. |
| 28 wrapBody: new VariableUse("_wrapJsFunctionForAsync"), | 28 null, |
| 29 safeVariableName: (String name) => "__$name", | 29 asyncHelper: new VariableUse("thenHelper"), |
| 30 bodyName: new StringBackedName("body"))); | 30 newCompleter: new VariableUse("Completer"), |
| 31 wrapBody: new VariableUse("_wrapJsFunctionForAsync"), |
| 32 safeVariableName: (String name) => "__$name", |
| 33 bodyName: new StringBackedName("body"))); |
| 31 } | 34 } |
| 32 | 35 |
| 33 void testSyncStarTransform(String source, String expected) { | 36 void testSyncStarTransform(String source, String expected) { |
| 34 testTransform(source, expected, new SyncStarRewriter( | 37 testTransform( |
| 35 null, | 38 source, |
| 36 null, | 39 expected, |
| 37 endOfIteration: new VariableUse("endOfIteration"), | 40 new SyncStarRewriter(null, null, |
| 38 newIterable: new VariableUse("newIterable"), | 41 endOfIteration: new VariableUse("endOfIteration"), |
| 39 yieldStarExpression: new VariableUse("yieldStar"), | 42 newIterable: new VariableUse("newIterable"), |
| 40 uncaughtErrorExpression: new VariableUse("uncaughtError"), | 43 yieldStarExpression: new VariableUse("yieldStar"), |
| 41 safeVariableName: (String name) => "__$name", | 44 uncaughtErrorExpression: new VariableUse("uncaughtError"), |
| 42 bodyName: new StringBackedName("body"))); | 45 safeVariableName: (String name) => "__$name", |
| 46 bodyName: new StringBackedName("body"))); |
| 43 } | 47 } |
| 44 | 48 |
| 45 main() { | 49 main() { |
| 46 testAsyncTransform( /// 01: ok | 50 testAsyncTransform( |
| 47 r"""function() async { | 51 |
| 52 /// 01: ok |
| 53 r"""function() async { |
| 48 var closures = [new A.main_closure()], v0 = await closures, v1 = 0, v2, v3; | 54 var closures = [new A.main_closure()], v0 = await closures, v1 = 0, v2, v3; |
| 49 if (v1 < 0 || v1 >= v0.length) | 55 if (v1 < 0 || v1 >= v0.length) |
| 50 H.ioore(v0, v1); | 56 H.ioore(v0, v1); |
| 51 v2 = 4; | 57 v2 = 4; |
| 52 v3 = 2; | 58 v3 = 2; |
| 53 P.print(v0[v1].call$2(v2, v3)); | 59 P.print(v0[v1].call$2(v2, v3)); |
| 54 }""" | 60 }""", |
| 55 , /// 01: ok | 61 |
| 56 r"""function() { | 62 /// 01: ok |
| 63 r"""function() { |
| 57 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
closures, v0, v1, v2, v3; | 64 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
closures, v0, v1, v2, v3; |
| 58 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 65 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 59 if (__errorCode === 1) { | 66 if (__errorCode === 1) { |
| 60 __currentError = __result; | 67 __currentError = __result; |
| 61 __goto = __handler; | 68 __goto = __handler; |
| 62 } | 69 } |
| 63 while (true) | 70 while (true) |
| 64 switch (__goto) { | 71 switch (__goto) { |
| 65 case 0: | 72 case 0: |
| 66 // Function start | 73 // Function start |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 v3 = 2; | 84 v3 = 2; |
| 78 P.print(v0[v1].call$2(v2, v3)); | 85 P.print(v0[v1].call$2(v2, v3)); |
| 79 // implicit return | 86 // implicit return |
| 80 return thenHelper(null, 0, __completer); | 87 return thenHelper(null, 0, __completer); |
| 81 case 1: | 88 case 1: |
| 82 // rethrow | 89 // rethrow |
| 83 return thenHelper(__currentError, 1, __completer); | 90 return thenHelper(__currentError, 1, __completer); |
| 84 } | 91 } |
| 85 }); | 92 }); |
| 86 return thenHelper(null, body, __completer); | 93 return thenHelper(null, body, __completer); |
| 87 }""" | 94 }""") |
| 88 ) /// 01: ok | |
| 89 ; | |
| 90 | 95 |
| 91 testAsyncTransform(""" | 96 /// 01: ok |
| 97 ; |
| 98 |
| 99 testAsyncTransform( |
| 100 """ |
| 92 function(a) async { | 101 function(a) async { |
| 93 print(this.x); // Ensure `this` is translated in the helper function. | 102 print(this.x); // Ensure `this` is translated in the helper function. |
| 94 await foo(); | 103 await foo(); |
| 95 }""", """ | 104 }""", |
| 105 """ |
| 96 function(a) { | 106 function(a) { |
| 97 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__self = this; | 107 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__self = this; |
| 98 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 108 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 99 if (__errorCode === 1) { | 109 if (__errorCode === 1) { |
| 100 __currentError = __result; | 110 __currentError = __result; |
| 101 __goto = __handler; | 111 __goto = __handler; |
| 102 } | 112 } |
| 103 while (true) | 113 while (true) |
| 104 switch (__goto) { | 114 switch (__goto) { |
| 105 case 0: | 115 case 0: |
| 106 // Function start | 116 // Function start |
| 107 print(__self.x); | 117 print(__self.x); |
| 108 __goto = 2; | 118 __goto = 2; |
| 109 return thenHelper(foo(), body, __completer); | 119 return thenHelper(foo(), body, __completer); |
| 110 case 2: | 120 case 2: |
| 111 // returning from await. | 121 // returning from await. |
| 112 // implicit return | 122 // implicit return |
| 113 return thenHelper(null, 0, __completer); | 123 return thenHelper(null, 0, __completer); |
| 114 case 1: | 124 case 1: |
| 115 // rethrow | 125 // rethrow |
| 116 return thenHelper(__currentError, 1, __completer); | 126 return thenHelper(__currentError, 1, __completer); |
| 117 } | 127 } |
| 118 }); | 128 }); |
| 119 return thenHelper(null, body, __completer); | 129 return thenHelper(null, body, __completer); |
| 120 }"""); | 130 }"""); |
| 121 | 131 |
| 122 testAsyncTransform(""" | 132 testAsyncTransform( |
| 133 """ |
| 123 function(b) async { | 134 function(b) async { |
| 124 try { | 135 try { |
| 125 __outer: while (true) { // Overlapping label name. | 136 __outer: while (true) { // Overlapping label name. |
| 126 try { | 137 try { |
| 127 inner: while (true) { | 138 inner: while (true) { |
| 128 break __outer; // Break from untranslated loop to translated target. | 139 break __outer; // Break from untranslated loop to translated target. |
| 129 break; // break to untranslated target. | 140 break; // break to untranslated target. |
| 130 } | 141 } |
| 131 while (true) { | 142 while (true) { |
| 132 return; // Return via finallies. | 143 return; // Return via finallies. |
| 133 } | 144 } |
| 134 var __helper = await foo(); // Overlapping variable name. | 145 var __helper = await foo(); // Overlapping variable name. |
| 135 } finally { | 146 } finally { |
| 136 foo(); | 147 foo(); |
| 137 continue; // Continue from finally with pending finally. | 148 continue; // Continue from finally with pending finally. |
| 138 return 2; // Return from finally with pending finally. | 149 return 2; // Return from finally with pending finally. |
| 139 } | 150 } |
| 140 } | 151 } |
| 141 } finally { | 152 } finally { |
| 142 return 3; // Return from finally with no pending finally. | 153 return 3; // Return from finally with no pending finally. |
| 143 } | 154 } |
| 144 return 4; | 155 return 4; |
| 145 }""", """ | 156 }""", |
| 157 """ |
| 146 function(b) { | 158 function(b) { |
| 147 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, __next = [], __helper; | 159 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, __next = [], __helper; |
| 148 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 160 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 149 if (__errorCode === 1) { | 161 if (__errorCode === 1) { |
| 150 __currentError = __result; | 162 __currentError = __result; |
| 151 __goto = __handler; | 163 __goto = __handler; |
| 152 } | 164 } |
| 153 while (true) | 165 while (true) |
| 154 __outer1: | 166 __outer1: |
| 155 switch (__goto) { | 167 switch (__goto) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // return | 248 // return |
| 237 return thenHelper(__returnValue, 0, __completer); | 249 return thenHelper(__returnValue, 0, __completer); |
| 238 case 2: | 250 case 2: |
| 239 // rethrow | 251 // rethrow |
| 240 return thenHelper(__currentError, 1, __completer); | 252 return thenHelper(__currentError, 1, __completer); |
| 241 } | 253 } |
| 242 }); | 254 }); |
| 243 return thenHelper(null, body, __completer); | 255 return thenHelper(null, body, __completer); |
| 244 }"""); | 256 }"""); |
| 245 | 257 |
| 246 testAsyncTransform(""" | 258 testAsyncTransform( |
| 259 """ |
| 247 function(c) async { | 260 function(c) async { |
| 248 var a, b, c, d, e, f; | 261 var a, b, c, d, e, f; |
| 249 a = b++; // post- and preincrements. | 262 a = b++; // post- and preincrements. |
| 250 b = --b; | 263 b = --b; |
| 251 c = (await foo()).a++; | 264 c = (await foo()).a++; |
| 252 d = ++(await foo()).a; | 265 d = ++(await foo()).a; |
| 253 e = foo1()[await foo2()]--; | 266 e = foo1()[await foo2()]--; |
| 254 f = --foo1()[await foo2()]; | 267 f = --foo1()[await foo2()]; |
| 255 }""", """ | 268 }""", |
| 269 """ |
| 256 function(c) { | 270 function(c) { |
| 257 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a, b, c, d, e, f, __temp1; | 271 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a, b, c, d, e, f, __temp1; |
| 258 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 272 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 259 if (__errorCode === 1) { | 273 if (__errorCode === 1) { |
| 260 __currentError = __result; | 274 __currentError = __result; |
| 261 __goto = __handler; | 275 __goto = __handler; |
| 262 } | 276 } |
| 263 while (true) | 277 while (true) |
| 264 switch (__goto) { | 278 switch (__goto) { |
| 265 case 0: | 279 case 0: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 291 // implicit return | 305 // implicit return |
| 292 return thenHelper(null, 0, __completer); | 306 return thenHelper(null, 0, __completer); |
| 293 case 1: | 307 case 1: |
| 294 // rethrow | 308 // rethrow |
| 295 return thenHelper(__currentError, 1, __completer); | 309 return thenHelper(__currentError, 1, __completer); |
| 296 } | 310 } |
| 297 }); | 311 }); |
| 298 return thenHelper(null, body, __completer); | 312 return thenHelper(null, body, __completer); |
| 299 }"""); | 313 }"""); |
| 300 | 314 |
| 301 testAsyncTransform(""" | 315 testAsyncTransform( |
| 316 """ |
| 302 function(d2) async { | 317 function(d2) async { |
| 303 var a, b, c, d, e, f, g, h; // empty initializer | 318 var a, b, c, d, e, f, g, h; // empty initializer |
| 304 a = foo1() || await foo2(); // short circuiting operators | 319 a = foo1() || await foo2(); // short circuiting operators |
| 305 b = await foo1() || foo2(); | 320 b = await foo1() || foo2(); |
| 306 c = await foo1() || foo3(await foo2()); | 321 c = await foo1() || foo3(await foo2()); |
| 307 d = foo1() || foo2(); | 322 d = foo1() || foo2(); |
| 308 e = foo1() && await foo2(); | 323 e = foo1() && await foo2(); |
| 309 f = await foo1() && foo2(); | 324 f = await foo1() && foo2(); |
| 310 g = await foo1() && await foo2(); | 325 g = await foo1() && await foo2(); |
| 311 h = foo1() && foo2(); | 326 h = foo1() && foo2(); |
| 312 }""", """ | 327 }""", |
| 328 """ |
| 313 function(d2) { | 329 function(d2) { |
| 314 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a, b, c, d, e, f, g, h, __temp1; | 330 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a, b, c, d, e, f, g, h, __temp1; |
| 315 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 331 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 316 if (__errorCode === 1) { | 332 if (__errorCode === 1) { |
| 317 __currentError = __result; | 333 __currentError = __result; |
| 318 __goto = __handler; | 334 __goto = __handler; |
| 319 } | 335 } |
| 320 while (true) | 336 while (true) |
| 321 switch (__goto) { | 337 switch (__goto) { |
| 322 case 0: | 338 case 0: |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 // implicit return | 440 // implicit return |
| 425 return thenHelper(null, 0, __completer); | 441 return thenHelper(null, 0, __completer); |
| 426 case 1: | 442 case 1: |
| 427 // rethrow | 443 // rethrow |
| 428 return thenHelper(__currentError, 1, __completer); | 444 return thenHelper(__currentError, 1, __completer); |
| 429 } | 445 } |
| 430 }); | 446 }); |
| 431 return thenHelper(null, body, __completer); | 447 return thenHelper(null, body, __completer); |
| 432 }"""); | 448 }"""); |
| 433 | 449 |
| 434 testAsyncTransform(""" | 450 testAsyncTransform( |
| 451 """ |
| 435 function(x, y) async { | 452 function(x, y) async { |
| 436 while (true) { | 453 while (true) { |
| 437 switch(y) { // Switch with no awaits in case key expressions | 454 switch(y) { // Switch with no awaits in case key expressions |
| 438 case 0: | 455 case 0: |
| 439 case 1: | 456 case 1: |
| 440 await foo(); | 457 await foo(); |
| 441 continue; // Continue the loop, not the switch | 458 continue; // Continue the loop, not the switch |
| 442 case 1: // Duplicate case | 459 case 1: // Duplicate case |
| 443 await foo(); | 460 await foo(); |
| 444 break; // Break the switch | 461 break; // Break the switch |
| 445 case 2: | 462 case 2: |
| 446 foo(); // No default | 463 foo(); // No default |
| 447 } | 464 } |
| 448 } | 465 } |
| 449 }""", """ | 466 }""", |
| 467 """ |
| 450 function(x, y) { | 468 function(x, y) { |
| 451 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError; | 469 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError; |
| 452 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 470 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 453 if (__errorCode === 1) { | 471 if (__errorCode === 1) { |
| 454 __currentError = __result; | 472 __currentError = __result; |
| 455 __goto = __handler; | 473 __goto = __handler; |
| 456 } | 474 } |
| 457 while (true) | 475 while (true) |
| 458 switch (__goto) { | 476 switch (__goto) { |
| 459 case 0: | 477 case 0: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 // implicit return | 536 // implicit return |
| 519 return thenHelper(null, 0, __completer); | 537 return thenHelper(null, 0, __completer); |
| 520 case 1: | 538 case 1: |
| 521 // rethrow | 539 // rethrow |
| 522 return thenHelper(__currentError, 1, __completer); | 540 return thenHelper(__currentError, 1, __completer); |
| 523 } | 541 } |
| 524 }); | 542 }); |
| 525 return thenHelper(null, body, __completer); | 543 return thenHelper(null, body, __completer); |
| 526 }"""); | 544 }"""); |
| 527 | 545 |
| 528 testAsyncTransform(""" | 546 testAsyncTransform( |
| 547 """ |
| 529 function(f) async { | 548 function(f) async { |
| 530 do { | 549 do { |
| 531 var a = await foo(); | 550 var a = await foo(); |
| 532 if (a) // If with no awaits in body | 551 if (a) // If with no awaits in body |
| 533 break; | 552 break; |
| 534 else | 553 else |
| 535 continue; | 554 continue; |
| 536 } while (await foo()); | 555 } while (await foo()); |
| 537 } | 556 } |
| 538 """, """ | 557 """, |
| 558 """ |
| 539 function(f) { | 559 function(f) { |
| 540 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a; | 560 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
a; |
| 541 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 561 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 542 if (__errorCode === 1) { | 562 if (__errorCode === 1) { |
| 543 __currentError = __result; | 563 __currentError = __result; |
| 544 __goto = __handler; | 564 __goto = __handler; |
| 545 } | 565 } |
| 546 while (true) | 566 while (true) |
| 547 switch (__goto) { | 567 switch (__goto) { |
| 548 case 0: | 568 case 0: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 579 // implicit return | 599 // implicit return |
| 580 return thenHelper(null, 0, __completer); | 600 return thenHelper(null, 0, __completer); |
| 581 case 1: | 601 case 1: |
| 582 // rethrow | 602 // rethrow |
| 583 return thenHelper(__currentError, 1, __completer); | 603 return thenHelper(__currentError, 1, __completer); |
| 584 } | 604 } |
| 585 }); | 605 }); |
| 586 return thenHelper(null, body, __completer); | 606 return thenHelper(null, body, __completer); |
| 587 }"""); | 607 }"""); |
| 588 | 608 |
| 589 testAsyncTransform(""" | 609 testAsyncTransform( |
| 610 """ |
| 590 function(g) async { | 611 function(g) async { |
| 591 for (var i = 0; i < await foo1(); i += await foo2()) { | 612 for (var i = 0; i < await foo1(); i += await foo2()) { |
| 592 if (foo(i)) | 613 if (foo(i)) |
| 593 continue; | 614 continue; |
| 594 else | 615 else |
| 595 break; | 616 break; |
| 596 if (!foo(i)) { // If with no else and await in body. | 617 if (!foo(i)) { // If with no else and await in body. |
| 597 await foo(); | 618 await foo(); |
| 598 return; | 619 return; |
| 599 } | 620 } |
| 600 print(await(foo(i))); | 621 print(await(foo(i))); |
| 601 } | 622 } |
| 602 } | 623 } |
| 603 """, """ | 624 """, |
| 625 """ |
| 604 function(g) { | 626 function(g) { |
| 605 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, i, __temp1; | 627 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, i, __temp1; |
| 606 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 628 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 607 if (__errorCode === 1) { | 629 if (__errorCode === 1) { |
| 608 __currentError = __result; | 630 __currentError = __result; |
| 609 __goto = __handler; | 631 __goto = __handler; |
| 610 } | 632 } |
| 611 while (true) | 633 while (true) |
| 612 switch (__goto) { | 634 switch (__goto) { |
| 613 case 0: | 635 case 0: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 // return | 691 // return |
| 670 return thenHelper(__returnValue, 0, __completer); | 692 return thenHelper(__returnValue, 0, __completer); |
| 671 case 2: | 693 case 2: |
| 672 // rethrow | 694 // rethrow |
| 673 return thenHelper(__currentError, 1, __completer); | 695 return thenHelper(__currentError, 1, __completer); |
| 674 } | 696 } |
| 675 }); | 697 }); |
| 676 return thenHelper(null, body, __completer); | 698 return thenHelper(null, body, __completer); |
| 677 }"""); | 699 }"""); |
| 678 | 700 |
| 679 testAsyncTransform(""" | 701 testAsyncTransform( |
| 702 """ |
| 680 function(a, h) async { | 703 function(a, h) async { |
| 681 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; | 704 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; |
| 682 x["a"] = 2; // Different assignments | 705 x["a"] = 2; // Different assignments |
| 683 (await foo()).a = 3; | 706 (await foo()).a = 3; |
| 684 x[await foo()] = 4; | 707 x[await foo()] = 4; |
| 685 x[(await foo1()).a = await foo2()] = 5; | 708 x[(await foo1()).a = await foo2()] = 5; |
| 686 (await foo1())[await foo2()] = await foo3(6); | 709 (await foo1())[await foo2()] = await foo3(6); |
| 687 } | 710 } |
| 688 """, """ | 711 """, |
| 712 """ |
| 689 function(a, h) { | 713 function(a, h) { |
| 690 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
x, __temp1, __temp2; | 714 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
x, __temp1, __temp2; |
| 691 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 715 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 692 if (__errorCode === 1) { | 716 if (__errorCode === 1) { |
| 693 __currentError = __result; | 717 __currentError = __result; |
| 694 __goto = __handler; | 718 __goto = __handler; |
| 695 } | 719 } |
| 696 while (true) | 720 while (true) |
| 697 switch (__goto) { | 721 switch (__goto) { |
| 698 case 0: | 722 case 0: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 // implicit return | 768 // implicit return |
| 745 return thenHelper(null, 0, __completer); | 769 return thenHelper(null, 0, __completer); |
| 746 case 1: | 770 case 1: |
| 747 // rethrow | 771 // rethrow |
| 748 return thenHelper(__currentError, 1, __completer); | 772 return thenHelper(__currentError, 1, __completer); |
| 749 } | 773 } |
| 750 }); | 774 }); |
| 751 return thenHelper(null, body, __completer); | 775 return thenHelper(null, body, __completer); |
| 752 }"""); | 776 }"""); |
| 753 | 777 |
| 754 testAsyncTransform(""" | 778 testAsyncTransform( |
| 779 """ |
| 755 function(c, i) async { | 780 function(c, i) async { |
| 756 try { | 781 try { |
| 757 var x = c ? await foo() : foo(); // conditional | 782 var x = c ? await foo() : foo(); // conditional |
| 758 var y = {}; | 783 var y = {}; |
| 759 } catch (error) { | 784 } catch (error) { |
| 760 try { | 785 try { |
| 761 x = c ? await fooError(error) : fooError(error); | 786 x = c ? await fooError(error) : fooError(error); |
| 762 } catch (error) { // nested error handler with overlapping name | 787 } catch (error) { // nested error handler with overlapping name |
| 763 y.x = foo(error); | 788 y.x = foo(error); |
| 764 } finally { | 789 } finally { |
| 765 foo(x); | 790 foo(x); |
| 766 } | 791 } |
| 767 } | 792 } |
| 768 } | 793 } |
| 769 """, """ | 794 """, |
| 795 """ |
| 770 function(c, i) { | 796 function(c, i) { |
| 771 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__next = [], x, y, __error, __error1; | 797 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__next = [], x, y, __error, __error1; |
| 772 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 798 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 773 if (__errorCode === 1) { | 799 if (__errorCode === 1) { |
| 774 __currentError = __result; | 800 __currentError = __result; |
| 775 __goto = __handler; | 801 __goto = __handler; |
| 776 } | 802 } |
| 777 while (true) | 803 while (true) |
| 778 switch (__goto) { | 804 switch (__goto) { |
| 779 case 0: | 805 case 0: |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 // implicit return | 887 // implicit return |
| 862 return thenHelper(null, 0, __completer); | 888 return thenHelper(null, 0, __completer); |
| 863 case 1: | 889 case 1: |
| 864 // rethrow | 890 // rethrow |
| 865 return thenHelper(__currentError, 1, __completer); | 891 return thenHelper(__currentError, 1, __completer); |
| 866 } | 892 } |
| 867 }); | 893 }); |
| 868 return thenHelper(null, body, __completer); | 894 return thenHelper(null, body, __completer); |
| 869 }"""); | 895 }"""); |
| 870 | 896 |
| 871 testAsyncTransform(""" | 897 testAsyncTransform( |
| 898 """ |
| 872 function(x, y, j) async { | 899 function(x, y, j) async { |
| 873 print(await(foo(x))); // calls | 900 print(await(foo(x))); // calls |
| 874 (await print)(foo(x)); | 901 (await print)(foo(x)); |
| 875 print(foo(await x)); | 902 print(foo(await x)); |
| 876 await (print(foo(await x))); | 903 await (print(foo(await x))); |
| 877 print(foo(x, await y, z)); | 904 print(foo(x, await y, z)); |
| 878 } | 905 } |
| 879 """, """ | 906 """, |
| 907 """ |
| 880 function(x, y, j) { | 908 function(x, y, j) { |
| 881 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__temp1, __temp2, __temp3; | 909 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__temp1, __temp2, __temp3; |
| 882 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 910 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 883 if (__errorCode === 1) { | 911 if (__errorCode === 1) { |
| 884 __currentError = __result; | 912 __currentError = __result; |
| 885 __goto = __handler; | 913 __goto = __handler; |
| 886 } | 914 } |
| 887 while (true) | 915 while (true) |
| 888 switch (__goto) { | 916 switch (__goto) { |
| 889 case 0: | 917 case 0: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 // implicit return | 955 // implicit return |
| 928 return thenHelper(null, 0, __completer); | 956 return thenHelper(null, 0, __completer); |
| 929 case 1: | 957 case 1: |
| 930 // rethrow | 958 // rethrow |
| 931 return thenHelper(__currentError, 1, __completer); | 959 return thenHelper(__currentError, 1, __completer); |
| 932 } | 960 } |
| 933 }); | 961 }); |
| 934 return thenHelper(null, body, __completer); | 962 return thenHelper(null, body, __completer); |
| 935 }"""); | 963 }"""); |
| 936 | 964 |
| 937 testAsyncTransform(""" | 965 testAsyncTransform( |
| 966 """ |
| 938 function(x, y, k) async { | 967 function(x, y, k) async { |
| 939 while (await(foo())) { | 968 while (await(foo())) { |
| 940 lab: { // labelled statement | 969 lab: { // labelled statement |
| 941 switch(y) { | 970 switch(y) { |
| 942 case 0: | 971 case 0: |
| 943 foo(); | 972 foo(); |
| 944 case 0: // Duplicate case | 973 case 0: // Duplicate case |
| 945 print(await foo1(x)); | 974 print(await foo1(x)); |
| 946 return y; | 975 return y; |
| 947 case await bar(): // await in case | 976 case await bar(): // await in case |
| 948 print(await foobar(x)); | 977 print(await foobar(x)); |
| 949 return y; | 978 return y; |
| 950 case x: | 979 case x: |
| 951 if (a) { | 980 if (a) { |
| 952 throw new Error(); | 981 throw new Error(); |
| 953 } else { | 982 } else { |
| 954 continue; | 983 continue; |
| 955 } | 984 } |
| 956 default: // defaul case | 985 default: // defaul case |
| 957 break lab; // break to label | 986 break lab; // break to label |
| 958 } | 987 } |
| 959 foo(); | 988 foo(); |
| 960 } | 989 } |
| 961 } | 990 } |
| 962 }""", """ | 991 }""", |
| 992 """ |
| 963 function(x, y, k) { | 993 function(x, y, k) { |
| 964 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, __temp1; | 994 var __goto = 0, __completer = new Completer(), __returnValue, __handler = 2, _
_currentError, __temp1; |
| 965 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 995 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 966 if (__errorCode === 1) { | 996 if (__errorCode === 1) { |
| 967 __currentError = __result; | 997 __currentError = __result; |
| 968 __goto = __handler; | 998 __goto = __handler; |
| 969 } | 999 } |
| 970 while (true) | 1000 while (true) |
| 971 switch (__goto) { | 1001 switch (__goto) { |
| 972 case 0: | 1002 case 0: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 // return | 1097 // return |
| 1068 return thenHelper(__returnValue, 0, __completer); | 1098 return thenHelper(__returnValue, 0, __completer); |
| 1069 case 2: | 1099 case 2: |
| 1070 // rethrow | 1100 // rethrow |
| 1071 return thenHelper(__currentError, 1, __completer); | 1101 return thenHelper(__currentError, 1, __completer); |
| 1072 } | 1102 } |
| 1073 }); | 1103 }); |
| 1074 return thenHelper(null, body, __completer); | 1104 return thenHelper(null, body, __completer); |
| 1075 }"""); | 1105 }"""); |
| 1076 | 1106 |
| 1077 testAsyncTransform(""" | 1107 testAsyncTransform( |
| 1108 """ |
| 1078 function(l) async { | 1109 function(l) async { |
| 1079 switch(await l) { | 1110 switch(await l) { |
| 1080 case 1: | 1111 case 1: |
| 1081 print(1); | 1112 print(1); |
| 1082 break; | 1113 break; |
| 1083 case 2: | 1114 case 2: |
| 1084 print(1); | 1115 print(1); |
| 1085 // Fallthrough | 1116 // Fallthrough |
| 1086 default: | 1117 default: |
| 1087 print(2); | 1118 print(2); |
| 1088 break; | 1119 break; |
| 1089 } | 1120 } |
| 1090 }""", """ | 1121 }""", |
| 1122 """ |
| 1091 function(l) { | 1123 function(l) { |
| 1092 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError; | 1124 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError; |
| 1093 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 1125 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 1094 if (__errorCode === 1) { | 1126 if (__errorCode === 1) { |
| 1095 __currentError = __result; | 1127 __currentError = __result; |
| 1096 __goto = __handler; | 1128 __goto = __handler; |
| 1097 } | 1129 } |
| 1098 while (true) | 1130 while (true) |
| 1099 switch (__goto) { | 1131 switch (__goto) { |
| 1100 case 0: | 1132 case 0: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1116 // implicit return | 1148 // implicit return |
| 1117 return thenHelper(null, 0, __completer); | 1149 return thenHelper(null, 0, __completer); |
| 1118 case 1: | 1150 case 1: |
| 1119 // rethrow | 1151 // rethrow |
| 1120 return thenHelper(__currentError, 1, __completer); | 1152 return thenHelper(__currentError, 1, __completer); |
| 1121 } | 1153 } |
| 1122 }); | 1154 }); |
| 1123 return thenHelper(null, body, __completer); | 1155 return thenHelper(null, body, __completer); |
| 1124 }"""); | 1156 }"""); |
| 1125 | 1157 |
| 1126 testAsyncTransform(""" | 1158 testAsyncTransform( |
| 1159 """ |
| 1127 function(m) async { | 1160 function(m) async { |
| 1128 var exception = 1; | 1161 var exception = 1; |
| 1129 try { | 1162 try { |
| 1130 await 42; | 1163 await 42; |
| 1131 throw 42; | 1164 throw 42; |
| 1132 } catch (exception) { | 1165 } catch (exception) { |
| 1133 exception = await 10; | 1166 exception = await 10; |
| 1134 exception += await 10; | 1167 exception += await 10; |
| 1135 exception++; | 1168 exception++; |
| 1136 exception--; | 1169 exception--; |
| 1137 ++exception; | 1170 ++exception; |
| 1138 --exception; | 1171 --exception; |
| 1139 exception += 10; | 1172 exception += 10; |
| 1140 } | 1173 } |
| 1141 print(exception); | 1174 print(exception); |
| 1142 }""", """ | 1175 }""", |
| 1176 """ |
| 1143 function(m) { | 1177 function(m) { |
| 1144 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__next = [], exception, __exception; | 1178 var __goto = 0, __completer = new Completer(), __handler = 1, __currentError,
__next = [], exception, __exception; |
| 1145 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 1179 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 1146 if (__errorCode === 1) { | 1180 if (__errorCode === 1) { |
| 1147 __currentError = __result; | 1181 __currentError = __result; |
| 1148 __goto = __handler; | 1182 __goto = __handler; |
| 1149 } | 1183 } |
| 1150 while (true) | 1184 while (true) |
| 1151 switch (__goto) { | 1185 switch (__goto) { |
| 1152 case 0: | 1186 case 0: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 // implicit return | 1229 // implicit return |
| 1196 return thenHelper(null, 0, __completer); | 1230 return thenHelper(null, 0, __completer); |
| 1197 case 1: | 1231 case 1: |
| 1198 // rethrow | 1232 // rethrow |
| 1199 return thenHelper(__currentError, 1, __completer); | 1233 return thenHelper(__currentError, 1, __completer); |
| 1200 } | 1234 } |
| 1201 }); | 1235 }); |
| 1202 return thenHelper(null, body, __completer); | 1236 return thenHelper(null, body, __completer); |
| 1203 }"""); | 1237 }"""); |
| 1204 | 1238 |
| 1205 testSyncStarTransform(""" | 1239 testSyncStarTransform( |
| 1240 """ |
| 1206 function(a) sync* { | 1241 function(a) sync* { |
| 1207 // Ensure that return of a value is treated as first evaluating the value, and | 1242 // Ensure that return of a value is treated as first evaluating the value, and |
| 1208 // then returning. | 1243 // then returning. |
| 1209 return foo(); | 1244 return foo(); |
| 1210 }""", """ | 1245 }""", |
| 1246 """ |
| 1211 function(__a) { | 1247 function(__a) { |
| 1212 return new newIterable(function() { | 1248 return new newIterable(function() { |
| 1213 var a = __a; | 1249 var a = __a; |
| 1214 var __goto = 0, __handler = 2, __currentError; | 1250 var __goto = 0, __handler = 2, __currentError; |
| 1215 return function body(__errorCode, __result) { | 1251 return function body(__errorCode, __result) { |
| 1216 if (__errorCode === 1) { | 1252 if (__errorCode === 1) { |
| 1217 __currentError = __result; | 1253 __currentError = __result; |
| 1218 __goto = __handler; | 1254 __goto = __handler; |
| 1219 } | 1255 } |
| 1220 while (true) | 1256 while (true) |
| 1221 switch (__goto) { | 1257 switch (__goto) { |
| 1222 case 0: | 1258 case 0: |
| 1223 // Function start | 1259 // Function start |
| 1224 foo(); | 1260 foo(); |
| 1225 // goto return | 1261 // goto return |
| 1226 __goto = 1; | 1262 __goto = 1; |
| 1227 break; | 1263 break; |
| 1228 case 1: | 1264 case 1: |
| 1229 // return | 1265 // return |
| 1230 return endOfIteration(); | 1266 return endOfIteration(); |
| 1231 case 2: | 1267 case 2: |
| 1232 // rethrow | 1268 // rethrow |
| 1233 return uncaughtError(__currentError); | 1269 return uncaughtError(__currentError); |
| 1234 } | 1270 } |
| 1235 }; | 1271 }; |
| 1236 }); | 1272 }); |
| 1237 }"""); | 1273 }"""); |
| 1238 } | 1274 } |
| OLD | NEW |