mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-02 12:32:55 +00:00
Bug 1068589 - Remove forced extensible check before calling JSObject::preventExtensions. r=jwalden
--HG-- extra : rebase_source : 5ec8efb801fd67dd7c9d08ad0259aaee36f225ce
This commit is contained in:
parent
95bdb7948d
commit
2174ece369
@ -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);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
// Don't assert
|
||||
var obj = {};
|
||||
var proxy = new Proxy(obj, {
|
||||
get preventExtensions() {
|
||||
Object.preventExtensions(obj);
|
||||
}
|
||||
});
|
||||
Object.preventExtensions(proxy);
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
27
js/src/tests/ecma_6/Object/freeze-proxy.js
Normal file
27
js/src/tests/ecma_6/Object/freeze-proxy.js
Normal 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);
|
23
js/src/tests/ecma_6/Object/preventExtensions-proxy.js
Normal file
23
js/src/tests/ecma_6/Object/preventExtensions-proxy.js
Normal 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);
|
27
js/src/tests/ecma_6/Object/seal-proxy.js
Normal file
27
js/src/tests/ecma_6/Object/seal-proxy.js
Normal 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);
|
@ -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)
|
||||
|
@ -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());
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user