Bug 1256688 - Change BPH::has to follow [[HasProperty]] for ordinary objects. r=jorendorff

This commit is contained in:
Tom Schuster 2016-03-19 01:30:03 +01:00
parent 132b94460d
commit ed7a4103c8
3 changed files with 25 additions and 34 deletions

View File

@ -259,35 +259,6 @@ BaseDOMProxyHandler::getOwnEnumerablePropertyKeys(JSContext* cx,
return ownPropNames(cx, proxy, JSITER_OWNONLY, props);
}
bool
DOMProxyHandler::has(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
{
if (!hasOwn(cx, proxy, id, bp)) {
return false;
}
if (*bp) {
// We have the property ourselves; no need to worry about our prototype
// chain.
return true;
}
// OK, now we have to look at the proto
JS::Rooted<JSObject*> proto(cx);
if (!js::GetObjectProto(cx, proxy, &proto)) {
return false;
}
if (!proto) {
return true;
}
bool protoHasProp;
bool ok = JS_HasPropertyById(cx, proto, id, &protoHasProp);
if (ok) {
*bp = protoHasProp;
}
return ok;
}
bool
DOMProxyHandler::setCustom(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
JS::Handle<JS::Value> v, bool *done) const

View File

@ -114,8 +114,6 @@ public:
JS::ObjectOpResult& result) const override;
bool isExtensible(JSContext *cx, JS::Handle<JSObject*> proxy, bool *extensible)
const override;
bool has(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
bool* bp) const override;
bool set(JSContext *cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
JS::Handle<JS::Value> v, JS::Handle<JS::Value> receiver, JS::ObjectOpResult &result)
const override;

View File

@ -26,10 +26,32 @@ bool
BaseProxyHandler::has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const
{
assertEnteredPolicy(cx, proxy, id, GET);
Rooted<PropertyDescriptor> desc(cx);
if (!getPropertyDescriptor(cx, proxy, id, &desc))
// This method is not covered by any spec, but we follow ES 2016
// (February 11, 2016) 9.1.7.1 fairly closely.
// Step 2. (Step 1 is a superfluous assertion.)
// Non-standard: Use our faster hasOwn trap.
if (!hasOwn(cx, proxy, id, bp))
return false;
*bp = !!desc.object();
// Step 3.
if (*bp)
return true;
// The spec calls this variable "parent", but that word has weird
// connotations in SpiderMonkey, so let's go with "proto".
// Step 4.
RootedObject proto(cx);
if (!GetPrototype(cx, proxy, &proto))
return false;
// Step 5.,5.a.
if (proto)
return HasProperty(cx, proto, id, bp);
// Step 6.
*bp = false;
return true;
}