Reviewers: Lasse Reichstein, Mads Ager,

Message:
Delete of an unqualified identifier is a syntax error.

Description:
Strict mode delete of unqualified identifier.
SyntaxError is reported in strict mode when deleting an unqualified identifier.
(11.4.1 of Ecma-262 5th Edition)


BUG=
TEST=test/mjsunit/strict-mode.js

Please review this at http://codereview.chromium.org/6516003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/messages.js
  M src/parser.cc
  M test/es5conform/es5conform.status
  M test/mjsunit/strict-mode.js


Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index 1e41b178ccfdf0aef09727cfe93f6fa9803871db..ac7962c5cd2c5d257a1f56d3cff7c962f1928984 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -224,6 +224,7 @@ function FormatMessage(message) {
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);
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 04d510f2fdcf174fe9615e7e871fc20ae236ff2d..036ec4060d06f8db001e632d1e2e0bcdd87b2f77 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2521,6 +2521,16 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
       }
     }

+    // "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);

   } else if (Token::IsCountOp(op)) {
Index: test/es5conform/es5conform.status
diff --git a/test/es5conform/es5conform.status b/test/es5conform/es5conform.status index 39754ca57dacf43d1e6fa40b1065606277306fe6..4cf01187211341201255eb777436a0ca13381553 100644
--- a/test/es5conform/es5conform.status
+++ b/test/es5conform/es5conform.status
@@ -359,16 +359,19 @@ chapter11/11.4/11.4.1/11.4.1-4.a-9-s: FAIL

 # 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.
Index: test/mjsunit/strict-mode.js
diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js
index 6b775fcb049409469a423e7ad58a1fd7582cb644..8baaea9429e381bc67215746218683ddb0875939 100644
--- a/test/mjsunit/strict-mode.js
+++ b/test/mjsunit/strict-mode.js
@@ -264,6 +264,14 @@ CheckStrictMode("function strict() { print(--arguments); }", SyntaxError);
 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";


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to