Property Iteration in JSON serialization

Brendan Eich brendan at mozilla.com
Wed Oct 14 16:20:14 PDT 2009


The issue is not overriding default for-in behavior (as you can do in  
JS1.7 via __iterator__). The issue is the default behavior.

Waldemar's right, browsers differ on Array enumeration, for some or  
all Arrays. My observation to TC39 when we last discussed this is that  
most arrays are populated front to back (0 to high index) so insertion  
order matches index order, and that most programmers (all I've ever  
polled or heard from) want array enumeration to use index order.

It's conceivable that we could standardize insertion order for named  
properties, index order for indexed properties (for all objects, not  
just for Arrays). I don't know how this will fly; some VMs already  
optimize this way (v8 does, IIRC). I think it's a good compromise,  
since the edge case behavior in different browsers does not allow edge- 
case-testing scripts to interoperate today.

But this will take someone (my name was on it at the end of the last  
TC39 meeting) writing up a proposal. I will make time this month for it.

/be

On Oct 14, 2009, at 4:11 PM, Brian Kardell wrote:

> It sounds to me like there is wide agreement in the sense that at
> least the basics rules and only disagreement on the fringes...
> Otherwise no one on this list in particular would be suggesting that
> there is anything remotely like a "de facto" implementation... It
> seems that at least those basic rules are required just to function
> with the existing expectations everywhere.
>
> It also seems that those expectations aren't likely to change any time
> soon for the "default" for-each iteration order whether more robust
> and interesting proposals are adopted...
>
> So can't that much be formalized and documented regardless of whether
> or not new introductions are made to over-ride "other" predictable
> iterators to be used in for-each (or perhaps even some new mechanism
> entirely)? The simple fact that conforming to the spec would currently
> create a non-workable solution seems to argue that at least the "de
> facto" parts should be included...
>
> No?
>
>
>
> On Wed, Oct 14, 2009 at 2:37 PM, Waldemar Horwat  
> <waldemar at google.com> wrote:
>> Brian Kardell wrote:
>>>
>>> Uh oh... Patrick looking at the same parts as me reacting the same  
>>> way
>>> (I believe older pre-5 docs also said something similar)...
>>> When Oliver said "All ES implementations are required to..." I  
>>> assumed
>>> that I missed something in the new 5 docs - not that everyone just
>>> seems to have implemented roughly the same thing...
>>>
>>> Is it required - or is it not?
>>
>> It is not required.  We were planning to make it required for ES5  
>> but it
>> turns out that implementations do not match each other and  
>> implementations
>> do not follow insertion order for some kinds of properties such as  
>> things
>> that could be used as array indices.  Requiring insertion order  
>> would make
>> iterating over arrays weird.
>>
>>   Waldemar
>>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list