Revision: 15082
Author: [email protected]
Date: Wed Jun 12 05:37:44 2013
Log: For-of statements do not permit initializers.
[email protected]
BUG=v8:2720
Review URL: https://codereview.chromium.org/16739008
http://code.google.com/p/v8/source/detail?r=15082
Modified:
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/src/parser.h
/branches/bleeding_edge/src/preparser.cc
/branches/bleeding_edge/src/preparser.h
/branches/bleeding_edge/test/mjsunit/harmony/iteration-syntax.js
=======================================
--- /branches/bleeding_edge/src/parser.cc Fri Jun 7 04:12:21 2013
+++ /branches/bleeding_edge/src/parser.cc Wed Jun 12 05:37:44 2013
@@ -2624,11 +2624,13 @@
}
-bool Parser::CheckInOrOf(ForEachStatement::VisitMode* visit_mode) {
+bool Parser::CheckInOrOf(bool accept_OF,
+ ForEachStatement::VisitMode* visit_mode) {
if (Check(Token::IN)) {
*visit_mode = ForEachStatement::ENUMERATE;
return true;
- } else if (allow_for_of() && CheckContextualKeyword(CStrVector("of"))) {
+ } else if (allow_for_of() && accept_OF &&
+ CheckContextualKeyword(CStrVector("of"))) {
*visit_mode = ForEachStatement::ITERATE;
return true;
}
@@ -2726,11 +2728,14 @@
if (peek() == Token::VAR || peek() == Token::CONST) {
bool is_const = peek() == Token::CONST;
Handle<String> name;
+ VariableDeclarationProperties decl_props = kHasNoInitializers;
Block* variable_statement =
- ParseVariableDeclarations(kForStatement, NULL, NULL, &name,
CHECK_OK);
+ ParseVariableDeclarations(kForStatement, &decl_props, NULL,
&name,
+ CHECK_OK);
+ bool accept_OF = decl_props == kHasNoInitializers;
ForEachStatement::VisitMode mode;
- if (!name.is_null() && CheckInOrOf(&mode)) {
+ if (!name.is_null() && CheckInOrOf(accept_OF, &mode)) {
Interface* interface =
is_const ? Interface::NewConst() : Interface::NewValue();
ForEachStatement* loop = factory()->NewForEachStatement(mode,
labels);
@@ -2762,9 +2767,10 @@
ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name,
CHECK_OK);
bool accept_IN = !name.is_null() && decl_props != kHasInitializers;
+ bool accept_OF = decl_props == kHasNoInitializers;
ForEachStatement::VisitMode mode;
- if (accept_IN && CheckInOrOf(&mode)) {
+ if (accept_IN && CheckInOrOf(accept_OF, &mode)) {
// Rewrite a for-in statement of the form
//
// for (let x in e) b
@@ -2820,8 +2826,9 @@
} else {
Expression* expression = ParseExpression(false, CHECK_OK);
ForEachStatement::VisitMode mode;
+ bool accept_OF = expression->AsVariableProxy();
- if (CheckInOrOf(&mode)) {
+ if (CheckInOrOf(accept_OF, &mode)) {
// Signal a reference error if the expression is an invalid
// left-hand side expression. We could report this as a syntax
// error here but for compatibility with JSC we choose to report
=======================================
--- /branches/bleeding_edge/src/parser.h Fri Jun 7 04:12:21 2013
+++ /branches/bleeding_edge/src/parser.h Wed Jun 12 05:37:44 2013
@@ -729,7 +729,7 @@
bool is_generator() const { return
current_function_state_->is_generator(); }
- bool CheckInOrOf(ForEachStatement::VisitMode* visit_mode);
+ bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode*
visit_mode);
bool peek_any_identifier();
=======================================
--- /branches/bleeding_edge/src/preparser.cc Tue Jun 11 04:30:03 2013
+++ /branches/bleeding_edge/src/preparser.cc Wed Jun 12 05:37:44 2013
@@ -659,10 +659,9 @@
}
-bool PreParser::CheckInOrOf() {
+bool PreParser::CheckInOrOf(bool accept_OF) {
if (peek() == i::Token::IN ||
- (allow_for_of() &&
- peek() == i::Token::IDENTIFIER &&
+ (allow_for_of() && accept_OF && peek() == i::Token::IDENTIFIER &&
scanner_->is_next_contextual_keyword(v8::internal::CStrVector("of")))) {
Next();
return true;
@@ -685,9 +684,10 @@
VariableDeclarationProperties decl_props = kHasNoInitializers;
ParseVariableDeclarations(
kForStatement, &decl_props, &decl_count, CHECK_OK);
- bool accept_IN = decl_count == 1 &&
- !(is_let && decl_props == kHasInitializers);
- if (accept_IN && CheckInOrOf()) {
+ bool has_initializers = decl_props == kHasInitializers;
+ bool accept_IN = decl_count == 1 && !(is_let && has_initializers);
+ bool accept_OF = !has_initializers;
+ if (accept_IN && CheckInOrOf(accept_OF)) {
ParseExpression(true, CHECK_OK);
Expect(i::Token::RPAREN, CHECK_OK);
@@ -695,8 +695,8 @@
return Statement::Default();
}
} else {
- ParseExpression(false, CHECK_OK);
- if (CheckInOrOf()) {
+ Expression lhs = ParseExpression(false, CHECK_OK);
+ if (CheckInOrOf(lhs.IsIdentifier())) {
ParseExpression(true, CHECK_OK);
Expect(i::Token::RPAREN, CHECK_OK);
=======================================
--- /branches/bleeding_edge/src/preparser.h Thu Jun 6 07:38:26 2013
+++ /branches/bleeding_edge/src/preparser.h Wed Jun 12 05:37:44 2013
@@ -658,7 +658,7 @@
}
void ExpectSemicolon(bool* ok);
- bool CheckInOrOf();
+ bool CheckInOrOf(bool accept_OF);
static int Precedence(i::Token::Value tok, bool accept_IN);
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/iteration-syntax.js Thu
Jun 6 07:38:26 2013
+++ /branches/bleeding_edge/test/mjsunit/harmony/iteration-syntax.js Wed
Jun 12 05:37:44 2013
@@ -54,6 +54,11 @@
assertThrows("function f() { for (let of y) { } }", SyntaxError);
assertThrows("function f() { for (let of of) { } }", SyntaxError);
+assertThrows("function f() { for (x = 3 of y) { } }", SyntaxError);
+assertThrows("function f() { for (var x = 3 of y) { } }", SyntaxError);
+assertThrows("function f() { for (let x = 3 of y) { } }", SyntaxError);
+
+
// Alack, this appears to be valid.
function f() { for (of of y) { } }
function f() { for (let of of y) { } }
--
--
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/groups/opt_out.