ES5 directives should not trigger 'useless expression' errors (559402, r=jimb).
authorBrendan Eich <brendan@mozilla.org>
Mon, 27 Dec 2010 13:10:25 -0800
changeset 60239 8ea7ed461dc03c2b75f7811a8b47b2f6239ad134
parent 60238 86285f568e0ce0c6bfd4158cb02703e909a6190b
child 60240 1073e19109bda1161d55a044d9b0c6378b3709eb
push id17896
push usercleary@mozilla.com
push dateSat, 08 Jan 2011 08:51:06 +0000
treeherdermozilla-central@df3c1150dd7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs559402
milestone2.0b9pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
ES5 directives should not trigger 'useless expression' errors (559402, r=jimb).
js/src/jsemit.cpp
js/src/tests/js1_8_5/regress/jstests.list
js/src/tests/js1_8_5/regress/regress-559402-1.js
js/src/tests/js1_8_5/regress/regress-559402-2.js
--- a/js/src/jsemit.cpp
+++ b/js/src/jsemit.cpp
@@ -6065,17 +6065,18 @@ js_EmitTree(JSContext *cx, JSCodeGenerat
              * Top-level or called-from-a-native JS_Execute/EvaluateScript,
              * debugger, and eval frames may need the value of the ultimate
              * expression statement as the script's result, despite the fact
              * that it appears useless to the compiler.
              *
              * API users may also set the JSOPTION_NO_SCRIPT_RVAL option when
              * calling JS_Compile* to suppress JSOP_POPV.
              */
-            useful = wantval = !(cg->flags & (TCF_IN_FUNCTION | TCF_NO_SCRIPT_RVAL));
+            wantval = !(cg->flags & (TCF_IN_FUNCTION | TCF_NO_SCRIPT_RVAL));
+            useful = wantval || pn->isDirectivePrologueMember();
             if (!useful) {
                 if (!CheckSideEffects(cx, cg, pn2, &useful))
                     return JS_FALSE;
             }
 
             /*
              * Don't eliminate apparently useless expressions if they are
              * labeled expression statements.  The tc->topStmt->update test
--- a/js/src/tests/js1_8_5/regress/jstests.list
+++ b/js/src/tests/js1_8_5/regress/jstests.list
@@ -10,16 +10,18 @@ script regress-541455.js
 script regress-546615.js
 script regress-551763-0.js
 script regress-551763-1.js
 script regress-551763-2.js
 script regress-552432.js
 script regress-553778.js
 script regress-555246-0.js
 script regress-555246-1.js
+script regress-559402-1.js
+script regress-559402-2.js
 script regress-559438.js
 script regress-560101.js
 script regress-560998-1.js
 script regress-560998-2.js
 script regress-563210.js
 script regress-563221.js
 script regress-566549.js
 script regress-566914.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/regress/regress-559402-1.js
@@ -0,0 +1,22 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+var expect = "No error";
+var actual = expect;
+
+if (typeof options == "function") {
+    var opts = options();
+    if (!/\bstrict\b/.test(opts))
+        options("strict");
+    if (!/\bwerror\b/.test(opts))
+        options("werror");
+}
+
+try {
+    eval('function foo() { "use strict"; }');
+} catch (e) {
+    actual = '' + e;
+}
+
+reportCompare(expect, actual, "ok");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/regress/regress-559402-2.js
@@ -0,0 +1,8 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+var expect = undefined;
+var actual = (function foo() { "bogus"; })();
+
+reportCompare(expect, actual, "ok");