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

Unified Diff: src/preparser.cc

Issue 7992005: Block scoped const variables. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
« src/parser.cc ('K') | « src/preparser.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ';'
« src/parser.cc ('K') | « src/preparser.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698