Le 19/09/2011 09:32, Jason Orendorff a écrit :
On Tue, Sep 6, 2011 at 10:59 AM, Mark S. Miller<erig...@google.com>  wrote:
[...] Regarding infinite extensible
objects, the only problem I see off the top of my head is: What would
Object.getOwnPropertyNames return?
Hmm. I wonder if this is a problem even for finite objects.
I'm not sure it's the exact same problem, but it's an interesting question.

js>  var x = [];
js>  x = Object.getOwnPropertyNames(x);
["length"]
js>  x = Object.getOwnPropertyNames(x);
["length", "0"]
js>  x = Object.getOwnPropertyNames(x);
["length", "0", "1"]
js>  x = Object.getOwnPropertyNames(x);
["length", "0", "1", "2"]

You see where this is going. There's a finite number of array indexes,
and the array .length property is always less than 2^32.

Of course on current machines we will eventually run out of time or
memory, but what is supposed to happen when we cross 2^32?
Object.getOwnPropertyDescriptor creates a native array and, for each own property, it calls [[DefineOwnProperty]] on this array for an index n (ES5.1 - 15.2.3.4 step 4.b) This internal method is special for arrays (ES5.1 - 15.4.5.1). When crossing 2³², ToString(n) is not an array index anymore, so the property is added (as per step 5), but the length property gets stuck to its maximum (2³²). Since the property is added, continuing results in an infinite loop, the length property remains at 2³².

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

Reply via email to