Bug 1058869 - Don't forget about Arrays for attribute-only Object.defineProperty calls. (r=jorendorff)

This commit is contained in:
Eric Faust
2014-08-29 14:59:51 -07:00
parent f3adf31ab2
commit a2e1eeb974

View File

@@ -4279,6 +4279,9 @@ js::DefineNativeProperty(ExclusiveContext *cx, HandleObject obj, HandleId id, Ha
* a data property.
* FIXME: All this logic should be removed when Proxies use PropDesc, but we need to
* remove JSPropertyOp getters and setters first.
* FIXME: This is still wrong for various array types, and will set the wrong attributes
* by accident, but we can't use NativeLookupOwnProperty in this case, because of resolve
* loops.
*/
shape = obj->nativeLookup(cx, id);
if (shape && shape->isDataDescriptor())
@@ -4293,6 +4296,21 @@ js::DefineNativeProperty(ExclusiveContext *cx, HandleObject obj, HandleId id, Ha
return false;
if (shape) {
// Don't forget about arrays.
if (IsImplicitDenseOrTypedArrayElement(shape)) {
if (obj->is<TypedArrayObject>()) {
/*
* Silently ignore attempts to change individial index attributes.
* FIXME: Uses the same broken behavior as for accessors. This should
* probably throw.
*/
return true;
}
if (!JSObject::sparsifyDenseElement(cx, obj, JSID_TO_INT(id)))
return false;
shape = obj->nativeLookup(cx, id);
}
attrs = ApplyOrDefaultAttributes(attrs, shape);
/* Keep everything from the shape that isn't the things we're changing */