[Harmony Proxies] Adding a defineProperties derived trap

David Bruant bruant at enseirb-matmeca.fr
Sat Mar 12 13:15:06 PST 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110312/40f5e5ac/attachment.html>


More information about the es-discuss mailing list