Bug 1068589 - Remove forced extensible check before calling JSObject::preventExtensions. r=jwalden

--HG--
extra : rebase_source : 5ec8efb801fd67dd7c9d08ad0259aaee36f225ce
This commit is contained in:
André Bargull 2014-09-23 22:47:01 +02:00
parent 95bdb7948d
commit 2174ece369
9 changed files with 89 additions and 31 deletions

View File

@ -1044,12 +1044,6 @@ obj_preventExtensions(JSContext *cx, unsigned argc, Value *vp)
args.rval().setObject(*obj);
bool extensible;
if (!JSObject::isExtensible(cx, obj, &extensible))
return false;
if (!extensible)
return true;
return JSObject::preventExtensions(cx, obj);
}

View File

@ -0,0 +1,8 @@
// Don't assert
var obj = {};
var proxy = new Proxy(obj, {
get preventExtensions() {
Object.preventExtensions(obj);
}
});
Object.preventExtensions(proxy);

View File

@ -6517,11 +6517,6 @@ JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length)
JS_PUBLIC_API(bool)
JS_PreventExtensions(JSContext *cx, JS::HandleObject obj)
{
bool extensible;
if (!JSObject::isExtensible(cx, obj, &extensible))
return false;
if (!extensible)
return true;
return JSObject::preventExtensions(cx, obj);
}

View File

@ -1267,10 +1267,7 @@ JSObject::sealOrFreeze(JSContext *cx, HandleObject obj, ImmutabilityType it)
assertSameCompartment(cx, obj);
JS_ASSERT(it == SEAL || it == FREEZE);
bool extensible;
if (!JSObject::isExtensible(cx, obj, &extensible))
return false;
if (extensible && !JSObject::preventExtensions(cx, obj))
if (!JSObject::preventExtensions(cx, obj))
return false;
AutoIdVector props(cx);

View File

@ -0,0 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function logProxy(object = {}, handler = {}) {
var log = [];
var proxy = new Proxy(object, new Proxy(handler, {
get(target, propertyKey, receiver) {
log.push(propertyKey);
return target[propertyKey];
}
}));
return {proxy, log};
}
// The order of operations is backwards when compared to ES6 draft rev 27
// (2014 August 24), but see https://bugs.ecmascript.org/show_bug.cgi?id=3215
// for an explanation on why the spec version is clearly wrong.
var {proxy, log} = logProxy();
Object.freeze(proxy);
assertDeepEq(log, ["preventExtensions", "ownKeys"]);
var {proxy, log} = logProxy();
Object.freeze(Object.freeze(proxy));
assertDeepEq(log, ["preventExtensions", "ownKeys", "preventExtensions", "ownKeys"]);
reportCompare(0, 0);

View File

@ -0,0 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function logProxy(object = {}, handler = {}) {
var log = [];
var proxy = new Proxy(object, new Proxy(handler, {
get(target, propertyKey, receiver) {
log.push(propertyKey);
return target[propertyKey];
}
}));
return {proxy, log};
}
var {proxy, log} = logProxy();
Object.preventExtensions(proxy);
assertDeepEq(log, ["preventExtensions"]);
var {proxy, log} = logProxy();
Object.preventExtensions(Object.preventExtensions(proxy));
assertDeepEq(log, ["preventExtensions", "preventExtensions"]);
reportCompare(0, 0);

View File

@ -0,0 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function logProxy(object = {}, handler = {}) {
var log = [];
var proxy = new Proxy(object, new Proxy(handler, {
get(target, propertyKey, receiver) {
log.push(propertyKey);
return target[propertyKey];
}
}));
return {proxy, log};
}
// The order of operations is backwards when compared to ES6 draft rev 27
// (2014 August 24), but see https://bugs.ecmascript.org/show_bug.cgi?id=3215
// for an explanation on why the spec version is clearly wrong.
var {proxy, log} = logProxy();
Object.seal(proxy);
assertDeepEq(log, ["preventExtensions", "ownKeys"]);
var {proxy, log} = logProxy();
Object.seal(Object.seal(proxy));
assertDeepEq(log, ["preventExtensions", "ownKeys", "preventExtensions", "ownKeys"]);
reportCompare(0, 0);

View File

@ -5577,13 +5577,6 @@ DebuggerObject_sealHelper(JSContext *cx, unsigned argc, Value *vp, SealHelperOp
ok = JSObject::freeze(cx, obj);
} else {
JS_ASSERT(op == PreventExtensions);
bool extensible;
if (!JSObject::isExtensible(cx, obj, &extensible))
return false;
if (!extensible) {
args.rval().setUndefined();
return true;
}
ok = JSObject::preventExtensions(cx, obj);
}
if (!ok)

View File

@ -1341,20 +1341,14 @@ Shape::setObjectMetadata(JSContext *cx, JSObject *metadata, TaggedProto proto, S
/* static */ bool
js::ObjectImpl::preventExtensions(JSContext *cx, Handle<ObjectImpl*> obj)
{
#ifdef DEBUG
bool extensible;
if (!JSObject::isExtensible(cx, obj, &extensible))
return false;
MOZ_ASSERT(extensible,
"Callers must ensure |obj| is extensible before calling "
"preventExtensions");
#endif
if (Downcast(obj)->is<ProxyObject>()) {
RootedObject object(cx, obj->asObjectPtr());
return js::Proxy::preventExtensions(cx, object);
}
if (!obj->nonProxyIsExtensible())
return true;
RootedObject self(cx, obj->asObjectPtr());
/*