On Dec 10, 2013, at 9:28 PM, James Clark wrote:

> On Wed, Dec 11, 2013 at 11:59 AM, R S <[email protected]> wrote:
> On Tue, Dec 10, 2013 at 8:44 PM, James Clark <[email protected]> wrote:
> For example, the ECMA spec needs the order of key/value pairs in an object to 
> be significant
> 
> I don't think ECMA-404 has such a requirement. In fact, it says otherwise in 
> at least two places.
> 
> Earlier in this discussion I believe AWB said he thought that ECMA-404 
> shouldn't say so.

No, currently ECMA-404 intentionally does not say that  key/value pairs are 
unordered because there is clearly an ordering to them in a JSON text.  it 
does't say one way or another whether any downstream semantics is derived from 
the ordering.

> 
> In JavaScript, objects do preserve the order of keys, and many programs rely 
> on this.  ECMAScript 5 doesn't specify this, but I was under the impression 
> that TC39 plans to fix this.

There is a de facto standard for the ordering of the most common cases.  At 
some point this ordering will probably be included in ECMA-262

>  The ES6 draft currently depends on ECMAScript evaluation semantics to 
> determine the value represented by a JSON text.

At this point in time, this is just for economy of specification text as we 
know that for syntactically valid JSON input that object literal evaluation 
produces the same result that JSON.parse needs to produce .  In both cases, 
source code key/value pairs are processed in left-to-right source code order 
and constructs an object whose property enumeration order is  derived from the 
processing order.

> So assuming TC39 fixes ECMAScript at some point to match the reality on the 
> Web, JSON.parse will specified to preserve order. I believe current 
> implementations of JSON.parse already do so.

yes and even if we changed how we expressed the specification for JSON.parse it 
would still have to preserve the current de facto ordering.
> 
> Maybe I am worrying unnecessarily about this.  It would certainly make life 
> simpler to be able to say JSON objects are unordered collections without 
> qualification.  But I suspect that this doesn't reflect reality on the Web.

and you'd be correct. I think you could get away with recommending that 
applications not depend upon the ordering but i doubt that web developers would 
pay attention.  ECMAScript stated out trying to not define a specific 
enumeration order for object properties.  But developers still wrote code that 
dependent upon the ordering they observed in the wild and interoperability 
pressures have generally forced convergence upon the ordering used by the 
browsers with the most market share. 

>   
> The way to deal with this is by careful spec layering.
> 
> An alternative way to deal with this is to write less in the IETF spec, and 
> use a normative reference to ECMA-404.
> 
> That is exactly the kind of layering I think we need.

It's probably obvious that I'd also agree with that.

Allen

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to