for-in evaluation order

2010-12-27 Thread Michael Day
Hi, Some quick testing with Firefox seems to show that for-in returns properties in the order they were added to the object, and some scripts on the web (eg. RaphaelJS) seem to depend on that, unless I'm horrendously misinterpreting them. This seems... bad? Are objects implicitly ordered,

Re: for-in evaluation order

2010-12-27 Thread Boris Zbarsky
On 12/27/10 5:39 AM, Michael Day wrote: Some quick testing with Firefox seems to show that for-in returns properties in the order they were added to the object Yep; it's required for web compat, as you discovered. When we accidentally broke it, we very quickly got bug reports. ;) and

Re: for-in evaluation order

2010-12-27 Thread Dmitry A. Soshnikov
On 27.12.2010 14:39, Michael Day wrote: Hi, Some quick testing with Firefox seems to show that for-in returns properties in the order they were added to the object, and some scripts on the web (eg. RaphaelJS) seem to depend on that, unless I'm horrendously misinterpreting them. This seems...

Re: for-in evaluation order

2010-12-27 Thread Michael Day
Thanks Boris, Dmitry, Are objects implicitly ordered, by implementation convention? For implementations that have to deal with the web, yes. Okay, now I know what we have to do then :) Might I suggest that this be added to the spec, if only in an informative note, to save future

Re: for-in evaluation order

2010-12-27 Thread Andreas Gal
Note that almost all implementations break for-in enumeration order for dense arrays, for some definition of dense. Example (firefox): a = [] a[2] = 1 a[1] = 1 a[0] = 1 for (i in a) alert(i) will alert 0, 1, 2 (in that order). Now if you do a[x] = 1 you get 0, 1, 2, x However, if we start

Re: for-in evaluation order

2010-12-27 Thread Michael Day
Hi Andreas, Note that almost all implementations break for-in enumeration order for dense arrays, for some definition of dense. This is understandable and very sensible. If we try to specify something, implementors will probably object, and each implementation will have specific

Re: for-in evaluation order

2010-12-27 Thread Dmitry A. Soshnikov
On 27.12.2010 15:40, Andreas Gal wrote: I can't speak for other VM implementors, but I think most implementors will not want to guarantee either enumeration method (property addition order vs numeric order). In some cases we store array data dense, in others we punt and use a natural object

Re: for-in evaluation order

2010-12-27 Thread Mark S. Miller
On Mon, Dec 27, 2010 at 9:54 AM, Wes Garland w...@page.ca wrote: I think Mark's suggestion here is very sensible. My gut tells me that it has a low probability of breaking the web, yet it offers room for implementers to provide a fast path for numeric object indices while offering an

Re: for-in evaluation order

2010-12-27 Thread David Herman
Dave, under the spec for Operation OwnProperties(obj) step 1, you don't explicitly state that these index properties are to be enumerated in numeric order. An oversight? Oops, yes, thanks for catching that. I've updated the wiki. Also, you misstate that indexes are properties with values

Re: for-in evaluation order

2010-12-27 Thread Dmitry A. Soshnikov
On 27.12.2010 20:54, Wes Garland wrote: On Mon, Dec 27, 2010 at 8:04 AM, Dmitry A. Soshnikov dmitry.soshni...@gmail.com mailto:dmitry.soshni...@gmail.com wrote: Can you also show a memory representation (at lower level) of dense and sparse (?) data. It will help to understand the

Re: for-in evaluation order

2010-12-27 Thread Brendan Eich
The es-discuss and es5-discuss lists have seen this topic before. I don't always remember names of people who sent messages, but I keep complete archives, search them locally, then search the web for a decent archive. Possibly others do the same and can provide links. Here's a good one to

Re: for-in evaluation order

2010-12-27 Thread David-Sarah Hopwood
On 2010-12-27 19:15, David Herman wrote: Dave, under the spec for Operation OwnProperties(obj) step 1, you don't explicitly state that these index properties are to be enumerated in numeric order. An oversight? Oops, yes, thanks for catching that. I've updated the wiki. The given