Bug 1124201 - Remove NonProxyLookupOwnProperty. r=jorendorff

This commit is contained in:
Tom Schuster
2015-01-22 17:17:26 +01:00
parent 598e20943c
commit dad18a0d17
5 changed files with 62 additions and 133 deletions

View File

@@ -538,9 +538,8 @@ DefinePropertyOnObject(JSContext *cx, HandleNativeObject obj, HandleId id, const
{
/* 8.12.9 step 1. */
RootedShape shape(cx);
RootedObject obj2(cx);
MOZ_ASSERT(!obj->getOps()->lookupGeneric);
if (!NonProxyLookupOwnProperty<CanGC>(cx, nullptr, obj, id, &obj2, &shape))
if (!NativeLookupOwnProperty<CanGC>(cx, obj, id, &shape))
return false;
MOZ_ASSERT(!obj->getOps()->defineProperty);
@@ -570,8 +569,6 @@ DefinePropertyOnObject(JSContext *cx, HandleNativeObject obj, HandleId id, const
/* 8.12.9 steps 5-6 (note 5 is merely a special case of 6). */
RootedValue v(cx);
MOZ_ASSERT(obj == obj2);
bool shapeDataDescriptor = true,
shapeAccessorDescriptor = false,
shapeWritable = true,
@@ -644,7 +641,7 @@ DefinePropertyOnObject(JSContext *cx, HandleNativeObject obj, HandleId id, const
return Reject(cx, JSMSG_CANT_REDEFINE_PROP, throwError, id, rval);
}
if (!NativeGetExistingProperty(cx, obj, obj2.as<NativeObject>(), shape, &v))
if (!NativeGetExistingProperty(cx, obj, obj, shape, &v))
return false;
}
@@ -826,7 +823,7 @@ DefinePropertyOnObject(JSContext *cx, HandleNativeObject obj, HandleId id, const
*/
if (callDelProperty) {
bool succeeded;
if (!CallJSDeletePropertyOp(cx, obj2->getClass()->delProperty, obj2, id, &succeeded))
if (!CallJSDeletePropertyOp(cx, obj->getClass()->delProperty, obj, id, &succeeded))
return false;
}
@@ -2880,88 +2877,22 @@ js::LookupNameUnqualified(JSContext *cx, HandlePropertyName name, HandleObject s
return true;
}
template <AllowGC allowGC>
bool
js::NonProxyLookupOwnProperty(JSContext *cx, LookupGenericOp lookup,
typename MaybeRooted<JSObject*, allowGC>::HandleType obj,
typename MaybeRooted<jsid, allowGC>::HandleType id,
typename MaybeRooted<JSObject*, allowGC>::MutableHandleType objp,
typename MaybeRooted<Shape*, allowGC>::MutableHandleType propp)
{
MOZ_ASSERT(!obj->template is<ProxyObject>());
if (lookup) {
if (!allowGC)
return false;
if (!lookup(cx,
MaybeRooted<JSObject*, allowGC>::toHandle(obj),
MaybeRooted<jsid, allowGC>::toHandle(id),
MaybeRooted<JSObject*, allowGC>::toMutableHandle(objp),
MaybeRooted<Shape*, allowGC>::toMutableHandle(propp)))
{
return false;
}
} else {
typename MaybeRooted<NativeObject*, allowGC>::HandleType nobj =
MaybeRooted<JSObject*, allowGC>::template downcastHandle<NativeObject>(obj);
bool done;
if (!LookupOwnPropertyInline<allowGC>(cx, nobj, id, propp, &done))
return false;
if (!done) {
objp.set(nullptr);
propp.set(nullptr);
return true;
}
if (propp)
objp.set(obj);
else
objp.set(nullptr);
}
if (!propp)
return true;
if (objp == obj)
return true;
JSObject *outer = nullptr;
if (js::ObjectOp op = objp->getClass()->ext.outerObject) {
if (!allowGC)
return false;
RootedObject inner(cx, objp);
outer = op(cx, inner);
if (!outer)
return false;
}
if (outer != objp)
propp.set(nullptr);
return true;
}
template bool
js::NonProxyLookupOwnProperty<CanGC>(JSContext *cx, LookupGenericOp lookup,
HandleObject obj, HandleId id,
MutableHandleObject objp, MutableHandleShape propp);
template bool
js::NonProxyLookupOwnProperty<NoGC>(JSContext *cx, LookupGenericOp lookup,
JSObject *obj, jsid id,
FakeMutableHandle<JSObject*> objp,
FakeMutableHandle<Shape*> propp);
bool
js::HasOwnProperty(JSContext *cx, HandleObject obj, HandleId id, bool *result)
{
if (obj->is<ProxyObject>())
return Proxy::hasOwn(cx, obj, id, result);
RootedObject pobj(cx);
if (GetOwnPropertyOp op = obj->getOps()->getOwnPropertyDescriptor) {
Rooted<PropertyDescriptor> desc(cx);
if (!op(cx, obj, id, &desc))
return false;
*result = !!desc.object();
return true;
}
RootedShape shape(cx);
LookupGenericOp lookupOp = obj->getOps()->lookupGeneric;
if (!NonProxyLookupOwnProperty<CanGC>(cx, lookupOp, obj, id, &pobj, &shape))
if (!NativeLookupOwnProperty<CanGC>(cx, obj.as<NativeObject>(), id, &shape))
return false;
*result = (shape != nullptr);
return true;
@@ -3199,10 +3130,8 @@ js::GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id,
if (GetOwnPropertyOp op = obj->getOps()->getOwnPropertyDescriptor)
return op(cx, obj, id, desc);
RootedObject pobj(cx);
RootedShape shape(cx);
LookupGenericOp lookupOp = obj->getOps()->lookupGeneric;
if (!NonProxyLookupOwnProperty<CanGC>(cx, lookupOp, obj, id, &pobj, &shape))
if (!NativeLookupOwnProperty<CanGC>(cx, obj.as<NativeObject>(), id, &shape))
return false;
if (!shape) {
desc.object().set(nullptr);
@@ -3210,25 +3139,20 @@ js::GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id,
}
bool doGet = true;
if (pobj->isNative()) {
desc.setAttributes(GetShapeAttributes(pobj, shape));
if (desc.hasGetterOrSetterObject()) {
MOZ_ASSERT(desc.isShared());
doGet = false;
if (desc.hasGetterObject())
desc.setGetterObject(shape->getterObject());
if (desc.hasSetterObject())
desc.setSetterObject(shape->setterObject());
} else {
// This is either a straight-up data property or (rarely) a
// property with a JSPropertyOp getter/setter. The latter must be
// reported to the caller as a plain data property, so don't
// populate desc.getter/setter, and mask away the SHARED bit.
desc.attributesRef() &= ~JSPROP_SHARED;
}
desc.setAttributes(GetShapeAttributes(obj, shape));
if (desc.hasGetterOrSetterObject()) {
MOZ_ASSERT(desc.isShared());
doGet = false;
if (desc.hasGetterObject())
desc.setGetterObject(shape->getterObject());
if (desc.hasSetterObject())
desc.setSetterObject(shape->setterObject());
} else {
if (!GetPropertyAttributes(cx, pobj, id, &desc.attributesRef()))
return false;
// This is either a straight-up data property or (rarely) a
// property with a JSPropertyOp getter/setter. The latter must be
// reported to the caller as a plain data property, so don't
// populate desc.getter/setter, and mask away the SHARED bit.
desc.attributesRef() &= ~JSPROP_SHARED;
}
RootedValue value(cx);