mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 06:25:01 +00:00

We now care (a little bit) about the "configurable" and "writable" property attributes. Property attributes are stored together with the property name in the Shape object. Forward transitions are not attribute-savvy and will cause poor Shape reuse in the case of multiple same-name properties with different attributes. Oh, and this patch also adds Object.getOwnPropertyDescriptor() :^)
39 lines
973 B
JavaScript
39 lines
973 B
JavaScript
function assert(x) { if (!x) throw 1; }
|
|
|
|
try {
|
|
|
|
var o = {};
|
|
Object.defineProperty(o, "foo", { value: 1, writable: false, enumerable: false });
|
|
|
|
assert(o.foo === 1);
|
|
o.foo = 2;
|
|
assert(o.foo === 1);
|
|
|
|
var d = Object.getOwnPropertyDescriptor(o, "foo");
|
|
assert(d.configurable === false);
|
|
assert(d.enumerable === false);
|
|
assert(d.writable === false);
|
|
assert(d.value === 1);
|
|
|
|
Object.defineProperty(o, "bar", { value: "hi", writable: true, enumerable: true });
|
|
|
|
assert(o.bar === "hi");
|
|
o.bar = "ho";
|
|
assert(o.bar === "ho");
|
|
|
|
d = Object.getOwnPropertyDescriptor(o, "bar");
|
|
assert(d.configurable === false);
|
|
assert(d.enumerable === true);
|
|
assert(d.writable === true);
|
|
assert(d.value === "ho");
|
|
|
|
try {
|
|
Object.defineProperty(o, "bar", { value: "xx", enumerable: false });
|
|
} catch (e) {
|
|
assert(e.name === "TypeError");
|
|
}
|
|
|
|
console.log("PASS");
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|