| 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( | 23 testTransform( |
| 24 source, | 24 source, |
| 25 expected, | 25 expected, |
| 26 new AsyncRewriter( | 26 new AsyncRewriter( |
| 27 null, // The diagnostic helper should not be used in these tests. | 27 null, // The diagnostic helper should not be used in these tests. |
| 28 null, | 28 null, |
| 29 asyncHelper: new VariableUse("thenHelper"), | 29 asyncStart: new VariableUse("startHelper"), |
| 30 asyncAwait: new VariableUse("awaitHelper"), |
| 31 asyncReturn: new VariableUse("returnHelper"), |
| 32 asyncRethrow: new VariableUse("rethrowHelper"), |
| 30 completerFactory: new VariableUse("NewCompleter"), | 33 completerFactory: new VariableUse("NewCompleter"), |
| 31 wrapBody: new VariableUse("_wrapJsFunctionForAsync"), | 34 wrapBody: new VariableUse("_wrapJsFunctionForAsync"), |
| 32 safeVariableName: (String name) => "__$name", | 35 safeVariableName: (String name) => "__$name", |
| 33 bodyName: new StringBackedName("body"))); | 36 bodyName: new StringBackedName("body"))); |
| 34 } | 37 } |
| 35 | 38 |
| 36 void testSyncStarTransform(String source, String expected) { | 39 void testSyncStarTransform(String source, String expected) { |
| 37 testTransform( | 40 testTransform( |
| 38 source, | 41 source, |
| 39 expected, | 42 expected, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 66 if (__errorCode === 1) { | 69 if (__errorCode === 1) { |
| 67 __currentError = __result; | 70 __currentError = __result; |
| 68 __goto = __handler; | 71 __goto = __handler; |
| 69 } | 72 } |
| 70 while (true) | 73 while (true) |
| 71 switch (__goto) { | 74 switch (__goto) { |
| 72 case 0: | 75 case 0: |
| 73 // Function start | 76 // Function start |
| 74 closures = [new A.main_closure()]; | 77 closures = [new A.main_closure()]; |
| 75 __goto = 2; | 78 __goto = 2; |
| 76 return thenHelper(closures, body, __completer); | 79 return awaitHelper(closures, body); |
| 77 case 2: | 80 case 2: |
| 78 // returning from await. | 81 // returning from await. |
| 79 v0 = __result; | 82 v0 = __result; |
| 80 v1 = 0; | 83 v1 = 0; |
| 81 if (v1 < 0 || v1 >= v0.length) | 84 if (v1 < 0 || v1 >= v0.length) |
| 82 H.ioore(v0, v1); | 85 H.ioore(v0, v1); |
| 83 v2 = 4; | 86 v2 = 4; |
| 84 v3 = 2; | 87 v3 = 2; |
| 85 P.print(v0[v1].call$2(v2, v3)); | 88 P.print(v0[v1].call$2(v2, v3)); |
| 86 // implicit return | 89 // implicit return |
| 87 return thenHelper(null, 0, __completer); | 90 return returnHelper(null, __completer); |
| 88 case 1: | 91 case 1: |
| 89 // rethrow | 92 // rethrow |
| 90 return thenHelper(__currentError, 1, __completer); | 93 return rethrowHelper(__currentError, __completer); |
| 91 } | 94 } |
| 92 }); | 95 }); |
| 93 return thenHelper(null, body, __completer); | 96 return startHelper(body, __completer); |
| 94 }""") | 97 }""") |
| 95 | 98 |
| 96 /// 01: ok | 99 /// 01: ok |
| 97 ; | 100 ; |
| 98 | 101 |
| 99 testAsyncTransform( | 102 testAsyncTransform( |
| 100 """ | 103 """ |
| 101 function(a) async { | 104 function(a) async { |
| 102 print(this.x); // Ensure `this` is translated in the helper function. | 105 print(this.x); // Ensure `this` is translated in the helper function. |
| 103 await foo(); | 106 await foo(); |
| 104 }""", | 107 }""", |
| 105 """ | 108 """ |
| 106 function(a) { | 109 function(a) { |
| 107 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
_self = this; | 110 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
_self = this; |
| 108 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 111 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 109 if (__errorCode === 1) { | 112 if (__errorCode === 1) { |
| 110 __currentError = __result; | 113 __currentError = __result; |
| 111 __goto = __handler; | 114 __goto = __handler; |
| 112 } | 115 } |
| 113 while (true) | 116 while (true) |
| 114 switch (__goto) { | 117 switch (__goto) { |
| 115 case 0: | 118 case 0: |
| 116 // Function start | 119 // Function start |
| 117 print(__self.x); | 120 print(__self.x); |
| 118 __goto = 2; | 121 __goto = 2; |
| 119 return thenHelper(foo(), body, __completer); | 122 return awaitHelper(foo(), body); |
| 120 case 2: | 123 case 2: |
| 121 // returning from await. | 124 // returning from await. |
| 122 // implicit return | 125 // implicit return |
| 123 return thenHelper(null, 0, __completer); | 126 return returnHelper(null, __completer); |
| 124 case 1: | 127 case 1: |
| 125 // rethrow | 128 // rethrow |
| 126 return thenHelper(__currentError, 1, __completer); | 129 return rethrowHelper(__currentError, __completer); |
| 127 } | 130 } |
| 128 }); | 131 }); |
| 129 return thenHelper(null, body, __completer); | 132 return startHelper(body, __completer); |
| 130 }"""); | 133 }"""); |
| 131 | 134 |
| 132 testAsyncTransform( | 135 testAsyncTransform( |
| 133 """ | 136 """ |
| 134 function(b) async { | 137 function(b) async { |
| 135 try { | 138 try { |
| 136 __outer: while (true) { // Overlapping label name. | 139 __outer: while (true) { // Overlapping label name. |
| 137 try { | 140 try { |
| 138 inner: while (true) { | 141 inner: while (true) { |
| 139 break __outer; // Break from untranslated loop to translated target. | 142 break __outer; // Break from untranslated loop to translated target. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 break __outer1; | 182 break __outer1; |
| 180 break; | 183 break; |
| 181 } | 184 } |
| 182 while (true) { | 185 while (true) { |
| 183 __next = [1, 4]; | 186 __next = [1, 4]; |
| 184 // goto finally | 187 // goto finally |
| 185 __goto = 10; | 188 __goto = 10; |
| 186 break __outer1; | 189 break __outer1; |
| 187 } | 190 } |
| 188 __goto = 12; | 191 __goto = 12; |
| 189 return thenHelper(foo(), body, __completer); | 192 return awaitHelper(foo(), body); |
| 190 case 12: | 193 case 12: |
| 191 // returning from await. | 194 // returning from await. |
| 192 __helper = __result; | 195 __helper = __result; |
| 193 __next.push(11); | 196 __next.push(11); |
| 194 // goto finally | 197 // goto finally |
| 195 __goto = 10; | 198 __goto = 10; |
| 196 break; | 199 break; |
| 197 case 9: | 200 case 9: |
| 198 // uncaught | 201 // uncaught |
| 199 __next = [3]; | 202 __next = [3]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 __goto = __next.pop(); | 242 __goto = __next.pop(); |
| 240 break; | 243 break; |
| 241 case 5: | 244 case 5: |
| 242 // after finally | 245 // after finally |
| 243 __returnValue = 4; | 246 __returnValue = 4; |
| 244 // goto return | 247 // goto return |
| 245 __goto = 1; | 248 __goto = 1; |
| 246 break; | 249 break; |
| 247 case 1: | 250 case 1: |
| 248 // return | 251 // return |
| 249 return thenHelper(__returnValue, 0, __completer); | 252 return returnHelper(__returnValue, __completer); |
| 250 case 2: | 253 case 2: |
| 251 // rethrow | 254 // rethrow |
| 252 return thenHelper(__currentError, 1, __completer); | 255 return rethrowHelper(__currentError, __completer); |
| 253 } | 256 } |
| 254 }); | 257 }); |
| 255 return thenHelper(null, body, __completer); | 258 return startHelper(body, __completer); |
| 256 }"""); | 259 }"""); |
| 257 | 260 |
| 258 testAsyncTransform( | 261 testAsyncTransform( |
| 259 """ | 262 """ |
| 260 function(c) async { | 263 function(c) async { |
| 261 var a, b, c, d, e, f; | 264 var a, b, c, d, e, f; |
| 262 a = b++; // post- and preincrements. | 265 a = b++; // post- and preincrements. |
| 263 b = --b; | 266 b = --b; |
| 264 c = (await foo()).a++; | 267 c = (await foo()).a++; |
| 265 d = ++(await foo()).a; | 268 d = ++(await foo()).a; |
| 266 e = foo1()[await foo2()]--; | 269 e = foo1()[await foo2()]--; |
| 267 f = --foo1()[await foo2()]; | 270 f = --foo1()[await foo2()]; |
| 268 }""", | 271 }""", |
| 269 """ | 272 """ |
| 270 function(c) { | 273 function(c) { |
| 271 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, a
, b, c, d, e, f, __temp1; | 274 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, a
, b, c, d, e, f, __temp1; |
| 272 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 275 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 273 if (__errorCode === 1) { | 276 if (__errorCode === 1) { |
| 274 __currentError = __result; | 277 __currentError = __result; |
| 275 __goto = __handler; | 278 __goto = __handler; |
| 276 } | 279 } |
| 277 while (true) | 280 while (true) |
| 278 switch (__goto) { | 281 switch (__goto) { |
| 279 case 0: | 282 case 0: |
| 280 // Function start | 283 // Function start |
| 281 a = b++; | 284 a = b++; |
| 282 b = --b; | 285 b = --b; |
| 283 __goto = 2; | 286 __goto = 2; |
| 284 return thenHelper(foo(), body, __completer); | 287 return awaitHelper(foo(), body); |
| 285 case 2: | 288 case 2: |
| 286 // returning from await. | 289 // returning from await. |
| 287 c = __result.a++; | 290 c = __result.a++; |
| 288 __goto = 3; | 291 __goto = 3; |
| 289 return thenHelper(foo(), body, __completer); | 292 return awaitHelper(foo(), body); |
| 290 case 3: | 293 case 3: |
| 291 // returning from await. | 294 // returning from await. |
| 292 d = ++__result.a; | 295 d = ++__result.a; |
| 293 __temp1 = foo1(); | 296 __temp1 = foo1(); |
| 294 __goto = 4; | 297 __goto = 4; |
| 295 return thenHelper(foo2(), body, __completer); | 298 return awaitHelper(foo2(), body); |
| 296 case 4: | 299 case 4: |
| 297 // returning from await. | 300 // returning from await. |
| 298 e = __temp1[__result]--; | 301 e = __temp1[__result]--; |
| 299 __temp1 = foo1(); | 302 __temp1 = foo1(); |
| 300 __goto = 5; | 303 __goto = 5; |
| 301 return thenHelper(foo2(), body, __completer); | 304 return awaitHelper(foo2(), body); |
| 302 case 5: | 305 case 5: |
| 303 // returning from await. | 306 // returning from await. |
| 304 f = --__temp1[__result]; | 307 f = --__temp1[__result]; |
| 305 // implicit return | 308 // implicit return |
| 306 return thenHelper(null, 0, __completer); | 309 return returnHelper(null, __completer); |
| 307 case 1: | 310 case 1: |
| 308 // rethrow | 311 // rethrow |
| 309 return thenHelper(__currentError, 1, __completer); | 312 return rethrowHelper(__currentError, __completer); |
| 310 } | 313 } |
| 311 }); | 314 }); |
| 312 return thenHelper(null, body, __completer); | 315 return startHelper(body, __completer); |
| 313 }"""); | 316 }"""); |
| 314 | 317 |
| 315 testAsyncTransform( | 318 testAsyncTransform( |
| 316 """ | 319 """ |
| 317 function(d2) async { | 320 function(d2) async { |
| 318 var a, b, c, d, e, f, g, h; // empty initializer | 321 var a, b, c, d, e, f, g, h; // empty initializer |
| 319 a = foo1() || await foo2(); // short circuiting operators | 322 a = foo1() || await foo2(); // short circuiting operators |
| 320 b = await foo1() || foo2(); | 323 b = await foo1() || foo2(); |
| 321 c = await foo1() || foo3(await foo2()); | 324 c = await foo1() || foo3(await foo2()); |
| 322 d = foo1() || foo2(); | 325 d = foo1() || foo2(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 344 // goto then | 347 // goto then |
| 345 __goto = 2; | 348 __goto = 2; |
| 346 break; | 349 break; |
| 347 } | 350 } |
| 348 // goto join | 351 // goto join |
| 349 __goto = 3; | 352 __goto = 3; |
| 350 break; | 353 break; |
| 351 case 2: | 354 case 2: |
| 352 // then | 355 // then |
| 353 __goto = 4; | 356 __goto = 4; |
| 354 return thenHelper(foo2(), body, __completer); | 357 return awaitHelper(foo2(), body); |
| 355 case 4: | 358 case 4: |
| 356 // returning from await. | 359 // returning from await. |
| 357 case 3: | 360 case 3: |
| 358 // join | 361 // join |
| 359 a = __result; | 362 a = __result; |
| 360 __goto = 5; | 363 __goto = 5; |
| 361 return thenHelper(foo1(), body, __completer); | 364 return awaitHelper(foo1(), body); |
| 362 case 5: | 365 case 5: |
| 363 // returning from await. | 366 // returning from await. |
| 364 b = __result || foo2(); | 367 b = __result || foo2(); |
| 365 __goto = 8; | 368 __goto = 8; |
| 366 return thenHelper(foo1(), body, __completer); | 369 return awaitHelper(foo1(), body); |
| 367 case 8: | 370 case 8: |
| 368 // returning from await. | 371 // returning from await. |
| 369 __temp1 = __result; | 372 __temp1 = __result; |
| 370 if (__temp1) | 373 if (__temp1) |
| 371 __result = __temp1; | 374 __result = __temp1; |
| 372 else { | 375 else { |
| 373 // goto then | 376 // goto then |
| 374 __goto = 6; | 377 __goto = 6; |
| 375 break; | 378 break; |
| 376 } | 379 } |
| 377 // goto join | 380 // goto join |
| 378 __goto = 7; | 381 __goto = 7; |
| 379 break; | 382 break; |
| 380 case 6: | 383 case 6: |
| 381 // then | 384 // then |
| 382 __temp1 = foo3; | 385 __temp1 = foo3; |
| 383 __goto = 9; | 386 __goto = 9; |
| 384 return thenHelper(foo2(), body, __completer); | 387 return awaitHelper(foo2(), body); |
| 385 case 9: | 388 case 9: |
| 386 // returning from await. | 389 // returning from await. |
| 387 __result = __temp1(__result); | 390 __result = __temp1(__result); |
| 388 case 7: | 391 case 7: |
| 389 // join | 392 // join |
| 390 c = __result; | 393 c = __result; |
| 391 d = foo1() || foo2(); | 394 d = foo1() || foo2(); |
| 392 __temp1 = foo1(); | 395 __temp1 = foo1(); |
| 393 if (__temp1) { | 396 if (__temp1) { |
| 394 // goto then | 397 // goto then |
| 395 __goto = 10; | 398 __goto = 10; |
| 396 break; | 399 break; |
| 397 } else | 400 } else |
| 398 __result = __temp1; | 401 __result = __temp1; |
| 399 // goto join | 402 // goto join |
| 400 __goto = 11; | 403 __goto = 11; |
| 401 break; | 404 break; |
| 402 case 10: | 405 case 10: |
| 403 // then | 406 // then |
| 404 __goto = 12; | 407 __goto = 12; |
| 405 return thenHelper(foo2(), body, __completer); | 408 return awaitHelper(foo2(), body); |
| 406 case 12: | 409 case 12: |
| 407 // returning from await. | 410 // returning from await. |
| 408 case 11: | 411 case 11: |
| 409 // join | 412 // join |
| 410 e = __result; | 413 e = __result; |
| 411 __goto = 13; | 414 __goto = 13; |
| 412 return thenHelper(foo1(), body, __completer); | 415 return awaitHelper(foo1(), body); |
| 413 case 13: | 416 case 13: |
| 414 // returning from await. | 417 // returning from await. |
| 415 f = __result && foo2(); | 418 f = __result && foo2(); |
| 416 __goto = 16; | 419 __goto = 16; |
| 417 return thenHelper(foo1(), body, __completer); | 420 return awaitHelper(foo1(), body); |
| 418 case 16: | 421 case 16: |
| 419 // returning from await. | 422 // returning from await. |
| 420 __temp1 = __result; | 423 __temp1 = __result; |
| 421 if (__temp1) { | 424 if (__temp1) { |
| 422 // goto then | 425 // goto then |
| 423 __goto = 14; | 426 __goto = 14; |
| 424 break; | 427 break; |
| 425 } else | 428 } else |
| 426 __result = __temp1; | 429 __result = __temp1; |
| 427 // goto join | 430 // goto join |
| 428 __goto = 15; | 431 __goto = 15; |
| 429 break; | 432 break; |
| 430 case 14: | 433 case 14: |
| 431 // then | 434 // then |
| 432 __goto = 17; | 435 __goto = 17; |
| 433 return thenHelper(foo2(), body, __completer); | 436 return awaitHelper(foo2(), body); |
| 434 case 17: | 437 case 17: |
| 435 // returning from await. | 438 // returning from await. |
| 436 case 15: | 439 case 15: |
| 437 // join | 440 // join |
| 438 g = __result; | 441 g = __result; |
| 439 h = foo1() && foo2(); | 442 h = foo1() && foo2(); |
| 440 // implicit return | 443 // implicit return |
| 441 return thenHelper(null, 0, __completer); | 444 return returnHelper(null, __completer); |
| 442 case 1: | 445 case 1: |
| 443 // rethrow | 446 // rethrow |
| 444 return thenHelper(__currentError, 1, __completer); | 447 return rethrowHelper(__currentError, __completer); |
| 445 } | 448 } |
| 446 }); | 449 }); |
| 447 return thenHelper(null, body, __completer); | 450 return startHelper(body, __completer); |
| 448 }"""); | 451 }"""); |
| 449 | 452 |
| 450 testAsyncTransform( | 453 testAsyncTransform( |
| 451 """ | 454 """ |
| 452 function(x, y) async { | 455 function(x, y) async { |
| 453 while (true) { | 456 while (true) { |
| 454 switch(y) { // Switch with no awaits in case key expressions | 457 switch(y) { // Switch with no awaits in case key expressions |
| 455 case 0: | 458 case 0: |
| 456 case 1: | 459 case 1: |
| 457 await foo(); | 460 await foo(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 // goto after switch | 504 // goto after switch |
| 502 __goto = 5; | 505 __goto = 5; |
| 503 break; | 506 break; |
| 504 } | 507 } |
| 505 break; | 508 break; |
| 506 case 6: | 509 case 6: |
| 507 // case | 510 // case |
| 508 case 7: | 511 case 7: |
| 509 // case | 512 // case |
| 510 __goto = 10; | 513 __goto = 10; |
| 511 return thenHelper(foo(), body, __completer); | 514 return awaitHelper(foo(), body); |
| 512 case 10: | 515 case 10: |
| 513 // returning from await. | 516 // returning from await. |
| 514 // goto while condition | 517 // goto while condition |
| 515 __goto = 2; | 518 __goto = 2; |
| 516 break; | 519 break; |
| 517 case 8: | 520 case 8: |
| 518 // case | 521 // case |
| 519 __goto = 11; | 522 __goto = 11; |
| 520 return thenHelper(foo(), body, __completer); | 523 return awaitHelper(foo(), body); |
| 521 case 11: | 524 case 11: |
| 522 // returning from await. | 525 // returning from await. |
| 523 // goto after switch | 526 // goto after switch |
| 524 __goto = 5; | 527 __goto = 5; |
| 525 break; | 528 break; |
| 526 case 9: | 529 case 9: |
| 527 // case | 530 // case |
| 528 foo(); | 531 foo(); |
| 529 case 5: | 532 case 5: |
| 530 // after switch | 533 // after switch |
| 531 // goto while condition | 534 // goto while condition |
| 532 __goto = 2; | 535 __goto = 2; |
| 533 break; | 536 break; |
| 534 case 3: | 537 case 3: |
| 535 // after while | 538 // after while |
| 536 // implicit return | 539 // implicit return |
| 537 return thenHelper(null, 0, __completer); | 540 return returnHelper(null, __completer); |
| 538 case 1: | 541 case 1: |
| 539 // rethrow | 542 // rethrow |
| 540 return thenHelper(__currentError, 1, __completer); | 543 return rethrowHelper(__currentError, __completer); |
| 541 } | 544 } |
| 542 }); | 545 }); |
| 543 return thenHelper(null, body, __completer); | 546 return startHelper(body, __completer); |
| 544 }"""); | 547 }"""); |
| 545 | 548 |
| 546 testAsyncTransform( | 549 testAsyncTransform( |
| 547 """ | 550 """ |
| 548 function(f) async { | 551 function(f) async { |
| 549 do { | 552 do { |
| 550 var a = await foo(); | 553 var a = await foo(); |
| 551 if (a) // If with no awaits in body | 554 if (a) // If with no awaits in body |
| 552 break; | 555 break; |
| 553 else | 556 else |
| 554 continue; | 557 continue; |
| 555 } while (await foo()); | 558 } while (await foo()); |
| 556 } | 559 } |
| 557 """, | 560 """, |
| 558 """ | 561 """ |
| 559 function(f) { | 562 function(f) { |
| 560 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, a
; | 563 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, a
; |
| 561 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 564 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 562 if (__errorCode === 1) { | 565 if (__errorCode === 1) { |
| 563 __currentError = __result; | 566 __currentError = __result; |
| 564 __goto = __handler; | 567 __goto = __handler; |
| 565 } | 568 } |
| 566 while (true) | 569 while (true) |
| 567 switch (__goto) { | 570 switch (__goto) { |
| 568 case 0: | 571 case 0: |
| 569 // Function start | 572 // Function start |
| 570 case 2: | 573 case 2: |
| 571 // do body | 574 // do body |
| 572 __goto = 5; | 575 __goto = 5; |
| 573 return thenHelper(foo(), body, __completer); | 576 return awaitHelper(foo(), body); |
| 574 case 5: | 577 case 5: |
| 575 // returning from await. | 578 // returning from await. |
| 576 a = __result; | 579 a = __result; |
| 577 if (a) { | 580 if (a) { |
| 578 // goto after do | 581 // goto after do |
| 579 __goto = 4; | 582 __goto = 4; |
| 580 break; | 583 break; |
| 581 } else { | 584 } else { |
| 582 // goto do condition | 585 // goto do condition |
| 583 __goto = 3; | 586 __goto = 3; |
| 584 break; | 587 break; |
| 585 } | 588 } |
| 586 case 3: | 589 case 3: |
| 587 // do condition | 590 // do condition |
| 588 __goto = 6; | 591 __goto = 6; |
| 589 return thenHelper(foo(), body, __completer); | 592 return awaitHelper(foo(), body); |
| 590 case 6: | 593 case 6: |
| 591 // returning from await. | 594 // returning from await. |
| 592 if (__result) { | 595 if (__result) { |
| 593 // goto do body | 596 // goto do body |
| 594 __goto = 2; | 597 __goto = 2; |
| 595 break; | 598 break; |
| 596 } | 599 } |
| 597 case 4: | 600 case 4: |
| 598 // after do | 601 // after do |
| 599 // implicit return | 602 // implicit return |
| 600 return thenHelper(null, 0, __completer); | 603 return returnHelper(null, __completer); |
| 601 case 1: | 604 case 1: |
| 602 // rethrow | 605 // rethrow |
| 603 return thenHelper(__currentError, 1, __completer); | 606 return rethrowHelper(__currentError, __completer); |
| 604 } | 607 } |
| 605 }); | 608 }); |
| 606 return thenHelper(null, body, __completer); | 609 return startHelper(body, __completer); |
| 607 }"""); | 610 }"""); |
| 608 | 611 |
| 609 testAsyncTransform( | 612 testAsyncTransform( |
| 610 """ | 613 """ |
| 611 function(g) async { | 614 function(g) async { |
| 612 for (var i = 0; i < await foo1(); i += await foo2()) { | 615 for (var i = 0; i < await foo1(); i += await foo2()) { |
| 613 if (foo(i)) | 616 if (foo(i)) |
| 614 continue; | 617 continue; |
| 615 else | 618 else |
| 616 break; | 619 break; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 632 } | 635 } |
| 633 while (true) | 636 while (true) |
| 634 switch (__goto) { | 637 switch (__goto) { |
| 635 case 0: | 638 case 0: |
| 636 // Function start | 639 // Function start |
| 637 i = 0; | 640 i = 0; |
| 638 case 3: | 641 case 3: |
| 639 // for condition | 642 // for condition |
| 640 __temp1 = i; | 643 __temp1 = i; |
| 641 __goto = 6; | 644 __goto = 6; |
| 642 return thenHelper(foo1(), body, __completer); | 645 return awaitHelper(foo1(), body); |
| 643 case 6: | 646 case 6: |
| 644 // returning from await. | 647 // returning from await. |
| 645 if (!(__temp1 < __result)) { | 648 if (!(__temp1 < __result)) { |
| 646 // goto after for | 649 // goto after for |
| 647 __goto = 5; | 650 __goto = 5; |
| 648 break; | 651 break; |
| 649 } | 652 } |
| 650 if (foo(i)) { | 653 if (foo(i)) { |
| 651 // goto for update | 654 // goto for update |
| 652 __goto = 4; | 655 __goto = 4; |
| 653 break; | 656 break; |
| 654 } else { | 657 } else { |
| 655 // goto after for | 658 // goto after for |
| 656 __goto = 5; | 659 __goto = 5; |
| 657 break; | 660 break; |
| 658 } | 661 } |
| 659 __goto = !foo(i) ? 7 : 8; | 662 __goto = !foo(i) ? 7 : 8; |
| 660 break; | 663 break; |
| 661 case 7: | 664 case 7: |
| 662 // then | 665 // then |
| 663 __goto = 9; | 666 __goto = 9; |
| 664 return thenHelper(foo(), body, __completer); | 667 return awaitHelper(foo(), body); |
| 665 case 9: | 668 case 9: |
| 666 // returning from await. | 669 // returning from await. |
| 667 // goto return | 670 // goto return |
| 668 __goto = 1; | 671 __goto = 1; |
| 669 break; | 672 break; |
| 670 case 8: | 673 case 8: |
| 671 // join | 674 // join |
| 672 __temp1 = print; | 675 __temp1 = print; |
| 673 __goto = 10; | 676 __goto = 10; |
| 674 return thenHelper(foo(i), body, __completer); | 677 return awaitHelper(foo(i), body); |
| 675 case 10: | 678 case 10: |
| 676 // returning from await. | 679 // returning from await. |
| 677 __temp1(__result); | 680 __temp1(__result); |
| 678 case 4: | 681 case 4: |
| 679 // for update | 682 // for update |
| 680 __goto = 11; | 683 __goto = 11; |
| 681 return thenHelper(foo2(), body, __completer); | 684 return awaitHelper(foo2(), body); |
| 682 case 11: | 685 case 11: |
| 683 // returning from await. | 686 // returning from await. |
| 684 i += __result; | 687 i += __result; |
| 685 // goto for condition | 688 // goto for condition |
| 686 __goto = 3; | 689 __goto = 3; |
| 687 break; | 690 break; |
| 688 case 5: | 691 case 5: |
| 689 // after for | 692 // after for |
| 690 case 1: | 693 case 1: |
| 691 // return | 694 // return |
| 692 return thenHelper(__returnValue, 0, __completer); | 695 return returnHelper(__returnValue, __completer); |
| 693 case 2: | 696 case 2: |
| 694 // rethrow | 697 // rethrow |
| 695 return thenHelper(__currentError, 1, __completer); | 698 return rethrowHelper(__currentError, __completer); |
| 696 } | 699 } |
| 697 }); | 700 }); |
| 698 return thenHelper(null, body, __completer); | 701 return startHelper(body, __completer); |
| 699 }"""); | 702 }"""); |
| 700 | 703 |
| 701 testAsyncTransform( | 704 testAsyncTransform( |
| 702 """ | 705 """ |
| 703 function(a, h) async { | 706 function(a, h) async { |
| 704 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; | 707 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; |
| 705 x["a"] = 2; // Different assignments | 708 x["a"] = 2; // Different assignments |
| 706 (await foo()).a = 3; | 709 (await foo()).a = 3; |
| 707 x[await foo()] = 4; | 710 x[await foo()] = 4; |
| 708 x[(await foo1()).a = await foo2()] = 5; | 711 x[(await foo1()).a = await foo2()] = 5; |
| 709 (await foo1())[await foo2()] = await foo3(6); | 712 (await foo1())[await foo2()] = await foo3(6); |
| 710 } | 713 } |
| 711 """, | 714 """, |
| 712 """ | 715 """ |
| 713 function(a, h) { | 716 function(a, h) { |
| 714 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, x
, __temp1, __temp2; | 717 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, x
, __temp1, __temp2; |
| 715 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 718 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 716 if (__errorCode === 1) { | 719 if (__errorCode === 1) { |
| 717 __currentError = __result; | 720 __currentError = __result; |
| 718 __goto = __handler; | 721 __goto = __handler; |
| 719 } | 722 } |
| 720 while (true) | 723 while (true) |
| 721 switch (__goto) { | 724 switch (__goto) { |
| 722 case 0: | 725 case 0: |
| 723 // Function start | 726 // Function start |
| 724 __temp1 = foo1(); | 727 __temp1 = foo1(); |
| 725 __goto = 2; | 728 __goto = 2; |
| 726 return thenHelper(foo2(), body, __completer); | 729 return awaitHelper(foo2(), body); |
| 727 case 2: | 730 case 2: |
| 728 // returning from await. | 731 // returning from await. |
| 729 x = {a: __temp1, b: __result, c: foo3()}; | 732 x = {a: __temp1, b: __result, c: foo3()}; |
| 730 x.a = 2; | 733 x.a = 2; |
| 731 __goto = 3; | 734 __goto = 3; |
| 732 return thenHelper(foo(), body, __completer); | 735 return awaitHelper(foo(), body); |
| 733 case 3: | 736 case 3: |
| 734 // returning from await. | 737 // returning from await. |
| 735 __result.a = 3; | 738 __result.a = 3; |
| 736 __temp1 = x; | 739 __temp1 = x; |
| 737 __goto = 4; | 740 __goto = 4; |
| 738 return thenHelper(foo(), body, __completer); | 741 return awaitHelper(foo(), body); |
| 739 case 4: | 742 case 4: |
| 740 // returning from await. | 743 // returning from await. |
| 741 __temp1[__result] = 4; | 744 __temp1[__result] = 4; |
| 742 __temp1 = x; | 745 __temp1 = x; |
| 743 __goto = 5; | 746 __goto = 5; |
| 744 return thenHelper(foo1(), body, __completer); | 747 return awaitHelper(foo1(), body); |
| 745 case 5: | 748 case 5: |
| 746 // returning from await. | 749 // returning from await. |
| 747 __temp2 = __result; | 750 __temp2 = __result; |
| 748 __goto = 6; | 751 __goto = 6; |
| 749 return thenHelper(foo2(), body, __completer); | 752 return awaitHelper(foo2(), body); |
| 750 case 6: | 753 case 6: |
| 751 // returning from await. | 754 // returning from await. |
| 752 __temp1[__temp2.a = __result] = 5; | 755 __temp1[__temp2.a = __result] = 5; |
| 753 __goto = 7; | 756 __goto = 7; |
| 754 return thenHelper(foo1(), body, __completer); | 757 return awaitHelper(foo1(), body); |
| 755 case 7: | 758 case 7: |
| 756 // returning from await. | 759 // returning from await. |
| 757 __temp1 = __result; | 760 __temp1 = __result; |
| 758 __goto = 8; | 761 __goto = 8; |
| 759 return thenHelper(foo2(), body, __completer); | 762 return awaitHelper(foo2(), body); |
| 760 case 8: | 763 case 8: |
| 761 // returning from await. | 764 // returning from await. |
| 762 __temp2 = __result; | 765 __temp2 = __result; |
| 763 __goto = 9; | 766 __goto = 9; |
| 764 return thenHelper(foo3(6), body, __completer); | 767 return awaitHelper(foo3(6), body); |
| 765 case 9: | 768 case 9: |
| 766 // returning from await. | 769 // returning from await. |
| 767 __temp1[__temp2] = __result; | 770 __temp1[__temp2] = __result; |
| 768 // implicit return | 771 // implicit return |
| 769 return thenHelper(null, 0, __completer); | 772 return returnHelper(null, __completer); |
| 770 case 1: | 773 case 1: |
| 771 // rethrow | 774 // rethrow |
| 772 return thenHelper(__currentError, 1, __completer); | 775 return rethrowHelper(__currentError, __completer); |
| 773 } | 776 } |
| 774 }); | 777 }); |
| 775 return thenHelper(null, body, __completer); | 778 return startHelper(body, __completer); |
| 776 }"""); | 779 }"""); |
| 777 | 780 |
| 778 testAsyncTransform( | 781 testAsyncTransform( |
| 779 """ | 782 """ |
| 780 function(c, i) async { | 783 function(c, i) async { |
| 781 try { | 784 try { |
| 782 var x = c ? await foo() : foo(); // conditional | 785 var x = c ? await foo() : foo(); // conditional |
| 783 var y = {}; | 786 var y = {}; |
| 784 } catch (error) { | 787 } catch (error) { |
| 785 try { | 788 try { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 803 while (true) | 806 while (true) |
| 804 switch (__goto) { | 807 switch (__goto) { |
| 805 case 0: | 808 case 0: |
| 806 // Function start | 809 // Function start |
| 807 __handler = 3; | 810 __handler = 3; |
| 808 __goto = c ? 6 : 8; | 811 __goto = c ? 6 : 8; |
| 809 break; | 812 break; |
| 810 case 6: | 813 case 6: |
| 811 // then | 814 // then |
| 812 __goto = 9; | 815 __goto = 9; |
| 813 return thenHelper(foo(), body, __completer); | 816 return awaitHelper(foo(), body); |
| 814 case 9: | 817 case 9: |
| 815 // returning from await. | 818 // returning from await. |
| 816 // goto join | 819 // goto join |
| 817 __goto = 7; | 820 __goto = 7; |
| 818 break; | 821 break; |
| 819 case 8: | 822 case 8: |
| 820 // else | 823 // else |
| 821 __result = foo(); | 824 __result = foo(); |
| 822 case 7: | 825 case 7: |
| 823 // join | 826 // join |
| 824 x = __result; | 827 x = __result; |
| 825 y = {}; | 828 y = {}; |
| 826 __handler = 1; | 829 __handler = 1; |
| 827 // goto after finally | 830 // goto after finally |
| 828 __goto = 5; | 831 __goto = 5; |
| 829 break; | 832 break; |
| 830 case 3: | 833 case 3: |
| 831 // catch | 834 // catch |
| 832 __handler = 2; | 835 __handler = 2; |
| 833 __error = __currentError; | 836 __error = __currentError; |
| 834 __handler = 11; | 837 __handler = 11; |
| 835 __goto = c ? 14 : 16; | 838 __goto = c ? 14 : 16; |
| 836 break; | 839 break; |
| 837 case 14: | 840 case 14: |
| 838 // then | 841 // then |
| 839 __goto = 17; | 842 __goto = 17; |
| 840 return thenHelper(fooError(__error), body, __completer); | 843 return awaitHelper(fooError(__error), body); |
| 841 case 17: | 844 case 17: |
| 842 // returning from await. | 845 // returning from await. |
| 843 // goto join | 846 // goto join |
| 844 __goto = 15; | 847 __goto = 15; |
| 845 break; | 848 break; |
| 846 case 16: | 849 case 16: |
| 847 // else | 850 // else |
| 848 __result = fooError(__error); | 851 __result = fooError(__error); |
| 849 case 15: | 852 case 15: |
| 850 // join | 853 // join |
| (...skipping 27 matching lines...) Expand all Loading... |
| 878 __goto = 5; | 881 __goto = 5; |
| 879 break; | 882 break; |
| 880 case 2: | 883 case 2: |
| 881 // uncaught | 884 // uncaught |
| 882 // goto rethrow | 885 // goto rethrow |
| 883 __goto = 1; | 886 __goto = 1; |
| 884 break; | 887 break; |
| 885 case 5: | 888 case 5: |
| 886 // after finally | 889 // after finally |
| 887 // implicit return | 890 // implicit return |
| 888 return thenHelper(null, 0, __completer); | 891 return returnHelper(null, __completer); |
| 889 case 1: | 892 case 1: |
| 890 // rethrow | 893 // rethrow |
| 891 return thenHelper(__currentError, 1, __completer); | 894 return rethrowHelper(__currentError, __completer); |
| 892 } | 895 } |
| 893 }); | 896 }); |
| 894 return thenHelper(null, body, __completer); | 897 return startHelper(body, __completer); |
| 895 }"""); | 898 }"""); |
| 896 | 899 |
| 897 testAsyncTransform( | 900 testAsyncTransform( |
| 898 """ | 901 """ |
| 899 function(x, y, j) async { | 902 function(x, y, j) async { |
| 900 print(await(foo(x))); // calls | 903 print(await(foo(x))); // calls |
| 901 (await print)(foo(x)); | 904 (await print)(foo(x)); |
| 902 print(foo(await x)); | 905 print(foo(await x)); |
| 903 await (print(foo(await x))); | 906 await (print(foo(await x))); |
| 904 print(foo(x, await y, z)); | 907 print(foo(x, await y, z)); |
| 905 } | 908 } |
| 906 """, | 909 """, |
| 907 """ | 910 """ |
| 908 function(x, y, j) { | 911 function(x, y, j) { |
| 909 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
_temp1, __temp2, __temp3; | 912 var __goto = 0, __completer = NewCompleter(), __handler = 1, __currentError, _
_temp1, __temp2, __temp3; |
| 910 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 913 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 911 if (__errorCode === 1) { | 914 if (__errorCode === 1) { |
| 912 __currentError = __result; | 915 __currentError = __result; |
| 913 __goto = __handler; | 916 __goto = __handler; |
| 914 } | 917 } |
| 915 while (true) | 918 while (true) |
| 916 switch (__goto) { | 919 switch (__goto) { |
| 917 case 0: | 920 case 0: |
| 918 // Function start | 921 // Function start |
| 919 __temp1 = print; | 922 __temp1 = print; |
| 920 __goto = 2; | 923 __goto = 2; |
| 921 return thenHelper(foo(x), body, __completer); | 924 return awaitHelper(foo(x), body); |
| 922 case 2: | 925 case 2: |
| 923 // returning from await. | 926 // returning from await. |
| 924 __temp1(__result); | 927 __temp1(__result); |
| 925 __goto = 3; | 928 __goto = 3; |
| 926 return thenHelper(print, body, __completer); | 929 return awaitHelper(print, body); |
| 927 case 3: | 930 case 3: |
| 928 // returning from await. | 931 // returning from await. |
| 929 __result(foo(x)); | 932 __result(foo(x)); |
| 930 __temp1 = print; | 933 __temp1 = print; |
| 931 __temp2 = foo; | 934 __temp2 = foo; |
| 932 __goto = 4; | 935 __goto = 4; |
| 933 return thenHelper(x, body, __completer); | 936 return awaitHelper(x, body); |
| 934 case 4: | 937 case 4: |
| 935 // returning from await. | 938 // returning from await. |
| 936 __temp1(__temp2(__result)); | 939 __temp1(__temp2(__result)); |
| 937 __temp1 = print; | 940 __temp1 = print; |
| 938 __temp2 = foo; | 941 __temp2 = foo; |
| 939 __goto = 6; | 942 __goto = 6; |
| 940 return thenHelper(x, body, __completer); | 943 return awaitHelper(x, body); |
| 941 case 6: | 944 case 6: |
| 942 // returning from await. | 945 // returning from await. |
| 943 __goto = 5; | 946 __goto = 5; |
| 944 return thenHelper(__temp1(__temp2(__result)), body, __completer); | 947 return awaitHelper(__temp1(__temp2(__result)), body); |
| 945 case 5: | 948 case 5: |
| 946 // returning from await. | 949 // returning from await. |
| 947 __temp1 = print; | 950 __temp1 = print; |
| 948 __temp2 = foo; | 951 __temp2 = foo; |
| 949 __temp3 = x; | 952 __temp3 = x; |
| 950 __goto = 7; | 953 __goto = 7; |
| 951 return thenHelper(y, body, __completer); | 954 return awaitHelper(y, body); |
| 952 case 7: | 955 case 7: |
| 953 // returning from await. | 956 // returning from await. |
| 954 __temp1(__temp2(__temp3, __result, z)); | 957 __temp1(__temp2(__temp3, __result, z)); |
| 955 // implicit return | 958 // implicit return |
| 956 return thenHelper(null, 0, __completer); | 959 return returnHelper(null, __completer); |
| 957 case 1: | 960 case 1: |
| 958 // rethrow | 961 // rethrow |
| 959 return thenHelper(__currentError, 1, __completer); | 962 return rethrowHelper(__currentError, __completer); |
| 960 } | 963 } |
| 961 }); | 964 }); |
| 962 return thenHelper(null, body, __completer); | 965 return startHelper(body, __completer); |
| 963 }"""); | 966 }"""); |
| 964 | 967 |
| 965 testAsyncTransform( | 968 testAsyncTransform( |
| 966 """ | 969 """ |
| 967 function(x, y, k) async { | 970 function(x, y, k) async { |
| 968 while (await(foo())) { | 971 while (await(foo())) { |
| 969 lab: { // labelled statement | 972 lab: { // labelled statement |
| 970 switch(y) { | 973 switch(y) { |
| 971 case 0: | 974 case 0: |
| 972 foo(); | 975 foo(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 997 __currentError = __result; | 1000 __currentError = __result; |
| 998 __goto = __handler; | 1001 __goto = __handler; |
| 999 } | 1002 } |
| 1000 while (true) | 1003 while (true) |
| 1001 switch (__goto) { | 1004 switch (__goto) { |
| 1002 case 0: | 1005 case 0: |
| 1003 // Function start | 1006 // Function start |
| 1004 case 3: | 1007 case 3: |
| 1005 // while condition | 1008 // while condition |
| 1006 __goto = 5; | 1009 __goto = 5; |
| 1007 return thenHelper(foo(), body, __completer); | 1010 return awaitHelper(foo(), body); |
| 1008 case 5: | 1011 case 5: |
| 1009 // returning from await. | 1012 // returning from await. |
| 1010 if (!__result) { | 1013 if (!__result) { |
| 1011 // goto after while | 1014 // goto after while |
| 1012 __goto = 4; | 1015 __goto = 4; |
| 1013 break; | 1016 break; |
| 1014 } | 1017 } |
| 1015 case 7: | 1018 case 7: |
| 1016 // switch | 1019 // switch |
| 1017 __temp1 = y; | 1020 __temp1 = y; |
| 1018 if (__temp1 === 0) { | 1021 if (__temp1 === 0) { |
| 1019 // goto case | 1022 // goto case |
| 1020 __goto = 9; | 1023 __goto = 9; |
| 1021 break; | 1024 break; |
| 1022 } | 1025 } |
| 1023 if (__temp1 === 0) { | 1026 if (__temp1 === 0) { |
| 1024 // goto case | 1027 // goto case |
| 1025 __goto = 10; | 1028 __goto = 10; |
| 1026 break; | 1029 break; |
| 1027 } | 1030 } |
| 1028 __goto = 12; | 1031 __goto = 12; |
| 1029 return thenHelper(bar(), body, __completer); | 1032 return awaitHelper(bar(), body); |
| 1030 case 12: | 1033 case 12: |
| 1031 // returning from await. | 1034 // returning from await. |
| 1032 if (__temp1 === __result) { | 1035 if (__temp1 === __result) { |
| 1033 // goto case | 1036 // goto case |
| 1034 __goto = 11; | 1037 __goto = 11; |
| 1035 break; | 1038 break; |
| 1036 } | 1039 } |
| 1037 if (__temp1 === x) { | 1040 if (__temp1 === x) { |
| 1038 // goto case | 1041 // goto case |
| 1039 __goto = 13; | 1042 __goto = 13; |
| 1040 break; | 1043 break; |
| 1041 } | 1044 } |
| 1042 // goto default | 1045 // goto default |
| 1043 __goto = 14; | 1046 __goto = 14; |
| 1044 break; | 1047 break; |
| 1045 case 9: | 1048 case 9: |
| 1046 // case | 1049 // case |
| 1047 foo(); | 1050 foo(); |
| 1048 case 10: | 1051 case 10: |
| 1049 // case | 1052 // case |
| 1050 __temp1 = print; | 1053 __temp1 = print; |
| 1051 __goto = 15; | 1054 __goto = 15; |
| 1052 return thenHelper(foo1(x), body, __completer); | 1055 return awaitHelper(foo1(x), body); |
| 1053 case 15: | 1056 case 15: |
| 1054 // returning from await. | 1057 // returning from await. |
| 1055 __temp1(__result); | 1058 __temp1(__result); |
| 1056 __returnValue = y; | 1059 __returnValue = y; |
| 1057 // goto return | 1060 // goto return |
| 1058 __goto = 1; | 1061 __goto = 1; |
| 1059 break; | 1062 break; |
| 1060 case 11: | 1063 case 11: |
| 1061 // case | 1064 // case |
| 1062 __temp1 = print; | 1065 __temp1 = print; |
| 1063 __goto = 16; | 1066 __goto = 16; |
| 1064 return thenHelper(foobar(x), body, __completer); | 1067 return awaitHelper(foobar(x), body); |
| 1065 case 16: | 1068 case 16: |
| 1066 // returning from await. | 1069 // returning from await. |
| 1067 __temp1(__result); | 1070 __temp1(__result); |
| 1068 __returnValue = y; | 1071 __returnValue = y; |
| 1069 // goto return | 1072 // goto return |
| 1070 __goto = 1; | 1073 __goto = 1; |
| 1071 break; | 1074 break; |
| 1072 case 13: | 1075 case 13: |
| 1073 // case | 1076 // case |
| 1074 if (a) | 1077 if (a) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1088 foo(); | 1091 foo(); |
| 1089 case 6: | 1092 case 6: |
| 1090 // break lab | 1093 // break lab |
| 1091 // goto while condition | 1094 // goto while condition |
| 1092 __goto = 3; | 1095 __goto = 3; |
| 1093 break; | 1096 break; |
| 1094 case 4: | 1097 case 4: |
| 1095 // after while | 1098 // after while |
| 1096 case 1: | 1099 case 1: |
| 1097 // return | 1100 // return |
| 1098 return thenHelper(__returnValue, 0, __completer); | 1101 return returnHelper(__returnValue, __completer); |
| 1099 case 2: | 1102 case 2: |
| 1100 // rethrow | 1103 // rethrow |
| 1101 return thenHelper(__currentError, 1, __completer); | 1104 return rethrowHelper(__currentError, __completer); |
| 1102 } | 1105 } |
| 1103 }); | 1106 }); |
| 1104 return thenHelper(null, body, __completer); | 1107 return startHelper(body, __completer); |
| 1105 }"""); | 1108 }"""); |
| 1106 | 1109 |
| 1107 testAsyncTransform( | 1110 testAsyncTransform( |
| 1108 """ | 1111 """ |
| 1109 function(l) async { | 1112 function(l) async { |
| 1110 switch(await l) { | 1113 switch(await l) { |
| 1111 case 1: | 1114 case 1: |
| 1112 print(1); | 1115 print(1); |
| 1113 break; | 1116 break; |
| 1114 case 2: | 1117 case 2: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1125 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { | 1128 var body = _wrapJsFunctionForAsync(function(__errorCode, __result) { |
| 1126 if (__errorCode === 1) { | 1129 if (__errorCode === 1) { |
| 1127 __currentError = __result; | 1130 __currentError = __result; |
| 1128 __goto = __handler; | 1131 __goto = __handler; |
| 1129 } | 1132 } |
| 1130 while (true) | 1133 while (true) |
| 1131 switch (__goto) { | 1134 switch (__goto) { |
| 1132 case 0: | 1135 case 0: |
| 1133 // Function start | 1136 // Function start |
| 1134 __goto = 2; | 1137 __goto = 2; |
| 1135 return thenHelper(l, body, __completer); | 1138 return awaitHelper(l, body); |
| 1136 case 2: | 1139 case 2: |
| 1137 // returning from await. | 1140 // returning from await. |
| 1138 switch (__result) { | 1141 switch (__result) { |
| 1139 case 1: | 1142 case 1: |
| 1140 print(1); | 1143 print(1); |
| 1141 break; | 1144 break; |
| 1142 case 2: | 1145 case 2: |
| 1143 print(1); | 1146 print(1); |
| 1144 default: | 1147 default: |
| 1145 print(2); | 1148 print(2); |
| 1146 break; | 1149 break; |
| 1147 } | 1150 } |
| 1148 // implicit return | 1151 // implicit return |
| 1149 return thenHelper(null, 0, __completer); | 1152 return returnHelper(null, __completer); |
| 1150 case 1: | 1153 case 1: |
| 1151 // rethrow | 1154 // rethrow |
| 1152 return thenHelper(__currentError, 1, __completer); | 1155 return rethrowHelper(__currentError, __completer); |
| 1153 } | 1156 } |
| 1154 }); | 1157 }); |
| 1155 return thenHelper(null, body, __completer); | 1158 return startHelper(body, __completer); |
| 1156 }"""); | 1159 }"""); |
| 1157 | 1160 |
| 1158 testAsyncTransform( | 1161 testAsyncTransform( |
| 1159 """ | 1162 """ |
| 1160 function(m) async { | 1163 function(m) async { |
| 1161 var exception = 1; | 1164 var exception = 1; |
| 1162 try { | 1165 try { |
| 1163 await 42; | 1166 await 42; |
| 1164 throw 42; | 1167 throw 42; |
| 1165 } catch (exception) { | 1168 } catch (exception) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1181 __currentError = __result; | 1184 __currentError = __result; |
| 1182 __goto = __handler; | 1185 __goto = __handler; |
| 1183 } | 1186 } |
| 1184 while (true) | 1187 while (true) |
| 1185 switch (__goto) { | 1188 switch (__goto) { |
| 1186 case 0: | 1189 case 0: |
| 1187 // Function start | 1190 // Function start |
| 1188 exception = 1; | 1191 exception = 1; |
| 1189 __handler = 3; | 1192 __handler = 3; |
| 1190 __goto = 6; | 1193 __goto = 6; |
| 1191 return thenHelper(42, body, __completer); | 1194 return awaitHelper(42, body); |
| 1192 case 6: | 1195 case 6: |
| 1193 // returning from await. | 1196 // returning from await. |
| 1194 throw 42; | 1197 throw 42; |
| 1195 __handler = 1; | 1198 __handler = 1; |
| 1196 // goto after finally | 1199 // goto after finally |
| 1197 __goto = 5; | 1200 __goto = 5; |
| 1198 break; | 1201 break; |
| 1199 case 3: | 1202 case 3: |
| 1200 // catch | 1203 // catch |
| 1201 __handler = 2; | 1204 __handler = 2; |
| 1202 __exception = __currentError; | 1205 __exception = __currentError; |
| 1203 __goto = 7; | 1206 __goto = 7; |
| 1204 return thenHelper(10, body, __completer); | 1207 return awaitHelper(10, body); |
| 1205 case 7: | 1208 case 7: |
| 1206 // returning from await. | 1209 // returning from await. |
| 1207 __exception = __result; | 1210 __exception = __result; |
| 1208 __goto = 8; | 1211 __goto = 8; |
| 1209 return thenHelper(10, body, __completer); | 1212 return awaitHelper(10, body); |
| 1210 case 8: | 1213 case 8: |
| 1211 // returning from await. | 1214 // returning from await. |
| 1212 __exception += __result; | 1215 __exception += __result; |
| 1213 __exception++; | 1216 __exception++; |
| 1214 __exception--; | 1217 __exception--; |
| 1215 ++__exception; | 1218 ++__exception; |
| 1216 --__exception; | 1219 --__exception; |
| 1217 __exception += 10; | 1220 __exception += 10; |
| 1218 // goto after finally | 1221 // goto after finally |
| 1219 __goto = 5; | 1222 __goto = 5; |
| 1220 break; | 1223 break; |
| 1221 case 2: | 1224 case 2: |
| 1222 // uncaught | 1225 // uncaught |
| 1223 // goto rethrow | 1226 // goto rethrow |
| 1224 __goto = 1; | 1227 __goto = 1; |
| 1225 break; | 1228 break; |
| 1226 case 5: | 1229 case 5: |
| 1227 // after finally | 1230 // after finally |
| 1228 print(exception); | 1231 print(exception); |
| 1229 // implicit return | 1232 // implicit return |
| 1230 return thenHelper(null, 0, __completer); | 1233 return returnHelper(null, __completer); |
| 1231 case 1: | 1234 case 1: |
| 1232 // rethrow | 1235 // rethrow |
| 1233 return thenHelper(__currentError, 1, __completer); | 1236 return rethrowHelper(__currentError, __completer); |
| 1234 } | 1237 } |
| 1235 }); | 1238 }); |
| 1236 return thenHelper(null, body, __completer); | 1239 return startHelper(body, __completer); |
| 1237 }"""); | 1240 }"""); |
| 1238 | 1241 |
| 1239 testSyncStarTransform( | 1242 testSyncStarTransform( |
| 1240 """ | 1243 """ |
| 1241 function(a) sync* { | 1244 function(a) sync* { |
| 1242 // Ensure that return of a value is treated as first evaluating the value, and | 1245 // Ensure that return of a value is treated as first evaluating the value, and |
| 1243 // then returning. | 1246 // then returning. |
| 1244 return foo(); | 1247 return foo(); |
| 1245 }""", | 1248 }""", |
| 1246 """ | 1249 """ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1265 // return | 1268 // return |
| 1266 return endOfIteration(); | 1269 return endOfIteration(); |
| 1267 case 2: | 1270 case 2: |
| 1268 // rethrow | 1271 // rethrow |
| 1269 return uncaughtError(__currentError); | 1272 return uncaughtError(__currentError); |
| 1270 } | 1273 } |
| 1271 }; | 1274 }; |
| 1272 }); | 1275 }); |
| 1273 }"""); | 1276 }"""); |
| 1274 } | 1277 } |
| OLD | NEW |