Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(815)

Unified Diff: pkg/compiler/lib/src/js/rewrite_async.dart

Issue 1003213002: Fix "continue to a label" in dart2js async code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review. Also update unittest Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js/async_await_js_transform_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 0f1f4333e250f7c5a3bef748e7cf310d08f67286..8e900c015ed4c7f94f8adc0cfe02ece3ef4ea77f 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -996,18 +996,10 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
addStatement(node);
}
- void visitExpressionInStatementContext(js.Expression node) {
- if (node is js.VariableDeclarationList) {
- // Treat js.VariableDeclarationList as a statement.
- visitVariableDeclarationList(node);
- } else {
- visitExpressionIgnoreResult(node);
- }
- }
@override
void visitExpressionStatement(js.ExpressionStatement node) {
- visitExpressionInStatementContext(node.expression);
+ visitExpressionIgnoreResult(node.expression);
}
@override
@@ -1030,7 +1022,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
}
if (node.init != null) {
- visitExpressionInStatementContext(node.init);
+ addExpressionStatement(visitExpression(node.init));
}
int startLabel = newLabel("for condition");
// If there is no update, continuing the loop is the same as going to the
@@ -1154,12 +1146,12 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
new js.LabeledStatement(node.label, translateInBlock(node.body)));
return;
}
+ // `continue label` is really continuing the nested loop.
+ // This is set up in [PreTranslationAnalysis.visitContinue].
+ // Here we only need a breakLabel:
int breakLabel = newLabel("break ${node.label}");
- int continueLabel = newLabel("continue ${node.label}");
breakLabels[node] = breakLabel;
- continueLabels[node] = continueLabel;
- beginLabel(continueLabel);
jumpTargets.add(node);
visitStatement(node.body);
jumpTargets.removeLast();
@@ -1535,7 +1527,9 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
}
@override
- void visitVariableDeclarationList(js.VariableDeclarationList node) {
+ js.Expression visitVariableDeclarationList(js.VariableDeclarationList node) {
+ List<js.Assignment> initializations = new List<js.Assignment>();
+
// Declaration of local variables is hoisted outside the helper but the
// initialization is done here.
for (js.VariableInitialization initialization in node.declarations) {
@@ -1543,11 +1537,20 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
localVariables.add(declaration);
if (initialization.value != null) {
withExpression(initialization.value, (js.Expression value) {
- addStatement(new js.ExpressionStatement(
- new js.Assignment(new js.VariableUse(declaration.name), value)));
+ initializations.add(
+ new js.Assignment(new js.VariableUse(declaration.name), value));
}, store: false);
}
}
+ if (initializations.isEmpty) {
+ // Dummy expression. Will be dropped by [visitExpressionIgnoreResult].
+ return js.number(0);
+ } else {
+ return initializations.reduce(
+ (js.Expression first, js.Expression second) {
+ return new js.Binary(",", first, second);
+ });
+ }
}
@override
@@ -2251,8 +2254,10 @@ class PreTranslationAnalysis extends js.NodeVisitor<bool> {
@override
bool visitContinue(js.Continue node) {
if (node.targetLabel != null) {
- targets[node] = labelledStatements.lastWhere(
+ js.LabeledStatement targetLabel = labelledStatements.lastWhere(
(js.LabeledStatement stm) => stm.label == node.targetLabel);
+ js.Loop targetStatement = targetLabel.body;
+ targets[node] = targetStatement;
} else {
targets[node] =
loopsAndSwitches.lastWhere((js.Node node) => node is! js.Switch);
« no previous file with comments | « no previous file | tests/compiler/dart2js/async_await_js_transform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698