Bug 1154296 - Small GetOwnPropertyDescriptor cleanup. r=jorendorff

This commit is contained in:
Tom Schuster
2015-04-24 22:06:16 +02:00
parent 04d85ae213
commit f7cbe20850
2 changed files with 13 additions and 10 deletions

View File

@@ -3006,19 +3006,18 @@ js::GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
}
#endif
RootedNativeObject nobj(cx, obj.as<NativeObject>());
RootedShape shape(cx);
if (!NativeLookupOwnProperty<CanGC>(cx, obj.as<NativeObject>(), id, &shape))
if (!NativeLookupOwnProperty<CanGC>(cx, nobj, id, &shape))
return false;
if (!shape) {
desc.object().set(nullptr);
return true;
}
bool doGet = true;
desc.setAttributes(GetShapeAttributes(obj, shape));
if (desc.isAccessorDescriptor()) {
MOZ_ASSERT(desc.isShared());
doGet = false;
// The result of GetOwnPropertyDescriptor() must be either undefined or
// a complete property descriptor (per ES6 draft rev 32 (2015 Feb 2)
@@ -3040,20 +3039,24 @@ js::GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
desc.setSetterObject(nullptr);
desc.attributesRef() |= JSPROP_SETTER;
}
desc.value().setUndefined();
} else {
// This is either a straight-up data property or (rarely) a
// property with a JSGetterOp/JSSetterOp. 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;
if (IsImplicitDenseOrTypedArrayElement(shape)) {
desc.value().set(nobj->getDenseOrTypedArrayElement(JSID_TO_INT(id)));
} else {
if (!NativeGetExistingProperty(cx, nobj, nobj, shape, desc.value()))
return false;
}
}
RootedValue value(cx);
if (doGet && !GetProperty(cx, obj, obj, id, &value))
return false;
desc.value().set(value);
desc.object().set(obj);
desc.object().set(nobj);
desc.assertComplete();
return true;
}