Le 07/07/2011 20:52, Andreas Rossberg a écrit : > On 7 July 2011 19:35, David Bruant <[email protected]> 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. I was completely not thinking about this one. Sorry for the misunderstanding.
I would be in favor to not do the conversion at all for "this.getOwnPropertyDescriptor". I think that derived trap default implementation should be lightweight (no conversion if a trap calls another handler method). Type coercion can be implemented manually (like anything else). I think it's good to give as default behavior (implemented by engines, so hopefully more efficient) the one that is the most consistent with internal methods expetations (for instance [[GetOwnProperty]] expects a string as a name, for instance) The way I view it, it's up to the handler author to write his/her traps consistently. If he/she decides to return objects on a this.getOwnPropertyNames call, then if the spec says that this function will be called without type coercion, he/she has to implement this.getOwnPropertyDescriptor accordingly. But that's just my opinion. David _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

