Revision: 6780
Author: [email protected]
Date: Mon Feb 14 10:44:26 2011
Log: Strict mode delete of unqualified identifier.
SyntaxError is reported in strict mode when deleting
an unqualified identifier. (11.4.1 of Ecma-262 5th ed)
Review URL: http://codereview.chromium.org/6516003
http://code.google.com/p/v8/source/detail?r=6780
Modified:
/branches/bleeding_edge/src/messages.js
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/test/es5conform/es5conform.status
/branches/bleeding_edge/test/mjsunit/strict-mode.js
=======================================
--- /branches/bleeding_edge/src/messages.js Wed Feb 9 04:46:22 2011
+++ /branches/bleeding_edge/src/messages.js Mon Feb 14 10:44:26 2011
@@ -224,6 +224,7 @@
strict_lhs_postfix: ["Postfix increment/decrement may not
have eval or arguments operand in strict mode"],
strict_lhs_prefix: ["Prefix increment/decrement may not
have eval or arguments operand in strict mode"],
strict_reserved_word: ["Use of future reserved word in
strict mode"],
+ strict_delete: ["Delete of an unqualified identifier
in strict mode."],
};
}
var message_type = %MessageGetType(message);
=======================================
--- /branches/bleeding_edge/src/parser.cc Thu Feb 10 07:02:13 2011
+++ /branches/bleeding_edge/src/parser.cc Mon Feb 14 10:44:26 2011
@@ -2520,6 +2520,16 @@
default: break;
}
}
+
+ // "delete identifier" is a syntax error in strict mode.
+ if (op == Token::DELETE && temp_scope_->StrictMode()) {
+ VariableProxy* operand = expression->AsVariableProxy();
+ if (operand != NULL && !operand->is_this()) {
+ ReportMessage("strict_delete", Vector<const char*>::empty());
+ *ok = false;
+ return NULL;
+ }
+ }
return new UnaryOperation(op, expression);
=======================================
--- /branches/bleeding_edge/test/es5conform/es5conform.status Sun Feb 13
08:19:53 2011
+++ /branches/bleeding_edge/test/es5conform/es5conform.status Mon Feb 14
10:44:26 2011
@@ -359,16 +359,19 @@
# delete operator throws ReferenceError when deleting a direct reference
# to a var in strict mode
+# Invalid test case. Test expects ReferenceError instead of SyntaxError.
+# http://es5conform.codeplex.com/workitem/29084
chapter11/11.4/11.4.1/11.4.1-5-1-s: FAIL
# delete operator throws ReferenceError when deleting a direct reference
# to a function argument in strict mode
+# Invalid test case. Test expects ReferenceError instead of SyntaxError.
+# http://es5conform.codeplex.com/workitem/29084
chapter11/11.4/11.4.1/11.4.1-5-2-s: FAIL
# delete operator throws ReferenceError when deleting a direct reference
# to a function name in strict mode
+# Invalid test case. Test expects ReferenceError instead of SyntaxError.
+# http://es5conform.codeplex.com/workitem/29084
chapter11/11.4/11.4.1/11.4.1-5-3-s: FAIL
-# delete operator throws SyntaxError when deleting a direct reference
-# to a function argument(object) in strict mode
-chapter11/11.4/11.4.1/11.4.1-5-4-s: FAIL
# eval - a function declaring a var named 'eval' throws EvalError in
strict mode
# Invalid test case. SyntaxError should be expected instead of EvalError.
=======================================
--- /branches/bleeding_edge/test/mjsunit/strict-mode.js Sun Feb 13 08:19:53
2011
+++ /branches/bleeding_edge/test/mjsunit/strict-mode.js Mon Feb 14 10:44:26
2011
@@ -169,13 +169,20 @@
CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };",
SyntaxError);
CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError);
CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError);
-CheckStrictMode("var x = { 123: 1,
123.00000000000000000000000000000000000000000000000000000000000000000001 :
2 }", SyntaxError);
+CheckStrictMode("var x = { \
+ 123: 1, \
+
123.00000000000000000000000000000000000000000000000000000000000000000001: 2
\
+}", SyntaxError);
// Non-conflicting data properties.
(function StrictModeNonDuplicate() {
"use strict";
var x = { 123 : 1, "0123" : 2 };
- var x = { 123:
1, '123.00000000000000000000000000000000000000000000000000000000000000000001' :
2 }
+ var x = {
+ 123: 1,
+ '123.00000000000000000000000000000000000000000000000000000000000000000001':
+ 2
+ };
})();
// Two getters (non-strict)
@@ -214,23 +221,32 @@
CheckStrictMode("function strict() { eval = undefined; }", SyntaxError);
CheckStrictMode("function strict() { arguments = undefined; }",
SyntaxError);
CheckStrictMode("function strict() { print(eval = undefined); }",
SyntaxError);
-CheckStrictMode("function strict() { print(arguments = undefined); }",
SyntaxError);
+CheckStrictMode("function strict() { print(arguments = undefined); }",
+ SyntaxError);
CheckStrictMode("function strict() { var x = eval = undefined; }",
SyntaxError);
-CheckStrictMode("function strict() { var x = arguments = undefined; }",
SyntaxError);
+CheckStrictMode("function strict() { var x = arguments = undefined; }",
+ SyntaxError);
// Compound assignment to eval or arguments
CheckStrictMode("function strict() { eval *= undefined; }", SyntaxError);
CheckStrictMode("function strict() { arguments /= undefined; }",
SyntaxError);
CheckStrictMode("function strict() { print(eval %= undefined); }",
SyntaxError);
-CheckStrictMode("function strict() { print(arguments %= undefined); }",
SyntaxError);
-CheckStrictMode("function strict() { var x = eval += undefined; }",
SyntaxError);
-CheckStrictMode("function strict() { var x = arguments -= undefined; }",
SyntaxError);
+CheckStrictMode("function strict() { print(arguments %= undefined); }",
+ SyntaxError);
+CheckStrictMode("function strict() { var x = eval += undefined; }",
+ SyntaxError);
+CheckStrictMode("function strict() { var x = arguments -= undefined; }",
+ SyntaxError);
CheckStrictMode("function strict() { eval <<= undefined; }", SyntaxError);
CheckStrictMode("function strict() { arguments >>= undefined; }",
SyntaxError);
-CheckStrictMode("function strict() { print(eval >>>= undefined); }",
SyntaxError);
-CheckStrictMode("function strict() { print(arguments &= undefined); }",
SyntaxError);
-CheckStrictMode("function strict() { var x = eval ^= undefined; }",
SyntaxError);
-CheckStrictMode("function strict() { var x = arguments |= undefined; }",
SyntaxError);
+CheckStrictMode("function strict() { print(eval >>>= undefined); }",
+ SyntaxError);
+CheckStrictMode("function strict() { print(arguments &= undefined); }",
+ SyntaxError);
+CheckStrictMode("function strict() { var x = eval ^= undefined; }",
+ SyntaxError);
+CheckStrictMode("function strict() { var x = arguments |= undefined; }",
+ SyntaxError);
// Postfix increment with eval or arguments
CheckStrictMode("function strict() { eval++; }", SyntaxError);
@@ -264,6 +280,17 @@
CheckStrictMode("function strict() { var x = --eval; }", SyntaxError);
CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError);
+// Delete of an unqialified identifier
+CheckStrictMode("delete unqualified;", SyntaxError);
+CheckStrictMode("function strict() { delete unqualified; }", SyntaxError);
+CheckStrictMode("function function_name() { delete function_name; }",
+ SyntaxError);
+CheckStrictMode("function strict(parameter) { delete parameter; }",
+ SyntaxError);
+CheckStrictMode("function strict() { var variable; delete variable; }",
+ SyntaxError);
+CheckStrictMode("var variable; delete variable;", SyntaxError);
+
// Prefix unary operators other than delete, ++, -- are valid in strict
mode
(function StrictModeUnaryOperators() {
"use strict";
@@ -318,17 +345,22 @@
// Function names and arguments when the body is strict
assertThrows("function " + word + " () { 'use strict'; }", SyntaxError);
assertThrows("function foo (" + word + ") 'use strict'; {}",
SyntaxError);
- assertThrows("function foo (" + word + ", " + word + ") { 'use strict';
}", SyntaxError);
+ assertThrows("function foo (" + word + ", " + word + ") { 'use strict';
}",
+ SyntaxError);
assertThrows("function foo (a, " + word + ") { 'use strict'; }",
SyntaxError);
assertThrows("function foo (" + word + ", a) { 'use strict'; }",
SyntaxError);
- assertThrows("function foo (a, " + word + ", b) { 'use strict'; }",
SyntaxError);
- assertThrows("var foo = function (" + word + ") { 'use strict'; }",
SyntaxError);
+ assertThrows("function foo (a, " + word + ", b) { 'use strict'; }",
+ SyntaxError);
+ assertThrows("var foo = function (" + word + ") { 'use strict'; }",
+ SyntaxError);
// get/set when the body is strict
eval("var x = { get " + word + " () { 'use strict'; } };");
eval("var x = { set " + word + " (value) { 'use strict'; } };");
- assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };",
SyntaxError);
- assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };",
SyntaxError);
+ assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };",
+ SyntaxError);
+ assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };",
+ SyntaxError);
}
for (var i = 0; i < future_reserved_words.length; i++) {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev