Bug 1325606 - Return wrapped async function from caller property. r=jwalden

This commit is contained in:
Tooru Fujisawa 2017-01-05 17:09:23 +09:00
Родитель d7971f4aa5
Коммит 00069dd84f
2 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@ -284,6 +284,8 @@ CallerGetterImpl(JSContext* cx, const CallArgs& args)
}
RootedObject caller(cx, iter.callee(cx));
if (caller->is<JSFunction>() && caller->as<JSFunction>().isAsync())
caller = GetWrappedAsyncFunction(&caller->as<JSFunction>());
if (!cx->compartment()->wrap(cx, &caller))
return false;
@ -298,6 +300,8 @@ CallerGetterImpl(JSContext* cx, const CallArgs& args)
}
JSFunction* callerFun = &callerObj->as<JSFunction>();
if (IsWrappedAsyncFunction(callerFun))
callerFun = GetUnwrappedAsyncFunction(callerFun);
MOZ_ASSERT(!callerFun->isBuiltin(), "non-builtin iterator returned a builtin?");
if (callerFun->strict()) {
@ -351,6 +355,10 @@ CallerSetterImpl(JSContext* cx, const CallArgs& args)
return true;
RootedObject caller(cx, iter.callee(cx));
// |caller| is only used for security access-checking and for its
// strictness. An unwrapped async function has its wrapped async
// function's security access and strictness, so don't bother calling
// |GetUnwrappedAsyncFunction|.
if (!cx->compartment()->wrap(cx, &caller)) {
cx->clearPendingException();
return true;

Просмотреть файл

@ -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);