mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 21:35:39 +00:00
Bug 1072817 - Minor adjustments (primarily for method-ordering) as a followup to making accessing the [[Prototype]] of a revoked proxy not crash. Also add another test. r=trivial
--HG-- extra : rebase_source : 4bc4c0b872a5ef2b8a4ae563b2ff44a246a838e3
This commit is contained in:
parent
5f774f10ac
commit
5573b02492
@ -328,6 +328,35 @@ ScriptedDirectProxyHandler::preventExtensions(JSContext *cx, HandleObject proxy)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ES6 implements both getPrototypeOf and setPrototypeOf traps. We don't have them yet (see bug
|
||||||
|
// 888969). For now, use these, to account for proxy revocation.
|
||||||
|
bool
|
||||||
|
ScriptedDirectProxyHandler::getPrototypeOf(JSContext *cx, HandleObject proxy,
|
||||||
|
MutableHandleObject protop) const
|
||||||
|
{
|
||||||
|
RootedObject target(cx, proxy->as<ProxyObject>().target());
|
||||||
|
// Though handler is used elsewhere, spec mandates that both get set to null.
|
||||||
|
if (!target) {
|
||||||
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DirectProxyHandler::getPrototypeOf(cx, proxy, protop);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ScriptedDirectProxyHandler::setPrototypeOf(JSContext *cx, HandleObject proxy,
|
||||||
|
HandleObject proto, bool *bp) const
|
||||||
|
{
|
||||||
|
RootedObject target(cx, proxy->as<ProxyObject>().target());
|
||||||
|
if (!target) {
|
||||||
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DirectProxyHandler::setPrototypeOf(cx, proxy, proto, bp);
|
||||||
|
}
|
||||||
|
|
||||||
// Corresponds to the "standard" property descriptor getOwn getPrototypeOf dance. It's so explicit
|
// Corresponds to the "standard" property descriptor getOwn getPrototypeOf dance. It's so explicit
|
||||||
// here because ScriptedDirectProxyHandler allows script visibility for this operation.
|
// here because ScriptedDirectProxyHandler allows script visibility for this operation.
|
||||||
bool
|
bool
|
||||||
@ -1090,35 +1119,6 @@ ScriptedDirectProxyHandler::isCallable(JSObject *obj) const
|
|||||||
return obj->as<ProxyObject>().extra(IS_CALLABLE_EXTRA).toBoolean();
|
return obj->as<ProxyObject>().extra(IS_CALLABLE_EXTRA).toBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ES6 implements both getPrototypeOf and setPrototypeOf traps. We don't have them yet (see bug
|
|
||||||
// 888969). For now, use these, to account for proxy revocation.
|
|
||||||
bool
|
|
||||||
ScriptedDirectProxyHandler::getPrototypeOf(JSContext *cx, HandleObject proxy,
|
|
||||||
MutableHandleObject protop) const
|
|
||||||
{
|
|
||||||
RootedObject target(cx, proxy->as<ProxyObject>().target());
|
|
||||||
// Though handler is used elsewhere, spec mandates that both get set to null.
|
|
||||||
if (!target) {
|
|
||||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return DirectProxyHandler::getPrototypeOf(cx, proxy, protop);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ScriptedDirectProxyHandler::setPrototypeOf(JSContext *cx, HandleObject proxy,
|
|
||||||
HandleObject proto, bool *bp) const
|
|
||||||
{
|
|
||||||
RootedObject target(cx, proxy->as<ProxyObject>().target());
|
|
||||||
if (!target) {
|
|
||||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return DirectProxyHandler::setPrototypeOf(cx, proxy, proto, bp);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char ScriptedDirectProxyHandler::family = 0;
|
const char ScriptedDirectProxyHandler::family = 0;
|
||||||
const ScriptedDirectProxyHandler ScriptedDirectProxyHandler::singleton;
|
const ScriptedDirectProxyHandler ScriptedDirectProxyHandler::singleton;
|
||||||
|
|
||||||
|
@ -29,6 +29,13 @@ class ScriptedDirectProxyHandler : public DirectProxyHandler {
|
|||||||
virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const MOZ_OVERRIDE;
|
virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const MOZ_OVERRIDE;
|
||||||
virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE;
|
virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE;
|
||||||
virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE;
|
virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE;
|
||||||
|
|
||||||
|
/* These two are standard internal methods but aren't implemented to spec yet. */
|
||||||
|
virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy,
|
||||||
|
MutableHandleObject protop) const MOZ_OVERRIDE;
|
||||||
|
virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto,
|
||||||
|
bool *bp) const MOZ_OVERRIDE;
|
||||||
|
|
||||||
virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const MOZ_OVERRIDE;
|
virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const MOZ_OVERRIDE;
|
||||||
virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id,
|
virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id,
|
||||||
MutableHandleValue vp) const MOZ_OVERRIDE;
|
MutableHandleValue vp) const MOZ_OVERRIDE;
|
||||||
@ -36,11 +43,6 @@ class ScriptedDirectProxyHandler : public DirectProxyHandler {
|
|||||||
bool strict, MutableHandleValue vp) const MOZ_OVERRIDE;
|
bool strict, MutableHandleValue vp) const MOZ_OVERRIDE;
|
||||||
virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE;
|
virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE;
|
||||||
virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE;
|
virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE;
|
||||||
// These are standard internal methods, but are not implemented to spec yet.
|
|
||||||
virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop)
|
|
||||||
const MOZ_OVERRIDE;
|
|
||||||
virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp)
|
|
||||||
const MOZ_OVERRIDE;
|
|
||||||
|
|
||||||
/* SpiderMonkey extensions. */
|
/* SpiderMonkey extensions. */
|
||||||
virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id,
|
virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id,
|
||||||
|
40
js/src/tests/ecma_6/Proxy/revocable-proxy-prototype.js
Normal file
40
js/src/tests/ecma_6/Proxy/revocable-proxy-prototype.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/licenses/publicdomain/
|
||||||
|
*/
|
||||||
|
|
||||||
|
var gTestfile = 'revocable-proxy-prototype.js';
|
||||||
|
var BUGNUMBER = 1052139;
|
||||||
|
var summary = "Accessing a revocable proxy's [[Prototype]] shouldn't crash";
|
||||||
|
|
||||||
|
print(BUGNUMBER + ": " + summary);
|
||||||
|
|
||||||
|
/**************
|
||||||
|
* BEGIN TEST *
|
||||||
|
**************/
|
||||||
|
function checkFunctionAppliedToRevokedProxy(fun)
|
||||||
|
{
|
||||||
|
var p = Proxy.revocable({}, {});
|
||||||
|
p.revoke();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fun(p.proxy);
|
||||||
|
throw "didn't throw";
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
assertEq(e instanceof TypeError, true,
|
||||||
|
"expected TypeError, got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkFunctionAppliedToRevokedProxy(proxy => Object.getPrototypeOf(proxy));
|
||||||
|
checkFunctionAppliedToRevokedProxy(proxy => Object.setPrototypeOf(proxy, null));
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
if (typeof reportCompare === "function")
|
||||||
|
reportCompare(true, true);
|
||||||
|
|
||||||
|
print("Tests complete");
|
Loading…
Reference in New Issue
Block a user