Index: pkg/compiler/lib/src/js_backend/codegen/codegen.dart |
diff --git a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart |
index 6491df609898e276f16ed02af13cbe508c9bef75..f6bb7b14d5448dc06f5fac11006675a20799bbad 100644 |
--- a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart |
+++ b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart |
@@ -419,13 +419,13 @@ class CodeGenerator extends tree_ir.StatementVisitor |
@override |
void visitIf(tree_ir.If node) { |
accumulator.add(new js.If(visitExpression(node.condition), |
- buildBody(node.thenStatement), |
- buildBody(node.elseStatement))); |
+ buildBodyStatement(node.thenStatement), |
+ buildBodyStatement(node.elseStatement))); |
} |
@override |
void visitLabeledStatement(tree_ir.LabeledStatement node) { |
- accumulator.add(buildLabeled(() => buildBody(node.body), |
+ accumulator.add(buildLabeled(() => buildBodyStatement(node.body), |
node.label, |
node.next)); |
visitStatement(node.next); |
@@ -481,20 +481,29 @@ class CodeGenerator extends tree_ir.StatementVisitor |
} |
/// Builds a nested statement. |
- js.Statement buildBody(tree_ir.Statement statement) { |
+ js.Statement buildBodyStatement(tree_ir.Statement statement) { |
List<js.Statement> savedAccumulator = accumulator; |
- accumulator = new List<js.Statement>(); |
+ accumulator = <js.Statement>[]; |
visitStatement(statement); |
js.Statement result = _bodyAsStatement(); |
accumulator = savedAccumulator; |
return result; |
} |
+ js.Block buildBodyBlock(tree_ir.Statement statement) { |
+ List<js.Statement> savedAccumulator = accumulator; |
+ accumulator = <js.Statement>[]; |
+ visitStatement(statement); |
+ js.Statement result = new js.Block(accumulator); |
+ accumulator = savedAccumulator; |
+ return result; |
+ } |
+ |
js.Statement buildWhile(js.Expression condition, |
tree_ir.Statement body, |
tree_ir.Label label, |
tree_ir.Statement fallthroughStatement) { |
- return buildLabeled(() => new js.While(condition, buildBody(body)), |
+ return buildLabeled(() => new js.While(condition, buildBodyStatement(body)), |
label, |
fallthroughStatement); |
} |
@@ -522,8 +531,13 @@ class CodeGenerator extends tree_ir.StatementVisitor |
@override |
void visitTry(tree_ir.Try node) { |
- // TODO(kmillikin): implement TryStatement. |
- return giveup(node); |
+ js.Block tryBlock = buildBodyBlock(node.tryBody); |
+ tree_ir.Variable exceptionVariable = node.catchParameters.first; |
+ js.VariableDeclaration exceptionParameter = |
+ new js.VariableDeclaration(getVariableName(exceptionVariable)); |
+ js.Block catchBlock = buildBodyBlock(node.catchBody); |
+ js.Catch catchPart = new js.Catch(exceptionParameter, catchBlock); |
+ accumulator.add(new js.Try(tryBlock, catchPart, null)); |
} |
@override |