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

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 969783002: implement rethrow (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 10 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 | test/codegen/expect/_isolate_helper/_isolate_helper.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index 00d4ef8063dedef39024d85153c68aa44a4b6d4e..628d7a1e95a80bb5c7a80475896653929a4c6611 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -37,6 +37,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
/// The variable for the target of the current `..` cascade expression.
SimpleIdentifier _cascadeTarget;
+ /// The variable for the current catch clause
+ String _catchParameter;
ClassDeclaration currentClass;
ConstantEvaluator _constEvaluator;
@@ -1287,6 +1289,15 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
}
@override
+ visitRethrowExpression(RethrowExpression node){
+ if (node.parent is ExpressionStatement) {
+ return js.statement('throw #;', _catchParameter);
+ } else {
+ return js.call('dart.throw_(#)', _catchParameter);
+ }
+ }
+
+ @override
JS.If visitIfStatement(IfStatement node) {
return new JS.If(_visit(node.condition), _visit(node.thenStatement),
_visitOrEmpty(node.elseStatement));
@@ -1342,19 +1353,22 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
// TODO(jmesserly): need a better way to get a temporary variable.
// This could incorrectly shadow a user's name.
- var name = '\$e';
+ var savedCatch = _catchParameter;
+ _catchParameter = '\$e';
if (clauses.length == 1) {
// Special case for a single catch.
var clause = clauses.single;
if (clause.exceptionParameter != null) {
- name = clause.exceptionParameter.name;
+ _catchParameter = clause.exceptionParameter.name;
}
}
- var catchBody = _statement(clauses.map((c) => _visitCatchClause(c, name)));
+ var catchVarDecl = new JS.VariableDeclaration(_catchParameter);
+ var catchBody = _statement(_visitList(clauses));
+ _catchParameter = savedCatch;
- return new JS.Catch(new JS.VariableDeclaration(name), catchBody);
+ return new JS.Catch(catchVarDecl, catchBody);
}
JS.Statement _statement(Iterable stmts) {
@@ -1365,12 +1379,16 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
return new JS.Block(s);
}
- JS.Statement _visitCatchClause(CatchClause node, String varName) {
+ @override
+ JS.Statement visitCatchClause(CatchClause node) {
var body = [];
+
+ var savedCatch = _catchParameter;
if (node.catchKeyword != null) {
var name = node.exceptionParameter;
- if (name != null && name.name != varName) {
- body.add(js.statement('let # = #;', [_visit(name), varName]));
+ if (name != null && name.name != _catchParameter) {
+ body.add(js.statement('let # = #;', [_visit(name), _catchParameter]));
+ _catchParameter = name.name;
}
if (node.stackTraceParameter != null) {
var stackVar = node.stackTraceParameter.name;
@@ -1380,14 +1398,16 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
}
body.add(_visit(node.body));
+ _catchParameter = savedCatch;
if (node.exceptionType != null) {
return js.statement('if (dart.is(#, #)) #;', [
- varName,
+ _catchParameter,
_emitTypeName(node.exceptionType.type),
_statement(body)
]);
}
+
return _statement(body);
}
« no previous file with comments | « no previous file | test/codegen/expect/_isolate_helper/_isolate_helper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698