Bug 514572: Forbid deletion of variables, arguments and functions in ES5 strict mode. r=jorendorff
authorJim Blandy <jimb@mozilla.org>
Thu, 19 Nov 2009 12:35:55 -0800
changeset 35311 b23078c3e55afba4d277f197a0d8a24bff6bcef0
parent 35310 37c3734c11f8d9a01fe9f685ede03b13fb4da75b
child 35312 2ed4651b95a9265af9ead428374486ea5d87679b
push id10560
push userrsayre@mozilla.com
push dateTue, 01 Dec 2009 18:15:12 +0000
treeherdermozilla-central@e2860a4dcf0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs514572
milestone1.9.3a1pre
Bug 514572: Forbid deletion of variables, arguments and functions in ES5 strict mode. r=jorendorff
js/src/js.msg
js/src/jsparse.cpp
js/src/tests/ecma_5/strict/11.4.1.js
js/src/tests/ecma_5/strict/jstests.list
--- a/js/src/js.msg
+++ b/js/src/js.msg
@@ -309,8 +309,9 @@ MSG_DEF(JSMSG_EVAL_ARITY,             22
 MSG_DEF(JSMSG_MISSING_FUN_ARG,        227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}")
 MSG_DEF(JSMSG_JSON_BAD_PARSE,         228, 0, JSEXN_SYNTAXERR, "JSON.parse")
 MSG_DEF(JSMSG_JSON_BAD_STRINGIFY,     229, 0, JSEXN_ERR, "JSON.stringify")
 MSG_DEF(JSMSG_XDR_CLOSURE_WRAPPER,    230, 1, JSEXN_INTERNALERR, "can't XDR closure wrapper for function {0}")
 MSG_DEF(JSMSG_NOT_NONNULL_OBJECT,     231, 0, JSEXN_TYPEERR, "value is not a non-null object")
 MSG_DEF(JSMSG_DEPRECATED_OCTAL,       232, 0, JSEXN_SYNTAXERR, "octal literals and octal escape sequences are deprecated")
 MSG_DEF(JSMSG_STRICT_CODE_WITH,       233, 0, JSEXN_SYNTAXERR, "strict mode code may not contain 'with' statements")
 MSG_DEF(JSMSG_DUPLICATE_PROPERTY,     234, 1, JSEXN_SYNTAXERR, "property name {0} appears more than once in object literal")
+MSG_DEF(JSMSG_DEPRECATED_DELETE_OPERAND, 235, 0, JSEXN_SYNTAXERR, "Applying the 'delete' operator to an unqualified name is deprecated")
--- a/js/src/jsparse.cpp
+++ b/js/src/jsparse.cpp
@@ -6248,16 +6248,18 @@ UnaryExpr(JSContext *cx, JSTokenStream *
         switch (pn2->pn_type) {
           case TOK_LP:
             if (pn2->pn_op != JSOP_SETCALL &&
                 !MakeSetCall(cx, pn2, tc, JSMSG_BAD_DELETE_OPERAND)) {
                 return NULL;
             }
             break;
           case TOK_NAME:
+            if (!js_ReportStrictModeError(cx, ts, tc, pn, JSMSG_DEPRECATED_DELETE_OPERAND))
+                return NULL;
             pn2->pn_op = JSOP_DELNAME;
             break;
           default:;
         }
         pn->pn_kid = pn2;
         break;
 
       case TOK_ERROR:
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/strict/11.4.1.js
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+/* Deleting an identifier is a syntax error in strict mode code only. */
+assertEq(testLenientAndStrict('delete x;',
+                              parsesSuccessfully,
+                              parseRaisesException(SyntaxError)),
+         true);
+
+/*
+ * A reference expression surrounded by parens is itself a reference
+ * expression.
+ */
+assertEq(testLenientAndStrict('delete (x);',
+                              parsesSuccessfully,
+                              parseRaisesException(SyntaxError)),
+         true);
+
+/* Deleting other sorts of expressions are not syntax errors in either mode. */
+assertEq(testLenientAndStrict('delete x.y;',
+                              parsesSuccessfully,
+                              parsesSuccessfully),
+         true);
+
+/* Functions should inherit the surrounding code's strictness. */
+assertEq(testLenientAndStrict('function f() { delete x; }',
+                              parsesSuccessfully,
+                              parseRaisesException(SyntaxError)),
+         true);
+
+/* Local directives override the surrounding code's strictness. */
+assertEq(testLenientAndStrict('function f() { "use strict"; delete x; }',
+                              parseRaisesException(SyntaxError),
+                              parseRaisesException(SyntaxError)),
+         true);
--- a/js/src/tests/ecma_5/strict/jstests.list
+++ b/js/src/tests/ecma_5/strict/jstests.list
@@ -1,7 +1,8 @@
 url-prefix ../../jsreftest.html?test=ecma_5/strict/
 script 8.7.2.js
 script 10.4.2.js
 script 11.1.5.js
+script 11.4.1.js
 script 12.10.1.js
 script B.1.1.js
 script B.1.2.js