Bug 1138499, part 1 - Assert some basic rules on property descriptors on entry to DefineProperty and exit from GetOwnPropertyDescriptor. r=Waldo.

This commit is contained in:
Jason Orendorff
2015-03-23 14:32:27 -05:00
parent 686e15c6a0
commit ad45aac07c
6 changed files with 104 additions and 30 deletions

View File

@@ -3123,8 +3123,12 @@ bool
js::GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
MutableHandle<PropertyDescriptor> desc)
{
if (GetOwnPropertyOp op = obj->getOps()->getOwnPropertyDescriptor)
return op(cx, obj, id, desc);
if (GetOwnPropertyOp op = obj->getOps()->getOwnPropertyDescriptor) {
bool ok = op(cx, obj, id, desc);
if (ok)
desc.assertCompleteIfFound();
return ok;
}
RootedShape shape(cx);
if (!NativeLookupOwnProperty<CanGC>(cx, obj.as<NativeObject>(), id, &shape))
@@ -3174,6 +3178,7 @@ js::GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
desc.value().set(value);
desc.object().set(obj);
desc.assertComplete();
return true;
}
@@ -3181,6 +3186,7 @@ bool
js::DefineProperty(JSContext* cx, HandleObject obj, HandleId id, Handle<PropertyDescriptor> desc,
ObjectOpResult& result)
{
desc.assertValid();
if (DefinePropertyOp op = obj->getOps()->defineProperty)
return op(cx, obj, id, desc, result);
return NativeDefineProperty(cx, obj.as<NativeObject>(), id, desc, result);
@@ -3288,8 +3294,12 @@ js::GetPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
RootedObject pobj(cx);
for (pobj = obj; pobj;) {
if (pobj->is<ProxyObject>())
return Proxy::getPropertyDescriptor(cx, pobj, id, desc);
if (pobj->is<ProxyObject>()) {
bool ok = Proxy::getPropertyDescriptor(cx, pobj, id, desc);
if (ok)
desc.assertCompleteIfFound();
return ok;
}
if (!GetOwnPropertyDescriptor(cx, pobj, id, desc))
return false;