OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/ast.h" | 7 #include "src/ast.h" |
8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 Visit(stmt->catch_block()); | 1202 Visit(stmt->catch_block()); |
1203 } | 1203 } |
1204 // Restore the context. | 1204 // Restore the context. |
1205 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 1205 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
1206 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 1206 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
1207 scope_ = saved_scope; | 1207 scope_ = saved_scope; |
1208 __ jmp(&exit); | 1208 __ jmp(&exit); |
1209 | 1209 |
1210 // Try block code. Sets up the exception handler chain. | 1210 // Try block code. Sets up the exception handler chain. |
1211 __ bind(&try_entry); | 1211 __ bind(&try_entry); |
| 1212 |
| 1213 try_catch_depth_++; |
1212 EnterTryBlock(stmt->index(), &handler_entry); | 1214 EnterTryBlock(stmt->index(), &handler_entry); |
1213 { TryCatch try_body(this); | 1215 { TryCatch try_body(this); |
1214 Visit(stmt->try_block()); | 1216 Visit(stmt->try_block()); |
1215 } | 1217 } |
1216 ExitTryBlock(stmt->index()); | 1218 ExitTryBlock(stmt->index()); |
| 1219 try_catch_depth_--; |
1217 __ bind(&exit); | 1220 __ bind(&exit); |
1218 } | 1221 } |
1219 | 1222 |
1220 | 1223 |
1221 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | 1224 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
1222 Comment cmnt(masm_, "[ TryFinallyStatement"); | 1225 Comment cmnt(masm_, "[ TryFinallyStatement"); |
1223 SetStatementPosition(stmt); | 1226 SetStatementPosition(stmt); |
1224 // Try finally is compiled by setting up a try-handler on the stack while | 1227 // Try finally is compiled by setting up a try-handler on the stack while |
1225 // executing the try body, and removing it again afterwards. | 1228 // executing the try body, and removing it again afterwards. |
1226 // | 1229 // |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 Comment cmnt(masm_, "[ Throw"); | 1424 Comment cmnt(masm_, "[ Throw"); |
1422 VisitForStackValue(expr->exception()); | 1425 VisitForStackValue(expr->exception()); |
1423 SetSourcePosition(expr->position()); | 1426 SetSourcePosition(expr->position()); |
1424 __ CallRuntime(Runtime::kThrow, 1); | 1427 __ CallRuntime(Runtime::kThrow, 1); |
1425 // Never returns here. | 1428 // Never returns here. |
1426 } | 1429 } |
1427 | 1430 |
1428 | 1431 |
1429 void FullCodeGenerator::EnterTryBlock(int index, Label* handler) { | 1432 void FullCodeGenerator::EnterTryBlock(int index, Label* handler) { |
1430 handler_table()->SetRangeStart(index, masm()->pc_offset()); | 1433 handler_table()->SetRangeStart(index, masm()->pc_offset()); |
1431 handler_table()->SetRangeHandler(index, handler->pos()); | 1434 HandlerTable::CatchPrediction prediction = |
| 1435 try_catch_depth_ > 0 ? HandlerTable::CAUGHT : HandlerTable::UNCAUGHT; |
| 1436 handler_table()->SetRangeHandler(index, handler->pos(), prediction); |
1432 | 1437 |
1433 // Determine expression stack depth of try statement. | 1438 // Determine expression stack depth of try statement. |
1434 int stack_depth = info_->scope()->num_stack_slots(); // Include stack locals. | 1439 int stack_depth = info_->scope()->num_stack_slots(); // Include stack locals. |
1435 for (NestedStatement* current = nesting_stack_; current != NULL; /*nop*/) { | 1440 for (NestedStatement* current = nesting_stack_; current != NULL; /*nop*/) { |
1436 current = current->AccumulateDepth(&stack_depth); | 1441 current = current->AccumulateDepth(&stack_depth); |
1437 } | 1442 } |
1438 handler_table()->SetRangeDepth(index, stack_depth); | 1443 handler_table()->SetRangeDepth(index, stack_depth); |
1439 | 1444 |
1440 // Push context onto operand stack. | 1445 // Push context onto operand stack. |
1441 STATIC_ASSERT(TryBlockConstant::kElementCount == 1); | 1446 STATIC_ASSERT(TryBlockConstant::kElementCount == 1); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 } | 1642 } |
1638 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); | 1643 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); |
1639 codegen_->scope_ = saved_scope_; | 1644 codegen_->scope_ = saved_scope_; |
1640 } | 1645 } |
1641 | 1646 |
1642 | 1647 |
1643 #undef __ | 1648 #undef __ |
1644 | 1649 |
1645 | 1650 |
1646 } } // namespace v8::internal | 1651 } } // namespace v8::internal |
OLD | NEW |