| Index: tests/compiler/dart2js/async_await_js_transform_test.dart
|
| ===================================================================
|
| --- tests/compiler/dart2js/async_await_js_transform_test.dart (revision 43839)
|
| +++ tests/compiler/dart2js/async_await_js_transform_test.dart (working copy)
|
| @@ -13,14 +13,15 @@
|
| Fun rewritten = new AsyncRewriter(
|
| null, // The diagnostic helper should not be used in these tests.
|
| null,
|
| - thenHelper: new VariableUse("thenHelper"),
|
| + asyncHelper: new VariableUse("thenHelper"),
|
| newCompleter: new VariableUse("Completer"),
|
| endOfIteration: new VariableUse("endOfIteration"),
|
| newIterable: new VariableUse("Iterator"),
|
| safeVariableName: (String name) => "__$name").rewrite(fun);
|
| -
|
| +
|
| JavaScriptPrintingOptions options = new JavaScriptPrintingOptions();
|
| - JavaScriptPrintingContext context = new SimpleJavaScriptPrintingContext();
|
| + SimpleJavaScriptPrintingContext context =
|
| + new SimpleJavaScriptPrintingContext();
|
| Printer printer = new Printer(options, context);
|
| printer.visit(rewritten);
|
| Expect.stringEquals(expected, context.getText());
|
| @@ -28,31 +29,44 @@
|
|
|
| main() {
|
| testTransform("""
|
| -function() async {
|
| +function(a) async {
|
| print(this.x); // Ensure `this` is translated in the helper function.
|
| await foo();
|
| }""", """
|
| -function() {
|
| - var __goto = 0, __completer = new Completer(), __self = this;
|
| - function __helper(__result) {
|
| +function(a) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, __self = this;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - print(__self.x);
|
| - __goto = 1;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 1:
|
| - // returning from await.
|
| - // implicit return
|
| - return thenHelper(null, null, __completer, null);
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + print(__self.x);
|
| + __goto = 2;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 2:
|
| + // returning from await.
|
| + // implicit return
|
| + return thenHelper(null, 0, __completer, null);
|
| + case 1:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
|
|
| testTransform("""
|
| -function() async {
|
| +function(b) async {
|
| try {
|
| __outer: while (true) { // Overlapping label name.
|
| try {
|
| @@ -75,9 +89,13 @@
|
| }
|
| return 4;
|
| }""", """
|
| -function() {
|
| - var __goto = 0, __completer = new Completer(), __handler = null, __next, __returnValue, __helper;
|
| - function __helper1(__result) {
|
| +function(b) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 2, __currentError, __next, __returnValue, __helper;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| try {
|
| __outer1:
|
| @@ -84,78 +102,73 @@
|
| switch (__goto) {
|
| case 0:
|
| // Function start
|
| - __handler = 2;
|
| - case 6:
|
| + __handler = 3;
|
| + case 7:
|
| // continue __outer
|
| - case 7:
|
| + case 8:
|
| // while condition
|
| - __handler = 9;
|
| + __handler = 10;
|
| inner: {
|
| while (true) {
|
| - __next = [5];
|
| + __next = [6];
|
| // goto finally
|
| - __goto = 10;
|
| + __goto = 11;
|
| break __outer1;
|
| break;
|
| }
|
| }
|
| while (true) {
|
| - __next = [1, 3];
|
| + __next = [1, 4];
|
| // goto finally
|
| - __goto = 10;
|
| + __goto = 11;
|
| break __outer1;
|
| }
|
| - __goto = 12;
|
| - return thenHelper(foo(), __helper1, __completer, function(__error) {
|
| - __goto = 9;
|
| - __helper1(__error);
|
| - });
|
| - case 12:
|
| + __goto = 13;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 13:
|
| // returning from await.
|
| __helper = __result;
|
| - __next = [11];
|
| + __next = [12];
|
| // goto finally
|
| - __goto = 10;
|
| + __goto = 11;
|
| break;
|
| - case 9:
|
| - // catch
|
| - __handler = 2;
|
| - __next = [11];
|
| case 10:
|
| + // uncaught
|
| + __next = [3];
|
| + case 11:
|
| // finally
|
| - __handler = 2;
|
| + __handler = 3;
|
| foo();
|
| // goto while condition
|
| - __goto = 7;
|
| + __goto = 8;
|
| break;
|
| __returnValue = 2;
|
| __next = [1];
|
| // goto finally
|
| - __goto = 3;
|
| + __goto = 4;
|
| break;
|
| // goto the next finally handler
|
| __goto = __next.pop();
|
| break;
|
| - case 11:
|
| + case 12:
|
| // after finally
|
| // goto while condition
|
| - __goto = 7;
|
| + __goto = 8;
|
| break;
|
| - case 8:
|
| + case 9:
|
| // after while
|
| - case 5:
|
| + case 6:
|
| // break __outer
|
| - __next = [4];
|
| + __next = [5];
|
| // goto finally
|
| - __goto = 3;
|
| + __goto = 4;
|
| break;
|
| - case 2:
|
| - // catch
|
| - __handler = null;
|
| - __next = [4];
|
| case 3:
|
| + // uncaught
|
| + __next = [2];
|
| + case 4:
|
| // finally
|
| - __handler = null;
|
| + __handler = 2;
|
| __returnValue = 3;
|
| // goto return
|
| __goto = 1;
|
| @@ -163,7 +176,7 @@
|
| // goto the next finally handler
|
| __goto = __next.pop();
|
| break;
|
| - case 4:
|
| + case 5:
|
| // after finally
|
| __returnValue = 4;
|
| // goto return
|
| @@ -171,20 +184,22 @@
|
| break;
|
| case 1:
|
| // return
|
| - return thenHelper(__returnValue, null, __completer, null);
|
| + return thenHelper(__returnValue, 0, __completer, null);
|
| + case 2:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| }
|
| } catch (__error) {
|
| - if (__handler === null)
|
| - throw __error;
|
| - __result = __error;
|
| + __currentError = __error;
|
| __goto = __handler;
|
| }
|
|
|
| }
|
| - return thenHelper(null, __helper1, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
| +
|
| testTransform("""
|
| -function() async {
|
| +function(c) async {
|
| var a, b, c, d, e, f;
|
| a = b++; // post- and preincrements.
|
| b = --b;
|
| @@ -193,45 +208,59 @@
|
| e = foo1()[await foo2()]--;
|
| f = --foo1()[await foo2()];
|
| }""", """
|
| -function() {
|
| - var __goto = 0, __completer = new Completer(), a, b, c, d, e, f, __temp1;
|
| - function __helper(__result) {
|
| +function(c) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, a, b, c, d, e, f, __temp1;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - a = b++;
|
| - b = --b;
|
| - __goto = 1;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 1:
|
| - // returning from await.
|
| - c = __result.a++;
|
| - __goto = 2;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 2:
|
| - // returning from await.
|
| - d = ++__result.a;
|
| - __temp1 = foo1();
|
| - __goto = 3;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 3:
|
| - // returning from await.
|
| - e = __temp1[__result]--;
|
| - __temp1 = foo1();
|
| - __goto = 4;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 4:
|
| - // returning from await.
|
| - f = --__temp1[__result];
|
| - // implicit return
|
| - return thenHelper(null, null, __completer, null);
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + a = b++;
|
| + b = --b;
|
| + __goto = 2;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 2:
|
| + // returning from await.
|
| + c = __result.a++;
|
| + __goto = 3;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 3:
|
| + // returning from await.
|
| + d = ++__result.a;
|
| + __temp1 = foo1();
|
| + __goto = 4;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 4:
|
| + // returning from await.
|
| + e = __temp1[__result]--;
|
| + __temp1 = foo1();
|
| + __goto = 5;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 5:
|
| + // returning from await.
|
| + f = --__temp1[__result];
|
| + // implicit return
|
| + return thenHelper(null, 0, __completer, null);
|
| + case 1:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
| +
|
| testTransform("""
|
| -function() async {
|
| +function(d2) async {
|
| var a, b, c, d, e, f, g, h; // empty initializer
|
| a = foo1() || await foo2(); // short circuiting operators
|
| b = await foo1() || foo2();
|
| @@ -242,119 +271,133 @@
|
| g = await foo1() && await foo2();
|
| h = foo1() && foo2();
|
| }""", """
|
| -function() {
|
| - var __goto = 0, __completer = new Completer(), a, b, c, d, e, f, g, h, __temp1;
|
| - function __helper(__result) {
|
| +function(d2) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, a, b, c, d, e, f, g, h, __temp1;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - __temp1 = foo1();
|
| - if (__temp1) {
|
| - // goto then
|
| - __goto = 1;
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + __temp1 = foo1();
|
| + if (__temp1) {
|
| + // goto then
|
| + __goto = 2;
|
| + break;
|
| + } else
|
| + __result = __temp1;
|
| + // goto join
|
| + __goto = 3;
|
| break;
|
| - } else
|
| - __result = __temp1;
|
| - // goto join
|
| - __goto = 2;
|
| - break;
|
| - case 1:
|
| - // then
|
| - __goto = 3;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 3:
|
| - // returning from await.
|
| - case 2:
|
| - // join
|
| - a = __result;
|
| - __goto = 4;
|
| - return thenHelper(foo1(), __helper, __completer, null);
|
| - case 4:
|
| - // returning from await.
|
| - b = __result || foo2();
|
| - __goto = 7;
|
| - return thenHelper(foo1(), __helper, __completer, null);
|
| - case 7:
|
| - // returning from await.
|
| - __temp1 = __result;
|
| - if (__temp1) {
|
| - // goto then
|
| + case 2:
|
| + // then
|
| + __goto = 4;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 4:
|
| + // returning from await.
|
| + case 3:
|
| + // join
|
| + a = __result;
|
| __goto = 5;
|
| + return thenHelper(foo1(), __body, __completer);
|
| + case 5:
|
| + // returning from await.
|
| + b = __result || foo2();
|
| + __goto = 8;
|
| + return thenHelper(foo1(), __body, __completer);
|
| + case 8:
|
| + // returning from await.
|
| + __temp1 = __result;
|
| + if (__temp1) {
|
| + // goto then
|
| + __goto = 6;
|
| + break;
|
| + } else
|
| + __result = __temp1;
|
| + // goto join
|
| + __goto = 7;
|
| break;
|
| - } else
|
| - __result = __temp1;
|
| - // goto join
|
| - __goto = 6;
|
| - break;
|
| - case 5:
|
| - // then
|
| - __temp1 = foo3;
|
| - __goto = 8;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 8:
|
| - // returning from await.
|
| - __result = __temp1(__result);
|
| - case 6:
|
| - // join
|
| - c = __result;
|
| - d = foo1() || foo2();
|
| - __temp1 = foo1();
|
| - if (__temp1)
|
| - __result = __temp1;
|
| - else {
|
| - // goto then
|
| + case 6:
|
| + // then
|
| + __temp1 = foo3;
|
| __goto = 9;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 9:
|
| + // returning from await.
|
| + __result = __temp1(__result);
|
| + case 7:
|
| + // join
|
| + c = __result;
|
| + d = foo1() || foo2();
|
| + __temp1 = foo1();
|
| + if (__temp1)
|
| + __result = __temp1;
|
| + else {
|
| + // goto then
|
| + __goto = 10;
|
| + break;
|
| + }
|
| + // goto join
|
| + __goto = 11;
|
| break;
|
| - }
|
| - // goto join
|
| - __goto = 10;
|
| - break;
|
| - case 9:
|
| - // then
|
| - __goto = 11;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 11:
|
| - // returning from await.
|
| - case 10:
|
| - // join
|
| - e = __result;
|
| - __goto = 12;
|
| - return thenHelper(foo1(), __helper, __completer, null);
|
| - case 12:
|
| - // returning from await.
|
| - f = __result && foo2();
|
| - __goto = 15;
|
| - return thenHelper(foo1(), __helper, __completer, null);
|
| - case 15:
|
| - // returning from await.
|
| - __temp1 = __result;
|
| - if (__temp1)
|
| - __result = __temp1;
|
| - else {
|
| - // goto then
|
| + case 10:
|
| + // then
|
| + __goto = 12;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 12:
|
| + // returning from await.
|
| + case 11:
|
| + // join
|
| + e = __result;
|
| __goto = 13;
|
| + return thenHelper(foo1(), __body, __completer);
|
| + case 13:
|
| + // returning from await.
|
| + f = __result && foo2();
|
| + __goto = 16;
|
| + return thenHelper(foo1(), __body, __completer);
|
| + case 16:
|
| + // returning from await.
|
| + __temp1 = __result;
|
| + if (__temp1)
|
| + __result = __temp1;
|
| + else {
|
| + // goto then
|
| + __goto = 14;
|
| + break;
|
| + }
|
| + // goto join
|
| + __goto = 15;
|
| break;
|
| - }
|
| - // goto join
|
| - __goto = 14;
|
| - break;
|
| - case 13:
|
| - // then
|
| - __goto = 16;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 16:
|
| - // returning from await.
|
| - case 14:
|
| - // join
|
| - g = __result;
|
| - h = foo1() && foo2();
|
| - // implicit return
|
| - return thenHelper(null, null, __completer, null);
|
| + case 14:
|
| + // then
|
| + __goto = 17;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 17:
|
| + // returning from await.
|
| + case 15:
|
| + // join
|
| + g = __result;
|
| + h = foo1() && foo2();
|
| + // implicit return
|
| + return thenHelper(null, 0, __completer, null);
|
| + case 1:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
| +
|
| testTransform("""
|
| function(x, y) async {
|
| while (true) {
|
| @@ -372,75 +415,89 @@
|
| }
|
| }""", """
|
| function(x, y) {
|
| - var __goto = 0, __completer = new Completer();
|
| - function __helper(__result) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 1, __currentError;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - case 1:
|
| - // while condition
|
| - case 3:
|
| - // switch
|
| - switch (y) {
|
| - case 0:
|
| - // goto case
|
| - __goto = 5;
|
| - break;
|
| - case 1:
|
| - // goto case
|
| - __goto = 6;
|
| - break;
|
| - case 1:
|
| - // goto case
|
| - __goto = 7;
|
| - break;
|
| - case 2:
|
| - // goto case
|
| - __goto = 8;
|
| - break;
|
| - }
|
| - // goto after switch
|
| - __goto = 4;
|
| - break;
|
| - case 5:
|
| - // case
|
| - case 6:
|
| - // case
|
| - __goto = 9;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 9:
|
| - // returning from await.
|
| - // goto while condition
|
| - __goto = 1;
|
| - break;
|
| - case 7:
|
| - // case
|
| - __goto = 10;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 10:
|
| - // returning from await.
|
| - // goto after switch
|
| - __goto = 4;
|
| - break;
|
| - case 8:
|
| - // case
|
| - foo();
|
| - case 4:
|
| - // after switch
|
| - // goto while condition
|
| - __goto = 1;
|
| - break;
|
| - case 2:
|
| - // after while
|
| - // implicit return
|
| - return thenHelper(null, null, __completer, null);
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + case 2:
|
| + // while condition
|
| + case 4:
|
| + // switch
|
| + switch (y) {
|
| + case 0:
|
| + // goto case
|
| + __goto = 6;
|
| + break;
|
| + case 1:
|
| + // goto case
|
| + __goto = 7;
|
| + break;
|
| + case 1:
|
| + // goto case
|
| + __goto = 8;
|
| + break;
|
| + case 2:
|
| + // goto case
|
| + __goto = 9;
|
| + break;
|
| + }
|
| + // goto after switch
|
| + __goto = 5;
|
| + break;
|
| + case 6:
|
| + // case
|
| + case 7:
|
| + // case
|
| + __goto = 10;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 10:
|
| + // returning from await.
|
| + // goto while condition
|
| + __goto = 2;
|
| + break;
|
| + case 8:
|
| + // case
|
| + __goto = 11;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 11:
|
| + // returning from await.
|
| + // goto after switch
|
| + __goto = 5;
|
| + break;
|
| + case 9:
|
| + // case
|
| + foo();
|
| + case 5:
|
| + // after switch
|
| + // goto while condition
|
| + __goto = 2;
|
| + break;
|
| + case 3:
|
| + // after while
|
| + // implicit return
|
| + return thenHelper(null, 0, __completer, null);
|
| + case 1:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
| +
|
| testTransform("""
|
| -function() async {
|
| +function(f) async {
|
| do {
|
| var a = await foo();
|
| if (a) // If with no awaits in body
|
| @@ -450,51 +507,64 @@
|
| } while (await foo());
|
| }
|
| """, """
|
| -function() {
|
| - var __goto = 0, __completer = new Completer(), a;
|
| - function __helper(__result) {
|
| +function(f) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, a;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - case 1:
|
| - // do body
|
| - __goto = 4;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 4:
|
| - // returning from await.
|
| - a = __result;
|
| - if (a) {
|
| - // goto after do
|
| - __goto = 3;
|
| - break;
|
| - } else {
|
| - // goto do condition
|
| - __goto = 2;
|
| - break;
|
| - }
|
| - case 2:
|
| - // do condition
|
| - __goto = 5;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 5:
|
| - // returning from await.
|
| - if (__result) {
|
| - // goto do body
|
| - __goto = 1;
|
| - break;
|
| - }
|
| - case 3:
|
| - // after do
|
| - // implicit return
|
| - return thenHelper(null, null, __completer, null);
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + case 2:
|
| + // do body
|
| + __goto = 5;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 5:
|
| + // returning from await.
|
| + a = __result;
|
| + if (a) {
|
| + // goto after do
|
| + __goto = 4;
|
| + break;
|
| + } else {
|
| + // goto do condition
|
| + __goto = 3;
|
| + break;
|
| + }
|
| + case 3:
|
| + // do condition
|
| + __goto = 6;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 6:
|
| + // returning from await.
|
| + if (__result) {
|
| + // goto do body
|
| + __goto = 2;
|
| + break;
|
| + }
|
| + case 4:
|
| + // after do
|
| + // implicit return
|
| + return thenHelper(null, 0, __completer, null);
|
| + case 1:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
|
|
| testTransform("""
|
| -function() async {
|
| +function(g) async {
|
| for (var i = 0; i < await foo1(); i += await foo2()) {
|
| if (foo(i))
|
| continue;
|
| @@ -508,76 +578,89 @@
|
| }
|
| }
|
| """, """
|
| -function() {
|
| - var __goto = 0, __completer = new Completer(), __returnValue, i, __temp1;
|
| - function __helper(__result) {
|
| +function(g) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 2, __currentError, __returnValue, i, __temp1;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - i = 0;
|
| - case 2:
|
| - // for condition
|
| - __temp1 = i;
|
| - __goto = 5;
|
| - return thenHelper(foo1(), __helper, __completer, null);
|
| - case 5:
|
| - // returning from await.
|
| - if (!(__temp1 < __result)) {
|
| - // goto after for
|
| - __goto = 4;
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + i = 0;
|
| + case 3:
|
| + // for condition
|
| + __temp1 = i;
|
| + __goto = 6;
|
| + return thenHelper(foo1(), __body, __completer);
|
| + case 6:
|
| + // returning from await.
|
| + if (!(__temp1 < __result)) {
|
| + // goto after for
|
| + __goto = 5;
|
| + break;
|
| + }
|
| + if (foo(i)) {
|
| + // goto for update
|
| + __goto = 4;
|
| + break;
|
| + } else {
|
| + // goto after for
|
| + __goto = 5;
|
| + break;
|
| + }
|
| + __goto = !foo(i) ? 7 : 8;
|
| break;
|
| - }
|
| - if (foo(i)) {
|
| - // goto for update
|
| + case 7:
|
| + // then
|
| + __goto = 9;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 9:
|
| + // returning from await.
|
| + // goto return
|
| + __goto = 1;
|
| + break;
|
| + case 8:
|
| + // join
|
| + __temp1 = print;
|
| + __goto = 10;
|
| + return thenHelper(foo(i), __body, __completer);
|
| + case 10:
|
| + // returning from await.
|
| + __temp1(__result);
|
| + case 4:
|
| + // for update
|
| + __goto = 11;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 11:
|
| + // returning from await.
|
| + i = __result;
|
| + // goto for condition
|
| __goto = 3;
|
| break;
|
| - } else {
|
| - // goto after for
|
| - __goto = 4;
|
| - break;
|
| - }
|
| - __goto = !foo(i) ? 6 : 7;
|
| - break;
|
| - case 6:
|
| - // then
|
| - __goto = 8;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 8:
|
| - // returning from await.
|
| - // goto return
|
| - __goto = 1;
|
| - break;
|
| - case 7:
|
| - // join
|
| - __temp1 = print;
|
| - __goto = 9;
|
| - return thenHelper(foo(i), __helper, __completer, null);
|
| - case 9:
|
| - // returning from await.
|
| - __temp1(__result);
|
| - case 3:
|
| - // for update
|
| - __goto = 10;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 10:
|
| - // returning from await.
|
| - i = __result;
|
| - // goto for condition
|
| - __goto = 2;
|
| - break;
|
| - case 4:
|
| - // after for
|
| - case 1:
|
| - // return
|
| - return thenHelper(__returnValue, null, __completer, null);
|
| + case 5:
|
| + // after for
|
| + case 1:
|
| + // return
|
| + return thenHelper(__returnValue, 0, __completer, null);
|
| + case 2:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
|
|
| testTransform("""
|
| -function(a) async {
|
| +function(a, h) async {
|
| var x = {"a": foo1(), "b": await foo2(), "c": foo3()};
|
| x["a"] = 2; // Different assignments
|
| (await foo()).a = 3;
|
| @@ -586,65 +669,79 @@
|
| (await foo1())[await foo2()] = await foo3(6);
|
| }
|
| """, """
|
| -function(a) {
|
| - var __goto = 0, __completer = new Completer(), x, __temp1, __temp2;
|
| - function __helper(__result) {
|
| +function(a, h) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, x, __temp1, __temp2;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - __temp1 = foo1();
|
| - __goto = 1;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 1:
|
| - // returning from await.
|
| - x = {a: __temp1, b: __result, c: foo3()};
|
| - x.a = 2;
|
| - __goto = 2;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 2:
|
| - // returning from await.
|
| - __result.a = 3;
|
| - __temp1 = x;
|
| - __goto = 3;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 3:
|
| - // returning from await.
|
| - __temp1[__result] = 4;
|
| - __temp1 = x;
|
| - __goto = 4;
|
| - return thenHelper(foo1(), __helper, __completer, null);
|
| - case 4:
|
| - // returning from await.
|
| - __temp2 = __result;
|
| - __goto = 5;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 5:
|
| - // returning from await.
|
| - __temp1[__temp2.a = __result] = 5;
|
| - __goto = 6;
|
| - return thenHelper(foo1(), __helper, __completer, null);
|
| - case 6:
|
| - // returning from await.
|
| - __temp1 = __result;
|
| - __goto = 7;
|
| - return thenHelper(foo2(), __helper, __completer, null);
|
| - case 7:
|
| - // returning from await.
|
| - __temp2 = __result;
|
| - __goto = 8;
|
| - return thenHelper(foo3(6), __helper, __completer, null);
|
| - case 8:
|
| - // returning from await.
|
| - __temp1[__temp2] = __result;
|
| - // implicit return
|
| - return thenHelper(null, null, __completer, null);
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + __temp1 = foo1();
|
| + __goto = 2;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 2:
|
| + // returning from await.
|
| + x = {a: __temp1, b: __result, c: foo3()};
|
| + x.a = 2;
|
| + __goto = 3;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 3:
|
| + // returning from await.
|
| + __result.a = 3;
|
| + __temp1 = x;
|
| + __goto = 4;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 4:
|
| + // returning from await.
|
| + __temp1[__result] = 4;
|
| + __temp1 = x;
|
| + __goto = 5;
|
| + return thenHelper(foo1(), __body, __completer);
|
| + case 5:
|
| + // returning from await.
|
| + __temp2 = __result;
|
| + __goto = 6;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 6:
|
| + // returning from await.
|
| + __temp1[__temp2.a = __result] = 5;
|
| + __goto = 7;
|
| + return thenHelper(foo1(), __body, __completer);
|
| + case 7:
|
| + // returning from await.
|
| + __temp1 = __result;
|
| + __goto = 8;
|
| + return thenHelper(foo2(), __body, __completer);
|
| + case 8:
|
| + // returning from await.
|
| + __temp2 = __result;
|
| + __goto = 9;
|
| + return thenHelper(foo3(6), __body, __completer);
|
| + case 9:
|
| + // returning from await.
|
| + __temp1[__temp2] = __result;
|
| + // implicit return
|
| + return thenHelper(null, 0, __completer, null);
|
| + case 1:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
| +
|
| testTransform("""
|
| -function(c) async {
|
| +function(c, i) async {
|
| try {
|
| var x = c ? await foo() : foo(); // conditional
|
| var y = {};
|
| @@ -659,103 +756,115 @@
|
| }
|
| }
|
| """, """
|
| -function(c) {
|
| - var __goto = 0, __completer = new Completer(), __handler = null, x, y, __error1, __error2;
|
| - function __helper(__result) {
|
| +function(c, i) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, x, y, __error1, __error2;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| try {
|
| switch (__goto) {
|
| case 0:
|
| // Function start
|
| - __handler = 1;
|
| - __goto = c ? 4 : 6;
|
| + __handler = 3;
|
| + __goto = c ? 6 : 8;
|
| break;
|
| - case 4:
|
| + case 6:
|
| // then
|
| - __goto = 7;
|
| - return thenHelper(foo(), __helper, __completer, function(__error) {
|
| - __goto = 1;
|
| - __helper(__error);
|
| - });
|
| - case 7:
|
| + __goto = 9;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 9:
|
| // returning from await.
|
| // goto join
|
| - __goto = 5;
|
| + __goto = 7;
|
| break;
|
| - case 6:
|
| + case 8:
|
| // else
|
| __result = foo();
|
| - case 5:
|
| + case 7:
|
| // join
|
| x = __result;
|
| y = {};
|
| - __next = [3];
|
| - __handler = null;
|
| + __handler = 1;
|
| // goto after finally
|
| - __goto = 3;
|
| + __goto = 5;
|
| break;
|
| - case 1:
|
| + case 3:
|
| // catch
|
| - __handler = null;
|
| - __error1 = __result;
|
| - __handler = 8;
|
| - __goto = c ? 11 : 13;
|
| + __handler = 2;
|
| + __error1 = __currentError;
|
| + __handler = 11;
|
| + __goto = c ? 14 : 16;
|
| break;
|
| - case 11:
|
| + case 14:
|
| // then
|
| - __goto = 14;
|
| - return thenHelper(fooError(__error1), __helper, __completer, function(__error) {
|
| - __goto = 8;
|
| - __helper(__error);
|
| - });
|
| - case 14:
|
| + __goto = 17;
|
| + return thenHelper(fooError(__error1), __body, __completer);
|
| + case 17:
|
| // returning from await.
|
| // goto join
|
| - __goto = 12;
|
| + __goto = 15;
|
| break;
|
| - case 13:
|
| + case 16:
|
| // else
|
| __result = fooError(__error1);
|
| - case 12:
|
| + case 15:
|
| // join
|
| x = __result;
|
| - __next = [10];
|
| + __next = [13];
|
| // goto finally
|
| - __goto = 9;
|
| + __goto = 12;
|
| break;
|
| - case 8:
|
| + case 11:
|
| // catch
|
| - __handler = null;
|
| - __error2 = __result;
|
| + __handler = 10;
|
| + __error2 = __currentError;
|
| y.x = foo(__error2);
|
| - __handler = null;
|
| - __next = [10];
|
| - case 9:
|
| + __next = [13];
|
| + // goto finally
|
| + __goto = 12;
|
| + break;
|
| + case 10:
|
| + // uncaught
|
| + __next = [2];
|
| + case 12:
|
| // finally
|
| - __handler = null;
|
| + __handler = 2;
|
| foo(x);
|
| // goto the next finally handler
|
| __goto = __next.pop();
|
| break;
|
| - case 10:
|
| + case 13:
|
| // after finally
|
| - case 3:
|
| + // goto after finally
|
| + __goto = 5;
|
| + break;
|
| + case 2:
|
| + // uncaught
|
| + // goto rethrow
|
| + __goto = 1;
|
| + break;
|
| + case 5:
|
| // after finally
|
| // implicit return
|
| - return thenHelper(null, null, __completer, null);
|
| + return thenHelper(null, 0, __completer, null);
|
| + case 1:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| }
|
| } catch (__error) {
|
| - if (__handler === null)
|
| - throw __error;
|
| - __result = __error;
|
| + __currentError = __error;
|
| __goto = __handler;
|
| }
|
|
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
| +
|
| testTransform("""
|
| -function(x, y) async {
|
| +function(x, y, j) async {
|
| print(await(foo(x))); // calls
|
| (await print)(foo(x));
|
| print(foo(await x));
|
| @@ -763,57 +872,71 @@
|
| print(foo(x, await y, z));
|
| }
|
| """, """
|
| -function(x, y) {
|
| - var __goto = 0, __completer = new Completer(), __temp1, __temp2, __temp3;
|
| - function __helper(__result) {
|
| +function(x, y, j) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 1, __currentError, __temp1, __temp2, __temp3;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - __temp1 = print;
|
| - __goto = 1;
|
| - return thenHelper(foo(x), __helper, __completer, null);
|
| - case 1:
|
| - // returning from await.
|
| - __temp1(__result);
|
| - __goto = 2;
|
| - return thenHelper(print, __helper, __completer, null);
|
| - case 2:
|
| - // returning from await.
|
| - __result(foo(x));
|
| - __temp1 = print;
|
| - __temp2 = foo;
|
| - __goto = 3;
|
| - return thenHelper(x, __helper, __completer, null);
|
| - case 3:
|
| - // returning from await.
|
| - __temp1(__temp2(__result));
|
| - __temp1 = print;
|
| - __temp2 = foo;
|
| - __goto = 5;
|
| - return thenHelper(x, __helper, __completer, null);
|
| - case 5:
|
| - // returning from await.
|
| - __goto = 4;
|
| - return thenHelper(__temp1(__temp2(__result)), __helper, __completer, null);
|
| - case 4:
|
| - // returning from await.
|
| - __temp1 = print;
|
| - __temp2 = foo;
|
| - __temp3 = x;
|
| - __goto = 6;
|
| - return thenHelper(y, __helper, __completer, null);
|
| - case 6:
|
| - // returning from await.
|
| - __temp1(__temp2(__temp3, __result, z));
|
| - // implicit return
|
| - return thenHelper(null, null, __completer, null);
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + __temp1 = print;
|
| + __goto = 2;
|
| + return thenHelper(foo(x), __body, __completer);
|
| + case 2:
|
| + // returning from await.
|
| + __temp1(__result);
|
| + __goto = 3;
|
| + return thenHelper(print, __body, __completer);
|
| + case 3:
|
| + // returning from await.
|
| + __result(foo(x));
|
| + __temp1 = print;
|
| + __temp2 = foo;
|
| + __goto = 4;
|
| + return thenHelper(x, __body, __completer);
|
| + case 4:
|
| + // returning from await.
|
| + __temp1(__temp2(__result));
|
| + __temp1 = print;
|
| + __temp2 = foo;
|
| + __goto = 6;
|
| + return thenHelper(x, __body, __completer);
|
| + case 6:
|
| + // returning from await.
|
| + __goto = 5;
|
| + return thenHelper(__temp1(__temp2(__result)), __body, __completer);
|
| + case 5:
|
| + // returning from await.
|
| + __temp1 = print;
|
| + __temp2 = foo;
|
| + __temp3 = x;
|
| + __goto = 7;
|
| + return thenHelper(y, __body, __completer);
|
| + case 7:
|
| + // returning from await.
|
| + __temp1(__temp2(__temp3, __result, z));
|
| + // implicit return
|
| + return thenHelper(null, 0, __completer, null);
|
| + case 1:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
| +
|
| testTransform("""
|
| -function(x, y) async {
|
| +function(x, y, k) async {
|
| while (await(foo())) {
|
| lab: { // labelled statement
|
| switch(y) {
|
| @@ -838,112 +961,125 @@
|
| }
|
| }
|
| }""", """
|
| -function(x, y) {
|
| - var __goto = 0, __completer = new Completer(), __returnValue, __temp1;
|
| - function __helper(__result) {
|
| +function(x, y, k) {
|
| + var __goto = 0, __completer = new Completer(), __handler = 2, __currentError, __returnValue, __temp1;
|
| + function __body(__errorCode, __result) {
|
| + if (__errorCode == 1) {
|
| + __currentError = __result;
|
| + __goto = __handler;
|
| + }
|
| while (true)
|
| - switch (__goto) {
|
| - case 0:
|
| - // Function start
|
| - case 2:
|
| - // while condition
|
| - __goto = 4;
|
| - return thenHelper(foo(), __helper, __completer, null);
|
| - case 4:
|
| - // returning from await.
|
| - if (!__result) {
|
| - // goto after while
|
| - __goto = 3;
|
| + try {
|
| + switch (__goto) {
|
| + case 0:
|
| + // Function start
|
| + case 3:
|
| + // while condition
|
| + __goto = 5;
|
| + return thenHelper(foo(), __body, __completer);
|
| + case 5:
|
| + // returning from await.
|
| + if (!__result) {
|
| + // goto after while
|
| + __goto = 4;
|
| + break;
|
| + }
|
| + case 7:
|
| + // continue lab
|
| + case 8:
|
| + // switch
|
| + __temp1 = y;
|
| + if (__temp1 === 0) {
|
| + // goto case
|
| + __goto = 10;
|
| + break;
|
| + }
|
| + if (__temp1 === 0) {
|
| + // goto case
|
| + __goto = 11;
|
| + break;
|
| + }
|
| + __goto = 13;
|
| + return thenHelper(bar(), __body, __completer);
|
| + case 13:
|
| + // returning from await.
|
| + if (__temp1 === __result) {
|
| + // goto case
|
| + __goto = 12;
|
| + break;
|
| + }
|
| + if (__temp1 === x) {
|
| + // goto case
|
| + __goto = 14;
|
| + break;
|
| + }
|
| + // goto default
|
| + __goto = 15;
|
| break;
|
| - }
|
| - case 6:
|
| - // continue lab
|
| - case 7:
|
| - // switch
|
| - __temp1 = y;
|
| - if (__temp1 === 0) {
|
| - // goto case
|
| - __goto = 9;
|
| + case 10:
|
| + // case
|
| + foo();
|
| + case 11:
|
| + // case
|
| + __temp1 = print;
|
| + __goto = 16;
|
| + return thenHelper(foo1(x), __body, __completer);
|
| + case 16:
|
| + // returning from await.
|
| + __temp1(__result);
|
| + __returnValue = y;
|
| + // goto return
|
| + __goto = 1;
|
| break;
|
| - }
|
| - if (__temp1 === 0) {
|
| - // goto case
|
| - __goto = 10;
|
| + case 12:
|
| + // case
|
| + __temp1 = print;
|
| + __goto = 17;
|
| + return thenHelper(foobar(x), __body, __completer);
|
| + case 17:
|
| + // returning from await.
|
| + __temp1(__result);
|
| + __returnValue = y;
|
| + // goto return
|
| + __goto = 1;
|
| break;
|
| - }
|
| - __goto = 12;
|
| - return thenHelper(bar(), __helper, __completer, null);
|
| - case 12:
|
| - // returning from await.
|
| - if (__temp1 === __result) {
|
| - // goto case
|
| - __goto = 11;
|
| + case 14:
|
| + // case
|
| + if (a) {
|
| + throw new Error();
|
| + } else {
|
| + // goto while condition
|
| + __goto = 3;
|
| + break;
|
| + }
|
| + case 15:
|
| + // default
|
| + // goto break lab
|
| + __goto = 6;
|
| break;
|
| - }
|
| - if (__temp1 === x) {
|
| - // goto case
|
| - __goto = 13;
|
| - break;
|
| - }
|
| - // goto default
|
| - __goto = 14;
|
| - break;
|
| - case 9:
|
| - // case
|
| - foo();
|
| - case 10:
|
| - // case
|
| - __temp1 = print;
|
| - __goto = 15;
|
| - return thenHelper(foo1(x), __helper, __completer, null);
|
| - case 15:
|
| - // returning from await.
|
| - __temp1(__result);
|
| - __returnValue = y;
|
| - // goto return
|
| - __goto = 1;
|
| - break;
|
| - case 11:
|
| - // case
|
| - __temp1 = print;
|
| - __goto = 16;
|
| - return thenHelper(foobar(x), __helper, __completer, null);
|
| - case 16:
|
| - // returning from await.
|
| - __temp1(__result);
|
| - __returnValue = y;
|
| - // goto return
|
| - __goto = 1;
|
| - break;
|
| - case 13:
|
| - // case
|
| - if (a) {
|
| - throw new Error();
|
| - } else {
|
| + case 9:
|
| + // after switch
|
| + foo();
|
| + case 6:
|
| + // break lab
|
| // goto while condition
|
| - __goto = 2;
|
| + __goto = 3;
|
| break;
|
| - }
|
| - case 14:
|
| - // default
|
| - // goto break lab
|
| - __goto = 5;
|
| - break;
|
| - case 8:
|
| - // after switch
|
| - foo();
|
| - case 5:
|
| - // break lab
|
| - // goto while condition
|
| - __goto = 2;
|
| - break;
|
| - case 3:
|
| - // after while
|
| - case 1:
|
| - // return
|
| - return thenHelper(__returnValue, null, __completer, null);
|
| + case 4:
|
| + // after while
|
| + case 1:
|
| + // return
|
| + return thenHelper(__returnValue, 0, __completer, null);
|
| + case 2:
|
| + // rethrow
|
| + return thenHelper(__currentError, 1, __completer);
|
| + }
|
| + } catch (__error) {
|
| + __currentError = __error;
|
| + __goto = __handler;
|
| }
|
| +
|
| }
|
| - return thenHelper(null, __helper, __completer, null);
|
| + return thenHelper(null, __body, __completer, null);
|
| }""");
|
| }
|
|
|