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

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: Add tests 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/language/async_continue_label_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 65408295e6f8bb56e49fc736df550a4b5c8143f6..e68216a43c22f354f54d8375bad3cb46c8fa6f00 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -920,7 +920,8 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
bool oldInsideUntranslatedBreakable = insideUntranslatedBreakable;
insideUntranslatedBreakable = true;
withExpression(node.condition, (js.Expression condition) {
- addStatement(js.js.statement('do {#} while (#)', [node.body, condition]));
+ addStatement(js.js.statement('do {#} while (#)',
+ [node.body, condition]));
}, store: false);
insideUntranslatedBreakable = oldInsideUntranslatedBreakable;
return;
@@ -952,18 +953,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
@@ -986,7 +979,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
@@ -1110,12 +1103,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();
@@ -1491,7 +1484,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) {
@@ -1499,11 +1494,15 @@ 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);
}
}
+ return initializations.isEmpty ? js.number(0)
floitsch 2015/03/13 14:20:22 Make this an if. Explain why "0".
sigurdm 2015/03/16 08:43:51 Done.
+ : initializations.reduce((js.Expression first, js.Expression second) {
+ return new js.Binary(",", first, second);
+ });
}
@override
@@ -2206,8 +2205,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/language/async_continue_label_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698