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/parser.h" | 5 #include "src/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 3775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3786 | 3786 |
3787 ForEachStatement* loop = | 3787 ForEachStatement* loop = |
3788 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3788 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3789 Target target(&this->target_stack_, loop); | 3789 Target target(&this->target_stack_, loop); |
3790 | 3790 |
3791 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3791 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3792 Expect(Token::RPAREN, CHECK_OK); | 3792 Expect(Token::RPAREN, CHECK_OK); |
3793 | 3793 |
3794 // Make a block around the statement in case a lexical binding | 3794 // Make a block around the statement in case a lexical binding |
3795 // is introduced, e.g. by a FunctionDeclaration. | 3795 // is introduced, e.g. by a FunctionDeclaration. |
| 3796 // This block must not use for_scope as its scope because if a |
| 3797 // lexical binding is introduced which overlaps with the for-in/of, |
| 3798 // expressions in head of the loop should actually have variables |
| 3799 // resolved in the outer scope. |
| 3800 Scope* body_scope = NewScope(for_scope, BLOCK_SCOPE); |
| 3801 scope_ = body_scope; |
3796 Block* block = | 3802 Block* block = |
3797 factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); | 3803 factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); |
3798 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3804 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3799 block->statements()->Add(body, zone()); | 3805 block->statements()->Add(body, zone()); |
3800 InitializeForEachStatement(loop, expression, enumerable, block); | 3806 InitializeForEachStatement(loop, expression, enumerable, block); |
3801 scope_ = saved_scope; | 3807 scope_ = saved_scope; |
| 3808 body_scope->set_end_position(scanner()->location().end_pos); |
| 3809 body_scope = body_scope->FinalizeBlockScope(); |
| 3810 if (body_scope != nullptr) { |
| 3811 block->set_scope(body_scope); |
| 3812 } |
3802 for_scope->set_end_position(scanner()->location().end_pos); | 3813 for_scope->set_end_position(scanner()->location().end_pos); |
3803 for_scope = for_scope->FinalizeBlockScope(); | 3814 for_scope = for_scope->FinalizeBlockScope(); |
3804 if (for_scope != nullptr) { | 3815 DCHECK(for_scope == nullptr); |
3805 block->set_scope(for_scope); | |
3806 } | |
3807 // Parsed for-in loop. | 3816 // Parsed for-in loop. |
3808 return loop; | 3817 return loop; |
3809 | 3818 |
3810 } else { | 3819 } else { |
3811 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); | 3820 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); |
3812 } | 3821 } |
3813 } | 3822 } |
3814 } | 3823 } |
3815 | 3824 |
3816 // Standard 'for' loop | 3825 // Standard 'for' loop |
(...skipping 2520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6337 | 6346 |
6338 Expression* Parser::SpreadCallNew(Expression* function, | 6347 Expression* Parser::SpreadCallNew(Expression* function, |
6339 ZoneList<v8::internal::Expression*>* args, | 6348 ZoneList<v8::internal::Expression*>* args, |
6340 int pos) { | 6349 int pos) { |
6341 args->InsertAt(0, function, zone()); | 6350 args->InsertAt(0, function, zone()); |
6342 | 6351 |
6343 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6352 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6344 } | 6353 } |
6345 } // namespace internal | 6354 } // namespace internal |
6346 } // namespace v8 | 6355 } // namespace v8 |
OLD | NEW |