[Harmony Proxies] Adding a defineProperties derived trap
dherman at mozilla.com
Mon Mar 14 20:24:25 PDT 2011
[Oh sorry, I'm behind on the iteration-order mega-thread. I'll have to catch up.]
On Mar 14, 2011, at 1:16 PM, David Herman wrote:
> Hi David,
> We have a strawman for making the enumeration order well-specified:
> Would that not be sufficient for the defineProperties case? I'd prefer that to adding another trap.
> On Mar 12, 2011, at 1:15 PM, David Bruant wrote:
>> The thread entitled "iteration order for Object" made me realize that there is no defineProperties trap.
>> Let's imagine I'd like to implement an object which would keep track of order in which own properties have been added/deleted to it. With the defineProperty and delete traps I can already track order of addition/deletion and reflect it on the enumerate/keys trap when required.
>> However, as of ES5, if I do:
>> Object.defineProperties(proxy, props)
>> then the defineProperty trap is called for each own property of props with an order chosen by the ES implementation (it's the same order than the one used in for..in which is implementation-dependent). Consequently, I cannot guarantee the object user that these keys will be enumerated with the order s/he provided them in props.
>> A defineProperties trap could allow me to throw an error saying roughly "I can't garantee my invariant with such a call, please tell me explicitely the order you want for your properties by using several Object.defineProperty".
>> It would obviously be a derived trap. The implementation is quite straightforward (based on ES5 Object.defineProperties algorithm 22.214.171.124) with one subtility: when retrieving all own enumerable property names of the props object, if props is itself a proxy, then the keys trap of this proxy would be called.
>> es-discuss mailing list
>> es-discuss at mozilla.org
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss