зеркало из https://github.com/mozilla/gecko-dev.git
Bug 978232 - ES6 Proxies: [[Construct]] must throw if the trap doesn't return an object. (r=jwalden)
This commit is contained in:
Родитель
648447a07f
Коммит
f8e717a96c
|
@ -1,6 +1,9 @@
|
|||
load(libdir + "asserts.js");
|
||||
/*
|
||||
* Call the trap with the handler as the this value, the target as the first
|
||||
* argument, and the original arguments as the third argument.
|
||||
*
|
||||
* Hooks that don't return an object must throw.
|
||||
*/
|
||||
var target = function () {};
|
||||
var handler = {
|
||||
|
@ -12,4 +15,4 @@ var handler = {
|
|||
assertEq(args[1], 3);
|
||||
}
|
||||
}
|
||||
assertEq(new (new Proxy(target, handler))(2, 3), undefined);
|
||||
assertThrowsInstanceOf(function () {new (new Proxy(target, handler))(2, 3)}, TypeError);
|
||||
|
|
|
@ -438,3 +438,4 @@ MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0
|
|||
MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}")
|
||||
MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}")
|
||||
MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target")
|
||||
MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object")
|
||||
|
|
|
@ -2348,7 +2348,13 @@ ScriptedDirectProxyHandler::construct(JSContext *cx, HandleObject proxy, const C
|
|||
ObjectValue(*argsArray)
|
||||
};
|
||||
RootedValue thisValue(cx, ObjectValue(*handler));
|
||||
return Invoke(cx, thisValue, trap, ArrayLength(constructArgv), constructArgv, args.rval());
|
||||
if (!Invoke(cx, thisValue, trap, ArrayLength(constructArgv), constructArgv, args.rval()))
|
||||
return false;
|
||||
if (!args.rval().isObject()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_PROXY_CONSTRUCT_OBJECT);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ScriptedDirectProxyHandler ScriptedDirectProxyHandler::singleton;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
function bogusConstruct(target) { return 4; }
|
||||
function bogusConstructUndefined(target) { }
|
||||
|
||||
var handler = { construct: bogusConstruct }
|
||||
|
||||
function callable() {}
|
||||
|
||||
var p = new Proxy(callable, handler);
|
||||
|
||||
assertThrowsInstanceOf(function () { new p(); }, TypeError,
|
||||
"[[Construct must throw if an object is not returned.");
|
||||
|
||||
handler.construct = bogusConstructUndefined;
|
||||
assertThrowsInstanceOf(function () { new p(); }, TypeError,
|
||||
"[[Construct must throw if an object is not returned.");
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(0,0, "OK");
|
Загрузка…
Ссылка в новой задаче