Chromium Code Reviews| Index: pkg/compiler/lib/src/js/rewrite_async.dart |
| diff --git a/pkg/compiler/lib/src/js/rewrite_async.dart b/pkg/compiler/lib/src/js/rewrite_async.dart |
| index b1918ad5ecded07ba04bedb2ededf87029f64c21..58d340c4858c6a97e3b397e7bc3a1c5441dbf49a 100644 |
| --- a/pkg/compiler/lib/src/js/rewrite_async.dart |
| +++ b/pkg/compiler/lib/src/js/rewrite_async.dart |
| @@ -127,6 +127,9 @@ abstract class AsyncRewriterBase extends js.NodeVisitor { |
| js.VariableUse get handler => new js.VariableUse(handlerName); |
| String handlerName; |
| + /// Set to `true` if any of the switch statement labels is a handler. |
| + bool hasHandlerLabels = false; |
| + |
| /// A stack of labels of finally blocks to visit, and the label to go to after |
| /// the last. |
| js.VariableUse get next => new js.VariableUse(nextName); |
| @@ -685,8 +688,10 @@ abstract class AsyncRewriterBase extends js.NodeVisitor { |
| variables.add(_makeVariableInitializer(goto, js.number(0))); |
| variables.addAll(variableInitializations()); |
| - variables.add(_makeVariableInitializer(handler, js.number(rethrowLabel))); |
| - variables.add(_makeVariableInitializer(currentError, null)); |
| + if (hasHandlerLabels) { |
| + variables.add(_makeVariableInitializer(handler, js.number(rethrowLabel))); |
| + variables.add(_makeVariableInitializer(currentError, null)); |
| + } |
| if (analysis.hasFinally || (isAsyncStar && analysis.hasYield)) { |
| variables.add(_makeVariableInitializer( |
| next, new js.ArrayInitializer(<js.Expression>[]))); |
| @@ -1412,6 +1417,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor { |
| } |
| setErrorHandler([int errorHandler]) { |
| + hasHandlerLabels = true; |
| js.Expression label = |
| (errorHandler == null) ? currentErrorHandler : js.number(errorHandler); |
| addStatement(js.js.statement('# = #;', [handler, label])); |
| @@ -1708,6 +1714,7 @@ class AsyncRewriter extends AsyncRewriterBase { |
| } |
| void addErrorExit() { |
| + if (!hasHandlerLabels) return; |
| beginLabel(rethrowLabel); |
| addStatement(js.js.statement( |
| "return #thenHelper(#currentError, #completer);", { |
| @@ -1777,8 +1784,11 @@ class AsyncRewriter extends AsyncRewriterBase { |
| #variableDeclarations; |
| var #bodyName = #wrapBody(function (#errorCode, #result) { |
| if (#errorCode === #ERROR) { |
| - #currentError = #result; |
| - #goto = #handler; |
| + if (#hasHandlerLabels) { |
| + #currentError = #result; |
| + #goto = #handler; |
| + } else |
| + return #asyncRethrow(#result, #completer); |
| } |
| #rewrittenBody; |
| }); |
| @@ -1796,6 +1806,8 @@ class AsyncRewriter extends AsyncRewriterBase { |
| "errorCode": errorCodeName, |
| "result": resultName, |
| "asyncStart": asyncStart, |
| + "asyncRethrow": asyncRethrow, |
| + "hasHandlerLabels": hasHandlerLabels, |
| "completer": completer, |
| "wrapBody": wrapBody, |
| }).withSourceInformation(sourceInformation); |
| @@ -1907,6 +1919,7 @@ class SyncStarRewriter extends AsyncRewriterBase { |
| } |
| void addErrorExit() { |
| + hasHandlerLabels = true; |
|
floitsch
2017/05/04 08:52:05
This is too confusing, but I'm guessing this is ju
sra1
2017/05/05 21:52:34
I added a field comment and a TODO comment here to
|
| beginLabel(rethrowLabel); |
| addStatement(js.js |
| .statement('return #(#);', [uncaughtErrorExpression, currentError])); |
| @@ -2091,6 +2104,7 @@ class AsyncStarRewriter extends AsyncRewriterBase { |
| @override |
| void addErrorExit() { |
| + hasHandlerLabels = true; |
|
floitsch
2017/05/04 08:52:05
ditto.
|
| beginLabel(rethrowLabel); |
| addStatement(js.js.statement( |
| "return #asyncHelper(#currentError, #errorCode, #controller);", { |