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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 2621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2632 | 2632 |
2633 // is_undefined ? this : is_object_conditional | 2633 // is_undefined ? this : is_object_conditional |
2634 return_value = factory()->NewConditional( | 2634 return_value = factory()->NewConditional( |
2635 is_undefined, ThisExpression(scope_, factory(), pos), | 2635 is_undefined, ThisExpression(scope_, factory(), pos), |
2636 is_object_conditional, pos); | 2636 is_object_conditional, pos); |
2637 } | 2637 } |
2638 | 2638 |
2639 // TODO(ishell): update chapter number. | 2639 // TODO(ishell): update chapter number. |
2640 // ES8 XX.YY.ZZ | 2640 // ES8 XX.YY.ZZ |
2641 if (tail_call_position >= 0) { | 2641 if (tail_call_position >= 0) { |
2642 if (!function_state_->collect_expressions_in_tail_position()) { | 2642 ReturnExprContext return_expr_context = |
| 2643 function_state_->return_expr_context(); |
| 2644 if (return_expr_context != ReturnExprContext::kNormal) { |
2643 Scanner::Location loc(tail_call_position, tail_call_position + 1); | 2645 Scanner::Location loc(tail_call_position, tail_call_position + 1); |
2644 ReportMessageAt(loc, MessageTemplate::kTailCallInTryBlock); | 2646 MessageTemplate::Template msg = |
| 2647 return_expr_context == ReturnExprContext::kInsideTryBlock |
| 2648 ? MessageTemplate::kTailCallInTryBlock |
| 2649 : MessageTemplate::kTailCallInForInOf; |
| 2650 ReportMessageAt(loc, msg); |
2645 *ok = false; | 2651 *ok = false; |
2646 return NULL; | 2652 return NULL; |
2647 } | 2653 } |
2648 function_state_->AddExpressionInTailPosition(return_value, | 2654 function_state_->AddExpressionInTailPosition(return_value, |
2649 tail_call_position); | 2655 tail_call_position); |
2650 | 2656 |
2651 } else if (allow_tailcalls() && !is_sloppy(language_mode())) { | 2657 } else if (allow_tailcalls() && !is_sloppy(language_mode())) { |
2652 // ES6 14.6.1 Static Semantics: IsInTailPosition | 2658 // ES6 14.6.1 Static Semantics: IsInTailPosition |
2653 function_state_->AddExpressionInTailPosition(return_value, pos); | 2659 function_state_->AddExpressionInTailPosition(return_value, pos); |
2654 } | 2660 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2841 // 'catch' '(' Identifier ')' Block | 2847 // 'catch' '(' Identifier ')' Block |
2842 // | 2848 // |
2843 // Finally :: | 2849 // Finally :: |
2844 // 'finally' Block | 2850 // 'finally' Block |
2845 | 2851 |
2846 Expect(Token::TRY, CHECK_OK); | 2852 Expect(Token::TRY, CHECK_OK); |
2847 int pos = position(); | 2853 int pos = position(); |
2848 | 2854 |
2849 Block* try_block; | 2855 Block* try_block; |
2850 { | 2856 { |
2851 DontCollectExpressionsInTailPositionScope no_tail_calls(function_state_); | 2857 ReturnExprScope no_tail_calls(function_state_, |
| 2858 ReturnExprContext::kInsideTryBlock); |
2852 try_block = ParseBlock(NULL, CHECK_OK); | 2859 try_block = ParseBlock(NULL, CHECK_OK); |
2853 } | 2860 } |
2854 | 2861 |
2855 Token::Value tok = peek(); | 2862 Token::Value tok = peek(); |
2856 if (tok != Token::CATCH && tok != Token::FINALLY) { | 2863 if (tok != Token::CATCH && tok != Token::FINALLY) { |
2857 ReportMessage(MessageTemplate::kNoCatchOrFinally); | 2864 ReportMessage(MessageTemplate::kNoCatchOrFinally); |
2858 *ok = false; | 2865 *ok = false; |
2859 return NULL; | 2866 return NULL; |
2860 } | 2867 } |
2861 | 2868 |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3548 | 3555 |
3549 Expect(Token::RPAREN, CHECK_OK); | 3556 Expect(Token::RPAREN, CHECK_OK); |
3550 | 3557 |
3551 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); | 3558 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); |
3552 body_scope->set_start_position(scanner()->location().beg_pos); | 3559 body_scope->set_start_position(scanner()->location().beg_pos); |
3553 | 3560 |
3554 Block* body_block = | 3561 Block* body_block = |
3555 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3562 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
3556 | 3563 |
3557 { | 3564 { |
3558 DontCollectExpressionsInTailPositionScope no_tail_calls( | 3565 ReturnExprScope no_tail_calls(function_state_, |
3559 function_state_); | 3566 ReturnExprContext::kInsideForInOfBody); |
3560 BlockState block_state(&scope_, body_scope); | 3567 BlockState block_state(&scope_, body_scope); |
3561 | 3568 |
3562 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); | 3569 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); |
3563 | 3570 |
3564 auto each_initialization_block = | 3571 auto each_initialization_block = |
3565 factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); | 3572 factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); |
3566 { | 3573 { |
3567 auto descriptor = parsing_result.descriptor; | 3574 auto descriptor = parsing_result.descriptor; |
3568 descriptor.declaration_pos = RelocInfo::kNoPosition; | 3575 descriptor.declaration_pos = RelocInfo::kNoPosition; |
3569 descriptor.initialization_pos = RelocInfo::kNoPosition; | 3576 descriptor.initialization_pos = RelocInfo::kNoPosition; |
(...skipping 3223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6793 try_block, target); | 6800 try_block, target); |
6794 final_loop = target; | 6801 final_loop = target; |
6795 } | 6802 } |
6796 | 6803 |
6797 return final_loop; | 6804 return final_loop; |
6798 } | 6805 } |
6799 | 6806 |
6800 | 6807 |
6801 } // namespace internal | 6808 } // namespace internal |
6802 } // namespace v8 | 6809 } // namespace v8 |
OLD | NEW |