Bug 1073446 - Object.preventExtensions() should return its argument with no conversion when the argument is a primitive value. r=till

This commit is contained in:
ziyunfei 2014-09-26 03:32:00 -04:00
parent b1016b8cff
commit d0b4ed6358
4 changed files with 31 additions and 6 deletions

View File

@ -1034,15 +1034,19 @@ obj_isExtensible(JSContext *cx, unsigned argc, Value *vp)
return true;
}
// ES6 draft rev27 (2014/08/24) 19.1.2.15 Object.preventExtensions(O)
static bool
obj_preventExtensions(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
RootedObject obj(cx);
if (!GetFirstArgumentAsObject(cx, args, "Object.preventExtensions", &obj))
return false;
args.rval().set(args.get(0));
args.rval().setObject(*obj);
// step 1
if (!args.get(0).isObject())
return true;
// steps 2-5
RootedObject obj(cx, &args.get(0).toObject());
return JSObject::preventExtensions(cx, obj);
}

View File

@ -8,5 +8,5 @@ function test(stdlib, foreign) {
}
return f;
};
f = test(this, {ff: Object.preventExtensions});
f = test(this, {ff: Object.defineProperty});
f();

View File

@ -65,7 +65,7 @@ assertEq(caught, true);
var caught = false;
try {
callFFI(null, {ffi:Object.preventExtensions})();
callFFI(null, {ffi:Object.defineProperty})();
} catch (e) {
caught = true;
}

View File

@ -0,0 +1,21 @@
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
var BUGNUMBER = 1073446;
var summary = "Object.preventExtensions() should return its argument with no conversion when the argument is a primitive value";
print(BUGNUMBER + ": " + summary);
assertEq(Object.preventExtensions(), undefined);
assertEq(Object.preventExtensions(undefined), undefined);
assertEq(Object.preventExtensions(null), null);
assertEq(Object.preventExtensions(1), 1);
assertEq(Object.preventExtensions("foo"), "foo");
assertEq(Object.preventExtensions(true), true);
if (typeof Symbol === "function") {
assertEq(Object.preventExtensions(Symbol.for("foo")), Symbol.for("foo"));
}
if (typeof reportCompare === "function")
reportCompare(true, true);