From 180b6ec6b4349bedd9472c93e6978fb6e4918dce Mon Sep 17 00:00:00 2001 From: "mmaly@chromium.org" Date: Mon, 28 Feb 2011 18:38:17 +0000 Subject: [PATCH] Disable const in strict mode. Using const in strict mode yields SyntaxError. Review URL: http://codereview.chromium.org/6592031/ git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6974 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/messages.js | 1 + src/parser.cc | 5 +++++ test/mjsunit/strict-mode.js | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/messages.js b/src/messages.js index 3f73706..7c74abc 100644 --- a/src/messages.js +++ b/src/messages.js @@ -226,6 +226,7 @@ function FormatMessage(message) { strict_reserved_word: ["Use of future reserved word in strict mode"], strict_delete: ["Delete of an unqualified identifier in strict mode."], strict_delete_property: ["Cannot delete property '", "%0", "' of ", "%1"], + strict_const: ["Use of const in strict mode."], }; } var message_type = %MessageGetType(message); diff --git a/src/parser.cc b/src/parser.cc index 249c9ce..de3bcf9 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -1515,6 +1515,11 @@ Block* Parser::ParseVariableDeclarations(bool accept_IN, Consume(Token::VAR); } else if (peek() == Token::CONST) { Consume(Token::CONST); + if (temp_scope_->StrictMode()) { + ReportMessage("strict_const", Vector::empty()); + *ok = false; + return NULL; + } mode = Variable::CONST; is_const = true; } else { diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js index ab3e535..28a0455 100644 --- a/test/mjsunit/strict-mode.js +++ b/test/mjsunit/strict-mode.js @@ -280,6 +280,11 @@ CheckStrictMode("function strict() { print(--arguments); }", SyntaxError); CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); +// Use of const in strict mode is disallowed in anticipation of ES Harmony. +CheckStrictMode("const x = 0;", SyntaxError); +CheckStrictMode("for (const x = 0; false;) {}", SyntaxError); +CheckStrictMode("function strict() { const x = 0; }", SyntaxError); + // Delete of an unqualified identifier CheckStrictMode("delete unqualified;", SyntaxError); CheckStrictMode("function strict() { delete unqualified; }", SyntaxError); -- 2.7.4