On 7 July 2011 17:58, Brendan Eich <bren...@mozilla.com> wrote:
> On Jul 7, 2011, at 8:32 AM, Andreas Rossberg wrote:
>
>> On 7 July 2011 16:12, David Bruant <david.bru...@labri.fr> wrote:
>>>>> Derived traps as showed are written in JS for expository purposes.
>>>>> Engines
>>>>> will be free to optimize as they wish internally as long as the observed
>>>>> behavior is the same.
>>>>
>>>> True, but optimizing that actually is more tricky than you might
>>>> think, since in general it would change the semantics if an engine
>>>> decided to call toString only once. It has to make sure that none of
>>>> the names are objects, or at least none of their toString methods was
>>>> modified and they are all free of side effects.
>>>
>>> Interesting.
>>> However, I'm not sure side-effects are a problem.
>>> -----
>>> var o = {a:1, toString:function(){o.b = 12; return 'a'; }};
>>> console.log(o[o], o.b); // 1, 12 on Firefox 5
>>> -----
>>> Here, o[o] triggers a side effect and that sound like the normal behavior.
>>
>> I'm not sure I understand what your example is intended to show. But
>> consider this:
>>
>> var i = 0
>> var o = {toString: function() { ++i; return "a" }
>> var p = Proxy.create({getOwnPropertyNames: function() { return [o] }, ...})
>> var k = Object.keys(p)
>> // What's the value of i now?
>
> Fresh tracemonkey tip js shell:
>
> js> var i = 0
> js> var o = {toString: function() { ++i; return "a" }}
> js> var p = Proxy.create({getOwnPropertyNames: function() { return [o] },
>                      getOwnPropertyDescriptor: function() { return {value:42} 
> }})
> js> var k = Object.keys(p)
> js> i
> 1
>
> Where would there be a double-conversion?

Well, with the canonical fix to the spec we discussed further up the
thread (adding a conversion to string in the default trap for `keys')
there would (have to) be. So my concern was that that is perhaps not
the best fix, despite its simplicity.

/Andreas
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to