Bug 1020609 - Make configurability check in Xray defineProperty match the spec. r=bz

This code is basically emulating the ES semantics with respect to non-configurable
properties. Non-configurable value properties can still be writable, in which case
their value and writability may be updated.
This commit is contained in:
Bobby Holley 2014-06-11 15:16:06 -07:00
Родитель 730ae601c6
Коммит 0f251a891e
1 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -2314,8 +2314,22 @@ XrayWrapper<Base, Traits>::defineProperty(JSContext *cx, HandleObject wrapper,
// we often lie (sloppily) about where we found properties and set
// desc.object() to |wrapper|. Once we fully fix our Xray prototype semantics,
// this should work as intended.
if (existing_desc.object() == wrapper && existing_desc.isPermanent())
return true; // silently ignore attempt to overwrite native property
if (existing_desc.object() == wrapper && existing_desc.isPermanent()) {
// We have a non-configurable property. See if the caller is trying to
// re-configure it in any way other than making it non-writable.
if (existing_desc.hasGetterOrSetterObject() || desc.hasGetterOrSetterObject() ||
existing_desc.isEnumerable() != desc.isEnumerable() ||
(existing_desc.isReadonly() && !desc.isReadonly()))
{
// We should technically report non-configurability in strict mode, but
// doing that via JSAPI is a lot of trouble.
return true;
}
if (existing_desc.isReadonly()) {
// Same as the above for non-writability.
return true;
}
}
bool defined = false;
if (!Traits::singleton.defineProperty(cx, wrapper, id, desc, existing_desc, &defined))