Index: src/interpreter/bytecode-generator.cc |
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc |
index 596f718ead8d5c13bca9d23a8d6cee130f1ea79b..5f640854f751764938498f4fe2b33a00fc4c9543 100644 |
--- a/src/interpreter/bytecode-generator.cc |
+++ b/src/interpreter/bytecode-generator.cc |
@@ -917,20 +917,10 @@ void BytecodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { |
// TODO(mstarzinger): Implement this! |
// Create a catch scope that binds the exception. |
- register_allocator()->PrepareForConsecutiveAllocations(3); |
- Register name = register_allocator()->NextConsecutiveRegister(); |
- Register exception = register_allocator()->NextConsecutiveRegister(); |
- Register closure = register_allocator()->NextConsecutiveRegister(); |
- builder() |
- ->StoreAccumulatorInRegister(exception) |
- .LoadLiteral(stmt->variable()->name()) |
- .StoreAccumulatorInRegister(name); |
- VisitFunctionClosureForContext(); |
- builder()->StoreAccumulatorInRegister(closure).CallRuntime( |
- Runtime::kPushCatchContext, name, 3); |
+ VisitNewLocalCatchContext(stmt->variable()); |
// Evaluate the catch-block. |
- Visit(stmt->catch_block()); |
+ VisitInScope(stmt->catch_block(), stmt->scope()); |
try_control_builder.EndCatch(); |
} |
@@ -2128,6 +2118,27 @@ void BytecodeGenerator::VisitNewLocalBlockContext(Scope* scope) { |
} |
+void BytecodeGenerator::VisitNewLocalCatchContext(Variable* variable) { |
+ AccumulatorResultScope accumulator_execution_result(this); |
+ DCHECK(variable->IsContextSlot()); |
+ |
+ // Allocate a new local block context. |
+ register_allocator()->PrepareForConsecutiveAllocations(3); |
+ Register name = register_allocator()->NextConsecutiveRegister(); |
+ Register exception = register_allocator()->NextConsecutiveRegister(); |
+ Register closure = register_allocator()->NextConsecutiveRegister(); |
+ |
+ builder() |
+ ->StoreAccumulatorInRegister(exception) |
+ .LoadLiteral(variable->name()) |
+ .StoreAccumulatorInRegister(name); |
+ VisitFunctionClosureForContext(); |
+ builder()->StoreAccumulatorInRegister(closure).CallRuntime( |
+ Runtime::kPushCatchContext, name, 3); |
+ execution_result()->SetResultInAccumulator(); |
+} |
+ |
+ |
void BytecodeGenerator::VisitObjectLiteralAccessor( |
Register home_object, ObjectLiteralProperty* property, Register value_out) { |
// TODO(rmcilroy): Replace value_out with VisitForRegister(); |
@@ -2232,6 +2243,13 @@ Register BytecodeGenerator::VisitForRegisterValue(Expression* expr) { |
} |
+void BytecodeGenerator::VisitInScope(Statement* stmt, Scope* scope) { |
+ ContextScope context_scope(this, scope); |
+ DCHECK(scope->declarations()->is_empty()); |
+ Visit(stmt); |
+} |
+ |
+ |
Register BytecodeGenerator::NextContextRegister() const { |
if (execution_context() == nullptr) { |
// Return the incoming function context for the outermost execution context. |