Align PreParser for loop early error-checking with Parser

R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/1290193003

Cr-Commit-Position: refs/heads/master@{#30168}
This commit is contained in:
adamk 2015-08-13 12:10:59 -07:00 committed by Commit bot
parent 0584903167
commit 092b4317b2
3 changed files with 19 additions and 2 deletions

View File

@ -913,13 +913,16 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
return Statement::Default();
}
} else {
int lhs_beg_pos = peek_position();
Expression lhs = ParseExpression(false, CHECK_OK);
int lhs_end_pos = scanner()->location().end_pos;
is_let_identifier_expression =
lhs.IsIdentifier() && lhs.AsIdentifier().IsLet();
if (CheckInOrOf(lhs.IsIdentifier(), &mode, ok)) {
if (!*ok) return Statement::Default();
// TODO(adamk): Should call CheckAndRewriteReferenceExpression here
// to catch early errors if lhs is not a valid reference expression.
lhs = CheckAndRewriteReferenceExpression(
lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
CHECK_OK);
ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
ParseSubStatement(CHECK_OK);

View File

@ -0,0 +1,9 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// TODO(adamk): Remove flag after the test runner tests all message tests with
// the preparser: https://code.google.com/p/v8/issues/detail?id=4372
// Flags: --min-preparse-length=0
function f() { for ("unassignable" in {}); }

View File

@ -0,0 +1,5 @@
*%(basename)s:9: ReferenceError: Invalid left-hand side in for-loop
function f() { for ("unassignable" in {}); }
^^^^^^^^^^^^^^
ReferenceError: Invalid left-hand side in for-loop