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

Unified Diff: pkg/kernel/lib/interpreter/interpreter.dart

Issue 3002003002: Add support for catch statements. (Closed)
Patch Set: Remove formatting changes Created 3 years, 4 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 | pkg/kernel/testcases/interpreter/try_catch_finally_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/interpreter/interpreter.dart
diff --git a/pkg/kernel/lib/interpreter/interpreter.dart b/pkg/kernel/lib/interpreter/interpreter.dart
index d06b82f8520c7d5224dab33e564c92dfadc73182..3fc588f13ee75e123a2b4691666e2d9e2b730d05 100644
--- a/pkg/kernel/lib/interpreter/interpreter.dart
+++ b/pkg/kernel/lib/interpreter/interpreter.dart
@@ -18,13 +18,13 @@ class NotImplemented {
}
class Interpreter {
- Program program;
- StatementExecuter visitor = new StatementExecuter();
-
// The execution of the program starts with empty main environment.
static MainEnvironment mainEnvironment =
new MainEnvironment(<Member, Location>{});
+ final Program program;
+ final StatementExecuter visitor = new StatementExecuter();
+
Interpreter(this.program);
void run() {
@@ -1577,9 +1577,36 @@ class CatchHandler extends ExceptionHandler {
CatchHandler(this.catches, this.environment, this.state);
Configuration call(Value exception, StackTrace stackTrace) {
+ if (catches.isEmpty) {
+ return new ThrowConfiguration(
+ state.exceptionComponents.handler, exception, stackTrace);
+ }
+
// TODO(zhivkag): Check if there is a matching catch clause instead.
- return new ThrowConfiguration(
- state.exceptionComponents.handler, exception, stackTrace);
+ var currentCatch = catches.first;
+ if (currentCatch.guard is DynamicType) {
+ // Exception is caught, execute the body.
+
+ var env = environment;
+ if (currentCatch.exception != null) {
+ env = env.extend(currentCatch.exception, exception);
+ }
+ if (currentCatch.stackTrace != null) {
+ env = env.extend(
+ currentCatch.stackTrace, new StringValue(stackTrace.toString()));
+ }
+ var ecs = new ExceptionComponents(state.exceptionComponents.handler,
+ state.exceptionComponents.stackTrace, stackTrace, exception);
+ var newState = new State.initial()
+ .withContinuation(state.continuation)
+ .withReturnContinuation(state.returnContinuation)
+ .withException(ecs);
+ return new ExecConfiguration(currentCatch.body, env, newState);
+ }
+
+ var catchHandler =
+ new CatchHandler(catches.skip(1).toList(), environment, state);
+ return new ThrowConfiguration(catchHandler, exception, stackTrace);
}
}
@@ -1661,7 +1688,7 @@ class StackTrace {
/// - It throws, in which case the handler is returned and applied accordingly.
class StatementExecuter
extends StatementVisitor1<Configuration, ExecConfiguration> {
- Evaluator evaluator = new Evaluator();
+ final Evaluator evaluator = new Evaluator();
void trampolinedExecution(Configuration configuration) {
while (configuration != null) {
« no previous file with comments | « no previous file | pkg/kernel/testcases/interpreter/try_catch_finally_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698