[[Enumerate]] and enumerate and keys trap

Tom Van Cutsem tomvc.be at gmail.com
Mon Oct 8 09:29:33 PDT 2012

2012/10/8 David Bruant <bruant.d at gmail.com>

>  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).

It all sounds plausible. For proxies and for-in loops there's an important
inversion-of-control though: currently the proxy takes control of a for-in
loop (it decides whether to continue the loop with its prototype), with
your proposal the proxy would lose that control. For all other traps that
may be called during a prototype-chain-walk (get, set, has) the proxy
always gets to "virtualize its prototype chain".

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

Indeed. If we stick with the current [[Enumerate]](includePrototype,
onlyEnumerable) signature we'll need an ugly preamble for proxies:
- when includePrototype is false and onlyEnumerable is true, call the keys
- when includePrototype is false and onlyEnumerable is false, call the
getOwnPropertyNames trap
- when includePrototype is true and onlyEnumerable is true, call the
enumerate trap
- any other combination should not occur

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

More information about the es-discuss mailing list