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

Unified Diff: compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java

Issue 8208016: Add support for exception rethrowing using "throw;" (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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/co19/co19-compiler.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java
===================================================================
--- compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java (revision 369)
+++ compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java (working copy)
@@ -153,6 +153,7 @@
import com.google.dart.compiler.type.Types;
import com.google.dart.compiler.util.AstUtil;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
@@ -253,6 +254,8 @@
private final CoreTypeProvider typeProvider;
private final Types typeUtils;
+ private final Deque<JsName> catchVarStack = new ArrayDeque<JsName>();
+
public GenerateJavascriptVisitor(DartUnit unit, DartCompilerContext context,
TranslationContext translationContext,
OptimizationStrategy optStrategy, CoreTypeProvider typeProvider,
@@ -1975,6 +1978,7 @@
jsCatch.setBody(jsCatchBody);
JsStatement jsElse = new JsThrow(new JsNameRef(exceptionVar));
+ catchVarStack.push(exceptionVar);
for (int i = catchBlocks.size() - 1; i >= 0; i--) {
DartCatchBlock catchBlock = catchBlocks.get(i);
JsBlock jsClauseBody = (JsBlock) generate(catchBlock.getBlock());
@@ -2012,6 +2016,7 @@
jsElse = new JsIf(instanceCheck, jsClauseBody, jsElse);
}
jsCatchBody.getStatements().add(jsElse);
+ catchVarStack.pop();
}
if (x.getFinallyBlock() != null) {
@@ -2031,12 +2036,24 @@
public JsNode visitThrowStatement(DartThrowStatement x) {
JsNameRef error = new JsNameRef("$Dart$ThrowException");
JsInvocation invoc = AstUtil.newInvocation(error);
+ JsExpression exception;
if (x.getException() != null) {
- invoc.getArguments().add((JsExpression) generate(x.getException()));
+ exception = (JsExpression) generate(x.getException());
+ } else {
+ // rethrow the exception
+ JsName name = catchVarStack.peek();
+ if (name != null) {
+ exception = name.makeRef();
+ } else {
+ // TODO(johnlenz): validate this is the correct behavior
+ throw new InternalCompilerException("invalid rethrow context");
+ }
}
+ invoc.getArguments().add(exception);
return new JsExprStmt(invoc.setSourceRef(x));
}
+
@Override
public JsNode visitVariableStatement(DartVariableStatement x) {
« no previous file with comments | « no previous file | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698