Hi David,

We have a strawman for making the enumeration order well-specified:

    http://wiki.ecmascript.org/doku.php?id=strawman:enumeration

Would that not be sufficient for the defineProperties case? I'd prefer that to 
adding another trap.

Dave

On Mar 12, 2011, at 1:15 PM, David Bruant wrote:

> Hi,
> 
> 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 15.2.3.7) 
> 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.
> 
> David
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to