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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1083663005: Implement try/catch in the JS backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review comment.s Created 5 years, 8 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 | « pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fe66f5bcda6c3057f8d800569909e36271dcd867..73c31e12e66cd09d26b138a78f9411c374fd1192 100644
--- a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
+++ b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
@@ -425,13 +425,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);
@@ -476,20 +476,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);
}
@@ -517,8 +526,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
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698