From ff46e0c58c7f82d7eba3cd1122b2c58e200d9997 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 16:16:14 -0400 Subject: [PATCH] 1325606 - Return wrapped async function from caller property. --- js/src/jsfun.cpp | 4 +++ .../ecma_2017/AsyncFunctions/inner-caller.js | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 js/src/tests/ecma_2017/AsyncFunctions/inner-caller.js diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index ef5aea7688..06d5cced72 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -284,6 +284,8 @@ CallerGetterImpl(JSContext* cx, const CallArgs& args) } RootedObject caller(cx, iter.callee(cx)); + if (caller->is() && caller->as().isAsync()) + caller = GetWrappedAsyncFunction(&caller->as()); if (!cx->compartment()->wrap(cx, &caller)) return false; @@ -304,6 +306,8 @@ CallerGetterImpl(JSContext* cx, const CallArgs& args) } JSFunction* callerFun = &callerObj->as(); + if (IsWrappedAsyncFunction(callerFun)) + callerFun = GetUnwrappedAsyncFunction(callerFun); MOZ_ASSERT(!callerFun->isBuiltin(), "non-builtin iterator returned a builtin?"); if (callerFun->strict()) { diff --git a/js/src/tests/ecma_2017/AsyncFunctions/inner-caller.js b/js/src/tests/ecma_2017/AsyncFunctions/inner-caller.js new file mode 100644 index 0000000000..523eb79ead --- /dev/null +++ b/js/src/tests/ecma_2017/AsyncFunctions/inner-caller.js @@ -0,0 +1,26 @@ +var BUGNUMBER = 1185106; +var summary = "caller property of function inside async function should return wrapped async function"; + +print(BUGNUMBER + ": " + summary); + +(async function f() { + var inner = (function g() { + return g.caller; + })(); + assertEq(inner, f); +})(); + +(async function f() { + "use strict"; + try { + (function g() { + return g.caller; + })(); + assertEq(true, false); + } catch (e) { + assertEq(e instanceof TypeError, true); + } +})(); + +if (typeof reportCompare === "function") + reportCompare(true, true);