General comments response (was Re: ES6 Rev13 Review: MOP-refactoring, symbols, proxies, Reflect module)

Brandon Benvie brandon at brandonbenvie.com
Sun Dec 30 15:25:35 PST 2012


Ah yes, I take it back. For some reason I had the mistaken notion that the
[[Origin]] was somehow planned to propagate/persist further, rather than
just being a way to support lossless maybe-forward (I believe this is the
purpose?). I must have crossed signals on something else, since I recall
reading some concern recently about a property descriptor mutating in
transit, like in the case of a proxy being passed as a descriptor.


On Sun, Dec 30, 2012 at 6:18 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:

>
> On Dec 30, 2012, at 2:57 PM, Brandon Benvie wrote:
>
>
> Wouldn't it be possible to make a copy of the provided descriptor object
> and otherwise work the same as it is currently specified? This retains the
> ability to set and get custom descriptor attributes without making the
> stored record mutable, which seems like the primary concern.
>
>
> There are no stored PD records (for ordinary objects, see 8.3.7.3). The PD
> records that reference the original descriptor object as just transient
> values.   It is not stored by the ordinary [[DefineOwnProperty]] call.  A
> Proxy defineProperty trap might capture the descriptor object that is
> passed in or even mutate it.  But so what?.  If a caller of
> Object.defineOwnProperty actually cares about that possibility, it can
> always make sure it passes a fresh descriptor object.
>
> Allen
>
>
> On Sun, Dec 30, 2012 at 5:13 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:
>>
>> > * I'm a bit uncomfortable with the removal of property descriptor
>> normalization in the getOwnPropertyDescriptor/defineProperty traps.
>> Especially for getOwnPropertyDescriptor I think it's a breaking change
>> w.r.t. ES5.1.
>>
>> To summarize, the [[GetOwnProperty]] internal method of proxy objects is
>> now (in the spec draft) specified to take the descriptor object returned
>> from the  getOwnPropertyDescriptor trap and to package it up as an internal
>> property descriptor record that is populated in the normal manner from the
>> descriptor object.  The process of creating this PD record performs the
>> same error checks that are performed (in ES5.1) by
>> Object.defineOwnProperty.  In addition, the PD record now captures a
>> reference to the original descriptor object.  If that PD record is
>> subsequently used in a context where a descriptor object is required, the
>> original captured descriptor object is used.  This is essential for
>> expressing the semantics of Object.getOwnPropertyDescriptor in terms of the
>> MOP while still enabling Proxies to extend of domain of property
>> attributes.  Object.getOwnPropertyDescriptor(obj) calls [[GetOwnProperty]]
>> on obj which yields a PD record.  It then calls the abstraction operation Fr
>> omPropertyDescriptor to produce the descriptor object that is its return
>> value.  If obj is an ordinary object, the PD record produced by ordinary
>> [[GetOwnProperty]] does not have a captured descriptor object so
>> FromPropertyDescriptor cons up a new descriptor object that is a direct
>> reflection of the PD record.  If obj is a proxy then [[GetOwnProperty]]
>> will return a PD record that captures the descriptor object that was
>> returned by the trap.  FromPropertyDescriptor simply returns that captured
>> descriptor object which becomes the value of the original
>> Object.getOwnPropertyDescriptor call.
>>
>> This permits things like:
>>
>> Object.defineOwnProperty(pObj1,"foo", {method: func});  //define property
>> on a proxy-based object, that have "method" properties
>> console.log (Object.getOwnPropertyDescriptor(pObj1,"foo").method);
>>  //we can retrieve the value of the method attribute (if the proxy supports
>> it)
>>
>> Object.defineOwnProperty(pObj2,"foo",Object.getOwnProperty(pObj1,
>> "foo"));  //copy a method properry from pObj1 to pObj2
>>
>> If descriptor object with extended attributes is applied to an ordinary
>> object, it is always first internally converted to a PD record.  PD records
>> only contain fields for the ordinary attributes, and any operations upon
>> ordinary objects will have no visibility  of  the extended attributes.
>>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121230/3365e279/attachment.html>


More information about the es-discuss mailing list