archives

« Bugzilla Issues Index

#2914 — Object.getOwnPropertyDescriptor/FromPropertyDescriptor returns object with undefined slots


My current implementation of the ES6 method FromPropertyDescriptor causes this test to print "undefined"

var a = {};
Object.defineProperty (a, "c", { value: 10 });
var desc = Object.getOwnPropertyDescriptor(a, "c");
console.log (desc.writable);

This appears to be in line with the spec, specifically 6.2.4.4 step 6a.

Both v8 and spidermonkey (in FF nightly) print "false"

ES5's text is similar (8.10.4 step 3b):

b. Call the [[DefineOwnProperty]] internal method of obj with arguments "writable", Property Descriptor
{[[Value]]: Desc.[[Writable]], [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}, and false.

It's missing the "does the descriptor have a [[Writable]] field" check, but it copies over whatever the value is, so I would expect this should copy over undefined.

Maybe the "Desc.[[Writable]]" load coerces the value to a boolean in both v8 and SM?


`Object.defineProperty()` calls 9.1.6.3 ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current), and in 9.1.6.3, step 2.c.i is of interest:
> If the value of an attribute field of Desc is absent, the attribute of
> the newly created property is set to its default value.

So `Object.defineProperty(a, "c", { value: 10 })` is exactly equivalent to `Object.defineProperty(a, "c", { value: 10, writable: false, enumerable: false, configurable: false })` in that context. See 6.1.7.1 Property Attributes, Table 4 "Default Attribute Values" for the defaults.