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

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: 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') | test/mjsunit/es6/iteration-syntax.js » ('J')
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);
adamk 2016/01/19 22:21:47 Why no ValidateExpression() call here?
3683 } else {
3684 enumerable = ParseExpression(true, CHECK_OK);
3685 }
3680 3686
3681 Expect(Token::RPAREN, CHECK_OK); 3687 Expect(Token::RPAREN, CHECK_OK);
3682 3688
3683 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); 3689 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE);
3684 body_scope->set_start_position(scanner()->location().beg_pos); 3690 body_scope->set_start_position(scanner()->location().beg_pos);
3685 3691
3686 Block* body_block = 3692 Block* body_block =
3687 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); 3693 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition);
3688 3694
3689 { 3695 {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3784 if (!is_destructuring) { 3790 if (!is_destructuring) {
3785 expression = this->CheckAndRewriteReferenceExpression( 3791 expression = this->CheckAndRewriteReferenceExpression(
3786 expression, lhs_beg_pos, lhs_end_pos, 3792 expression, lhs_beg_pos, lhs_end_pos,
3787 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK); 3793 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK);
3788 } 3794 }
3789 3795
3790 ForEachStatement* loop = 3796 ForEachStatement* loop =
3791 factory()->NewForEachStatement(mode, labels, stmt_pos); 3797 factory()->NewForEachStatement(mode, labels, stmt_pos);
3792 Target target(&this->target_stack_, loop); 3798 Target target(&this->target_stack_, loop);
3793 3799
3794 Expression* enumerable = ParseExpression(true, CHECK_OK); 3800 Expression* enumerable;
3801 if (mode == ForEachStatement::ITERATE) {
3802 ExpressionClassifier classifier;
3803 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK);
adamk 2016/01/19 22:21:47 Same question down here?
3804 } else {
3805 enumerable = ParseExpression(true, CHECK_OK);
3806 }
3807
3795 Expect(Token::RPAREN, CHECK_OK); 3808 Expect(Token::RPAREN, CHECK_OK);
3796 3809
3797 // Make a block around the statement in case a lexical binding 3810 // Make a block around the statement in case a lexical binding
3798 // is introduced, e.g. by a FunctionDeclaration. 3811 // is introduced, e.g. by a FunctionDeclaration.
3799 // This block must not use for_scope as its scope because if a 3812 // 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, 3813 // lexical binding is introduced which overlaps with the for-in/of,
3801 // expressions in head of the loop should actually have variables 3814 // expressions in head of the loop should actually have variables
3802 // resolved in the outer scope. 3815 // resolved in the outer scope.
3803 Scope* body_scope = NewScope(for_scope, BLOCK_SCOPE); 3816 Scope* body_scope = NewScope(for_scope, BLOCK_SCOPE);
3804 BlockState block_state(&scope_, body_scope); 3817 BlockState block_state(&scope_, body_scope);
(...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after
5736 auto class_literal = value->AsClassLiteral(); 5749 auto class_literal = value->AsClassLiteral();
5737 if (class_literal->raw_name() == nullptr) { 5750 if (class_literal->raw_name() == nullptr) {
5738 class_literal->set_raw_name(name); 5751 class_literal->set_raw_name(name);
5739 } 5752 }
5740 } 5753 }
5741 } 5754 }
5742 5755
5743 5756
5744 } // namespace internal 5757 } // namespace internal
5745 } // namespace v8 5758 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/parsing/preparser.cc » ('j') | test/mjsunit/es6/iteration-syntax.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698