Index: src/preparser.cc |
diff --git a/src/preparser.cc b/src/preparser.cc |
index 492ae7b214df79b0d804d35bc0a8c0ab5872d3fc..86d9d9bd34e50a1c06b045024348470b8ce82cf8 100644 |
--- a/src/preparser.cc |
+++ b/src/preparser.cc |
@@ -125,12 +125,18 @@ PreParser::Statement PreParser::ParseSourceElement(bool* ok) { |
// In harmony mode we allow additionally the following productions |
// SourceElement: |
// LetDeclaration |
+ // ConstDeclaration |
switch (peek()) { |
case i::Token::FUNCTION: |
return ParseFunctionDeclaration(ok); |
case i::Token::LET: |
return ParseVariableStatement(kSourceElement, ok); |
+ case i::Token::CONST: |
+ if (harmony_scoping_) { |
+ return ParseHarmonyConstDeclaration(ok); |
+ } |
+ // FALLTHROUGH |
default: |
return ParseStatement(ok); |
} |
@@ -335,6 +341,15 @@ PreParser::Statement PreParser::ParseVariableDeclarations( |
if (peek() == i::Token::VAR) { |
Consume(i::Token::VAR); |
} else if (peek() == i::Token::CONST) { |
+ if (harmony_scoping_) { |
+ ASSERT(var_context == kForStatement || |
+ var_context == kStatement); |
+ i::Scanner::Location location = scanner_->peek_location(); |
+ ReportMessageAt(location.beg_pos, location.end_pos, |
+ "unprotected_const", NULL); |
+ *ok = false; |
+ return Statement::Default(); |
+ } |
if (strict_mode()) { |
i::Scanner::Location location = scanner_->peek_location(); |
ReportMessageAt(location, "strict_const", NULL); |
@@ -386,6 +401,39 @@ PreParser::Statement PreParser::ParseVariableDeclarations( |
} |
+PreParser::Statement PreParser::ParseHarmonyConstDeclaration(bool* ok) { |
+ // ES6 Draft Rev3 |
+ // |
+ // ConstDeclaration :: |
+ // const ConstBinding (',' ConstBinding)* ';' |
+ // ConstBinding :: |
+ // Identifier '=' AssignmentExpression |
+ // |
+ // TODO(ES6): |
+ // ConstBinding :: |
+ // BindingPattern '=' AssignmentExpression |
+ |
+ Consume(i::Token::CONST); |
+ do { |
+ // Parse variable name. |
+ Identifier identifier = ParseIdentifier(CHECK_OK); |
+ if (!identifier.IsValidStrictVariable()) { |
+ StrictModeIdentifierViolation(scanner_->location(), |
+ "strict_var_name", |
+ identifier, |
+ ok); |
+ return Statement::Default(); |
+ } |
+ |
+ Expect(i::Token::ASSIGN, CHECK_OK); |
+ ParseAssignmentExpression(false, CHECK_OK); |
+ } while (Check(i::Token::COMMA)); |
+ |
+ ExpectSemicolon(CHECK_OK); |
+ return Statement::Default(); |
+} |
+ |
+ |
PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
// ExpressionStatement | LabelledStatement :: |
// Expression ';' |