Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1784)

Side by Side Diff: src/parsing/parser.cc

Issue 1602823003: [parser] Disallow Expression in for..of statements (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporating latest review feedback Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/parsing/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3658 matching lines...) Expand 10 before | Expand all | Expand 10 after
3669 // } 3669 // }
3670 // let x; // for TDZ 3670 // let x; // for TDZ
3671 // } 3671 // }
3672 3672
3673 Variable* temp = 3673 Variable* temp =
3674 scope_->NewTemporary(ast_value_factory()->dot_for_string()); 3674 scope_->NewTemporary(ast_value_factory()->dot_for_string());
3675 ForEachStatement* loop = 3675 ForEachStatement* loop =
3676 factory()->NewForEachStatement(mode, labels, stmt_pos); 3676 factory()->NewForEachStatement(mode, labels, stmt_pos);
3677 Target target(&this->target_stack_, loop); 3677 Target target(&this->target_stack_, loop);
3678 3678
3679 Expression* enumerable = ParseExpression(true, CHECK_OK); 3679 Expression* enumerable;
3680 if (mode == ForEachStatement::ITERATE) {
3681 ExpressionClassifier classifier;
3682 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK);
3683 enumerable = ParserTraits::RewriteNonPattern(enumerable, &classifier,
3684 CHECK_OK);
3685 } else {
3686 enumerable = ParseExpression(true, CHECK_OK);
3687 }
3680 3688
3681 Expect(Token::RPAREN, CHECK_OK); 3689 Expect(Token::RPAREN, CHECK_OK);
3682 3690
3683 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); 3691 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE);
3684 body_scope->set_start_position(scanner()->location().beg_pos); 3692 body_scope->set_start_position(scanner()->location().beg_pos);
3685 3693
3686 Block* body_block = 3694 Block* body_block =
3687 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); 3695 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition);
3688 3696
3689 { 3697 {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3784 if (!is_destructuring) { 3792 if (!is_destructuring) {
3785 expression = this->CheckAndRewriteReferenceExpression( 3793 expression = this->CheckAndRewriteReferenceExpression(
3786 expression, lhs_beg_pos, lhs_end_pos, 3794 expression, lhs_beg_pos, lhs_end_pos,
3787 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK); 3795 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK);
3788 } 3796 }
3789 3797
3790 ForEachStatement* loop = 3798 ForEachStatement* loop =
3791 factory()->NewForEachStatement(mode, labels, stmt_pos); 3799 factory()->NewForEachStatement(mode, labels, stmt_pos);
3792 Target target(&this->target_stack_, loop); 3800 Target target(&this->target_stack_, loop);
3793 3801
3794 Expression* enumerable = ParseExpression(true, CHECK_OK); 3802 Expression* enumerable;
3803 if (mode == ForEachStatement::ITERATE) {
3804 ExpressionClassifier classifier;
3805 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK);
3806 enumerable = ParserTraits::RewriteNonPattern(enumerable, &classifier,
3807 CHECK_OK);
3808 } else {
3809 enumerable = ParseExpression(true, CHECK_OK);
3810 }
3811
3795 Expect(Token::RPAREN, CHECK_OK); 3812 Expect(Token::RPAREN, CHECK_OK);
3796 3813
3797 // Make a block around the statement in case a lexical binding 3814 // Make a block around the statement in case a lexical binding
3798 // is introduced, e.g. by a FunctionDeclaration. 3815 // is introduced, e.g. by a FunctionDeclaration.
3799 // This block must not use for_scope as its scope because if a 3816 // This block must not use for_scope as its scope because if a
3800 // lexical binding is introduced which overlaps with the for-in/of, 3817 // lexical binding is introduced which overlaps with the for-in/of,
3801 // expressions in head of the loop should actually have variables 3818 // expressions in head of the loop should actually have variables
3802 // resolved in the outer scope. 3819 // resolved in the outer scope.
3803 Scope* body_scope = NewScope(for_scope, BLOCK_SCOPE); 3820 Scope* body_scope = NewScope(for_scope, BLOCK_SCOPE);
3804 BlockState block_state(&scope_, body_scope); 3821 BlockState block_state(&scope_, body_scope);
(...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after
5736 auto class_literal = value->AsClassLiteral(); 5753 auto class_literal = value->AsClassLiteral();
5737 if (class_literal->raw_name() == nullptr) { 5754 if (class_literal->raw_name() == nullptr) {
5738 class_literal->set_raw_name(name); 5755 class_literal->set_raw_name(name);
5739 } 5756 }
5740 } 5757 }
5741 } 5758 }
5742 5759
5743 5760
5744 } // namespace internal 5761 } // namespace internal
5745 } // namespace v8 5762 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698