[[Enumerate]] and enumerate and keys trap

David Bruant bruant.d at gmail.com
Mon Oct 8 02:59:07 PDT 2012


In the latest spec draft, the [[Enumerate]] internal operation has an
"includePrototype" argument (it also has an "onlyEnumerable" argument, but
that's irrelevant to my point). for..in loops use [[Enumerate]]
with includePrototype true and Object.keys/getOwnPropertyNames use
[[Enumerate]] with includePrototype false.
It looks a bit backwards to me. What about the following:
1) [[Enumerate]] only deals with own properties (and doesn't need
the "includePrototype" argument any longer). Arguably the operation can
renamed "[[getOwnKeys]]" or the like
2) for..in climbs the prototype chain itself and uses the own version of
property names enumeration on each object of the prototype chain
3) Object.keys/getOwnPropertyNames just use [[Enumerate]]

If the internal [[Enumerate]] only deals with own properties, it seems that
the enumerate trap can be removed and for..in loop can use the keys and
getPrototypeOf traps instead (as it does with regular objects which was my
point 2).

Even if not adopting the changes I just suggested, it seems that we need
some harmonization between the proxy traps and the internal [[Enumerate]]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121008/aa2186e8/attachment.html>

More information about the es-discuss mailing list