ToPropertyDescriptor and [[DefineOwnProperty]], regarding Object.defineProperty

Allen Wirfs-Brock Allen.Wirfs-Brock at
Mon Jun 1 13:47:47 PDT 2009

Jeff Walden wrote:
>0. Throughout this email any reference to a "property descriptor" refers
>to the specification type, not to the reification of one as exposed by
>Object.getOwnPropertyDescriptor or to the object taken as an argument by

The main reason we needed to deal with such partial property descriptors is to enable the use case of Object.defineProperty where someone wants to set the state of some specific attribute of an already existing property.  We wanted to enable a programmer to, for example, write:
	Object.defineProperty(myObj,"myProp", {configurable:false});
Rather than:
	var desc= Object.getOwnPropertyDescriptor(myObj,"myProp");
	Object.defineProperty(myObj,"myProp", desc);

If we are going to allow such modification of individual attributes (or subsets of attributes) then we need to specify the acceptable attribute transformations for an existing property.  That is specified by the algorithm steps of [[DefineOwnProperty]]. The specific encoding use within internal property descriptors to represent the intention to change or to leave unmodified a particular attribute doesn't significantly change the complexity of [[DefineOwnProperty]]. In earlier drafts we actually experimented with using fully populated property descriptors and attribute fields with three possible values logic (true, false, unspecified).  This actually added some complexity to the specification (for example, we couldn't use the internal Boolean type to define the expected field values) so we decided to use the absence of attribute field to indicate that its value is not being explicitly specified.

Note the such partial descriptors primarily come from Object.defineProperty via ToPropertyDescriptor. Within the actual specification we have generally tried to use write populated property descriptors in situations where we need to explicitly specify the attributes of a property. ToPropertyDescriptor adds another layer of complexity that logically is really part of Object.defineProperty/defineProperties and is necessary to ensure that the user hasn't specified bogus values for the various properties.

I agree that the rules of [[DefineOwnProperty]] are fairly complex.  I originally used a decision table to work out what they needed to be. I don't see any good way to reduce this complexity without eliminating support for the motivating use case for partial descriptors in Object.defineProperty.


More information about the es-discuss mailing list