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? /Andreas _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss