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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2654 if (mode == ForEachStatement::ITERATE) { | 2654 if (mode == ForEachStatement::ITERATE) { |
2655 ExpressionClassifier classifier(this); | 2655 ExpressionClassifier classifier(this); |
2656 enumerable = ParseAssignmentExpression(true, CHECK_OK); | 2656 enumerable = ParseAssignmentExpression(true, CHECK_OK); |
2657 RewriteNonPattern(CHECK_OK); | 2657 RewriteNonPattern(CHECK_OK); |
2658 } else { | 2658 } else { |
2659 enumerable = ParseExpression(true, CHECK_OK); | 2659 enumerable = ParseExpression(true, CHECK_OK); |
2660 } | 2660 } |
2661 | 2661 |
2662 Expect(Token::RPAREN, CHECK_OK); | 2662 Expect(Token::RPAREN, CHECK_OK); |
2663 | 2663 |
2664 // For legacy compat reasons, give for loops similar treatment to | 2664 { |
2665 // if statements in allowing a function declaration for a body | 2665 ReturnExprScope no_tail_calls(function_state_, |
2666 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); | 2666 ReturnExprContext::kInsideForInOfBody); |
2667 Statement* final_loop = InitializeForEachStatement( | 2667 BlockState block_state(&scope_state_); |
2668 loop, expression, enumerable, body, each_keyword_position); | 2668 block_state.set_start_position(scanner()->location().beg_pos); |
2669 | 2669 |
2670 DCHECK_NULL(for_state.FinalizedBlockScope()); | 2670 // For legacy compat reasons, give for loops similar treatment to |
2671 return final_loop; | 2671 // if statements in allowing a function declaration for a body |
| 2672 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); |
| 2673 block_state.set_end_position(scanner()->location().end_pos); |
| 2674 Statement* final_loop = InitializeForEachStatement( |
| 2675 loop, expression, enumerable, body, each_keyword_position); |
2672 | 2676 |
| 2677 DCHECK_NULL(for_state.FinalizedBlockScope()); |
| 2678 return final_loop; |
| 2679 } |
2673 } else { | 2680 } else { |
2674 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); | 2681 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); |
2675 } | 2682 } |
2676 } | 2683 } |
2677 } | 2684 } |
2678 | 2685 |
2679 // Standard 'for' loop | 2686 // Standard 'for' loop |
2680 ForStatement* loop = factory()->NewForStatement(labels, stmt_pos); | 2687 ForStatement* loop = factory()->NewForStatement(labels, stmt_pos); |
2681 ParserTarget target(this, loop); | 2688 ParserTarget target(this, loop); |
2682 | 2689 |
(...skipping 2944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5627 node->Print(Isolate::Current()); | 5634 node->Print(Isolate::Current()); |
5628 } | 5635 } |
5629 #endif // DEBUG | 5636 #endif // DEBUG |
5630 | 5637 |
5631 #undef CHECK_OK | 5638 #undef CHECK_OK |
5632 #undef CHECK_OK_VOID | 5639 #undef CHECK_OK_VOID |
5633 #undef CHECK_FAILED | 5640 #undef CHECK_FAILED |
5634 | 5641 |
5635 } // namespace internal | 5642 } // namespace internal |
5636 } // namespace v8 | 5643 } // namespace v8 |
OLD | NEW |