Reviewers: rossberg,
Description:
Align PreParser for loop early error-checking with Parser
[email protected]
Please review this at https://codereview.chromium.org/1290193003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+19, -2 lines):
M src/preparser.cc
A test/message/for-loop-invalid-lhs.js
A test/message/for-loop-invalid-lhs.out
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index
f186f8a694927d1808d48167b4de31340973c9d1..9a30ca58cc71b18031b17ff9cd152e95826a50f1
100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -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);
Index: test/message/for-loop-invalid-lhs.js
diff --git a/test/message/for-loop-invalid-lhs.js
b/test/message/for-loop-invalid-lhs.js
new file mode 100644
index
0000000000000000000000000000000000000000..c545230348a8a73f60430673557d7c5ac1c467e9
--- /dev/null
+++ b/test/message/for-loop-invalid-lhs.js
@@ -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 {}); }
Index: test/message/for-loop-invalid-lhs.out
diff --git a/test/message/for-loop-invalid-lhs.out
b/test/message/for-loop-invalid-lhs.out
new file mode 100644
index
0000000000000000000000000000000000000000..105eb6461cb11e54f4e8f5c8176eea4b70a520ef
--- /dev/null
+++ b/test/message/for-loop-invalid-lhs.out
@@ -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
+
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.