Nov 18 notes

Brendan Eich brendan at mozilla.com
Mon Nov 22 13:27:46 PST 2010


On Nov 22, 2010, at 11:49 AM, Brendan Eich wrote:

> On Nov 22, 2010, at 11:14 AM, Oliver Hunt wrote:
>> And all existing standards compliant code can no longer rely on for in doing what it has done for years.  Suddently for in _behaviour_ may change based on the prototype chain.
> 
> That's true in Harmony,

I think I misread your "based on the prototype chain" words.

I was making the general case for runtime semantic fixes -- few and worth making -- in Harmony as in ES5 strict.

But I think you were supposing a proxy on a non-proxy's prototype chain could start returning non-string non-keys via its iterate trap. Not so. Here's a session with a fresh js shell (Firefox 4 latest code):

js> var proxy = Proxy.create({
    has: function () { return false; },
    enumerate: function () { return ["a", "b", "c"]; },
    iterate: function () { for (let i = 0; i < 10; i++) yield i; }
});
js> 
js> var obj = Object.create(proxy);
js> 
js> for (var i in proxy)
    print(i);
0
1
2
3
4
5
6
7
8
9
js> 
js> for (var i in obj)
    print(i);
a
b
c

Once for-in starts up a non-proxy object's prototype chain, only enumerate traps -- never iterate. And enumerate is fundamental, so if missing, the for in fails:

js> var proxy = Proxy.create({
    has: function () { return false; },
    iterate: function () { for (let i = 0; i < 10; i++) yield i; }
});
js> 
js> var obj = Object.create(proxy);
js> 
js> for (var i in proxy)
    print(i);
0
1
2
3
4
5
6
7
8
9
js> 
js> for (var i in obj)
    print(i);
typein:11: TypeError: enumerate is not a function

/be



More information about the es-discuss mailing list