Type of property names, as seen by proxy traps

Tom Van Cutsem tomvc.be at gmail.com
Fri Jul 8 13:47:47 PDT 2011

I believe the alternative that David is talking about is the following
(pending the acceptance of <

keys: function(proxy) {
  return Object.getOwnPropertyNames(proxy).filter(
      function (name) { return Object.getOwnPropertyDescriptor(proxy,
name).enumerable });

(assuming that Object here refers to the built-in Object)

With this definition, I don't see the need for double coercion: the
handler's "getOwnPropertyNames" trap is called, and its result is coerced.
Then, the proxy implementation "knows" that each of the above |name|s passed
to "getOwnPropertyDescriptor" will be a String already, so it doesn't need
to coerce again. Finally, `keys' does not need to coerce its own result
array, since it is simply a filtered version of an already fresh, coerced

Perhaps all self-sends to fundamental traps should be expressed in terms of
the operation that causes the trap, rather than a direct trap invocation.
Similar issues could arise in the default 'set' trap behavior when it calls
'this.defineProperty' rather than 'Object.defineProperty(proxy,...)'.

2011/7/7 Andreas Rossberg <rossberg at google.com>

> On 7 July 2011 19:35, David Bruant <david.bruant at labri.fr> wrote:
> >> No, with the current keys default trap (calling
> >> this.getOwnPropertyNames()) there is no double conversion. Only one at
> >> the exit of the keys trap. There would be 2 conversions if the "keys"
> >> trap had the proxy argument (based on
> >> http://wiki.ecmascript.org/doku.php?id=strawman:handler_access_to_proxy
> )
> >> and if internally, the default keys trap was calling
> >> "Object.getOwnPropertyNames(proxy)" (which would call the trap and do
> >> type coercion).
> >>
> >> But the current implementation and a type coercion only when going out
> >> of traps would do double-conversion.
> > "not". "would not do double-conversion", sorry.
> I thought the fix we were discussing was changing the `keys' default trap
> from
> keys: function() {
>  return this.getOwnPropertyNames().filter(
>    function (name) { return
> this.getOwnPropertyDescriptor(name).enumerable }.bind(this));
> }
> to something along the lines of
> keys: function() {
>  return this.getOwnPropertyNames().filter(
>    function (name) { return this.getOwnPropertyDescriptor('' +
> name).enumerable }.bind(this));
> }
> That would fix passing non-strings to the getOwnPropertyDescriptor
> trap, but introduce double conversions when you invoke Object.keys.
> I'm not sure what alternative you are proposing now.
> /Andreas
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110708/be1f7ea4/attachment-0001.html>

More information about the es-discuss mailing list