Bug 611276 - JSOP_CALLEE should push undefined, not null, for this. r=jimb
authorJeff Walden <jwalden@mit.edu>
Thu, 11 Nov 2010 12:33:46 -0800
changeset 57792 d6dd9376a3c27a22c7390e2a6fe4c2b61da3e919
parent 57791 557b1111ce4ec0384736d387b20c013762c82ad1
child 57793 d3f5185f03927e69dc7c29322294a00588ebc14c
push id17032
push userrsayre@mozilla.com
push dateWed, 17 Nov 2010 21:55:39 +0000
treeherdermozilla-central@78a42f77bb90 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs611276
milestone2.0b8pre
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
Bug 611276 - JSOP_CALLEE should push undefined, not null, for this. r=jimb
js/src/jsemit.cpp
js/src/tests/ecma_5/strict/jstests.list
js/src/tests/ecma_5/strict/this-for-function-expression-recursion.js
--- a/js/src/jsemit.cpp
+++ b/js/src/jsemit.cpp
@@ -2792,17 +2792,17 @@ EmitNameOp(JSContext *cx, JSCodeGenerato
             JS_ASSERT(op == JSOP_ARGUMENTS || op == JSOP_CALLEE);
             break;
         }
     }
 
     if (op == JSOP_ARGUMENTS || op == JSOP_CALLEE) {
         if (js_Emit1(cx, cg, op) < 0)
             return JS_FALSE;
-        if (callContext && js_Emit1(cx, cg, JSOP_NULL) < 0)
+        if (callContext && js_Emit1(cx, cg, JSOP_PUSH) < 0)
             return JS_FALSE;
     } else {
         if (!pn->pn_cookie.isFree()) {
             EMIT_UINT16_IMM_OP(op, pn->pn_cookie.asInteger());
         } else {
             if (!EmitAtomOp(cx, pn, op, cg))
                 return JS_FALSE;
         }
--- a/js/src/tests/ecma_5/strict/jstests.list
+++ b/js/src/tests/ecma_5/strict/jstests.list
@@ -31,8 +31,9 @@ script 15.5.5.2.js
 script 15.10.7.js
 script B.1.1.js
 script B.1.2.js
 script function-name-arity.js
 script primitive-this-no-writeback.js
 script regress-532254.js
 script regress-532041.js
 script unbrand-this.js
+script this-for-function-expression-recursion.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/strict/this-for-function-expression-recursion.js
@@ -0,0 +1,44 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+var gTestfile = 'this-for-function-expression-recursion.js';
+var BUGNUMBER = 611276;
+var summary = "JSOP_CALLEE should push undefined, not null, for this";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+// Calling a named function expression (not function statement) uses the
+// JSOP_CALLEE opcode.  This opcode pushes its own |this|, distinct from the
+// normal call path; verify that that |this| value is properly |undefined|.
+
+var calleeThisFun =
+  function calleeThisFun(recurring)
+  {
+    if (recurring)
+      return this;
+    return calleeThisFun(true);
+  };
+assertEq(calleeThisFun(false), this);
+
+var calleeThisStrictFun =
+  function calleeThisStrictFun(recurring)
+  {
+    "use strict";
+    if (recurring)
+      return this;
+    return calleeThisStrictFun(true);
+  };
+assertEq(calleeThisStrictFun(false), undefined);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("All tests passed!");