Bug 1185106 - Part 12: Return wrapped function for arguments.callee. r=till
MozReview-Commit-ID: JxID0houuqK
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_7/AsyncFunctions/arguments_callee.js
@@ -0,0 +1,38 @@
+// |reftest| skip-if(!xulRuntime.shell) -- needs drainJobQueue
+
+var BUGNUMBER = 1185106;
+var summary = "arguments.callee in sloppy mode should return wrapped function";
+
+print(BUGNUMBER + ": " + summary);
+
+var test = `
+
+async function decl1() {
+ return arguments.callee;
+}
+assertEventuallyEq(decl1(), decl1);
+
+var expr1 = async function foo() {
+ return arguments.callee;
+};
+assertEventuallyEq(expr1(), expr1);
+
+var expr2 = async function() {
+ return arguments.callee;
+};
+assertEventuallyEq(expr2(), expr2);
+
+var obj = {
+ async method1() {
+ return arguments.callee;
+ }
+};
+assertEventuallyEq(obj.method1(), obj.method1);
+
+`;
+
+if (asyncFunctionsEnabled())
+ eval(test);
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
--- a/js/src/vm/ArgumentsObject.cpp
+++ b/js/src/vm/ArgumentsObject.cpp
@@ -4,16 +4,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "vm/ArgumentsObject-inl.h"
#include "mozilla/PodOperations.h"
#include "jit/JitFrames.h"
+#include "vm/AsyncFunction.h"
#include "vm/GlobalObject.h"
#include "vm/Stack.h"
#include "jsobjinlines.h"
#include "gc/Nursery-inl.h"
#include "vm/Stack-inl.h"
@@ -441,18 +442,23 @@ MappedArgGetter(JSContext* cx, HandleObj
unsigned arg = unsigned(JSID_TO_INT(id));
if (arg < argsobj.initialLength() && !argsobj.isElementDeleted(arg))
vp.set(argsobj.element(arg));
} else if (JSID_IS_ATOM(id, cx->names().length)) {
if (!argsobj.hasOverriddenLength())
vp.setInt32(argsobj.initialLength());
} else {
MOZ_ASSERT(JSID_IS_ATOM(id, cx->names().callee));
- if (!argsobj.hasOverriddenCallee())
- vp.setObject(argsobj.callee());
+ if (!argsobj.hasOverriddenCallee()) {
+ RootedFunction callee(cx, &argsobj.callee());
+ if (callee->isAsync())
+ vp.setObject(*GetWrappedAsyncFunction(callee));
+ else
+ vp.setObject(*callee);
+ }
}
return true;
}
static bool
MappedArgSetter(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp,
ObjectOpResult& result)
{