Reviewers: Erik Corry, Lasse Reichstein, Mads Ager,
Message:
const is a syntax error in strict mode.
Description:
Disable const in strict mode.
Using const in strict mode yields SyntaxError.
BUG=
TEST=test/mjsunit/strict-mode.js
Please review this at http://codereview.chromium.org/6592031/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/messages.js
M src/parser.cc
M test/mjsunit/strict-mode.js
Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index
b7e57aa228ea22f7db50da0fabb2aecd8445e5f7..f0efd5c3b21deb8f6390808752ce3b8e81a8f0c2
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);
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
249c9ced35309b935b441a8d917f149c017f5ef5..de3bcf9eeb3a1cc63139043ea7f3b3bd332ac039
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<const char*>::empty());
+ *ok = false;
+ return NULL;
+ }
mode = Variable::CONST;
is_const = true;
} else {
Index: test/mjsunit/strict-mode.js
diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js
index
ab3e535ec33055a8245ff5280c8b196a74170d3c..28a0455a60a06231b06bdefff4e35d044a2c81b9
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);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev