Property ordering of [[Enumerate]] / getOwnPropertyNames()
adamk at chromium.org
Thu Aug 20 22:40:42 UTC 2015
This doesn't answer the spec question, exactly, but v8 doesn't currently
conform to ES6's requirements for [[OwnPropertyKeys]]: some objects return
names in an implementation-dependent order (see
https://code.google.com/p/v8/issues/detail?id=3056 for more details).
On Thu, Aug 20, 2015 at 9:54 AM, Jesse McCarthy <
es-discuss-2015-02 at jessemccarthy.net> wrote:
> I just want to confirm some things about property enumeration order of
> plain Objects. I apologize that this has probably already been discussed
> before, but it's hard to locate a clear answer. Please note that I'm solely
> asking about ES2015 spec compliance, not what's in the wild.
> var y = Object.create(null);
> // Note that property names are all strings.
> y.one = 1;
> y.two = 2;
> y.three = 3;
> This is my understanding of what's guaranteed (or not) about enumeration
> order (in the context of the example given):
> 1. No guarantee of order
> Anything that relies on or has property-order equivalence with
> `[[Enumerate]]` or `EnumerableOwnNames`
> 1b. for (x in y)
> 1c. Object.keys(y)
> This is based on the statement in 9.1.11 [[Enumerate]] () step 1:
>> The mechanics and order of enumerating the properties is not specified
> Although it says that...
>> [[Enumerate]] must obtain the own property keys of the target object as
>> if by calling its [[OwnPropertyKeys]] internal method.
> ...and `[[OwnPropertyKeys]]` specifies ordering, my reading is that
> `[[Enumerate]]` doesn't guarantee that the iterator it returns will
> preserve the order returned by `[[OwnPropertyKeys]]`.
> 2. Guarantee of insertion order (['one', 'two', 'three'])
> Are those interpretations correct?
> In this thread...
> ...Bergi asked these pertinent questions that no one answered:
>> But why was the default object [[enumerate]] algorithm not specced to
>> match the [[OwnPropertyKeys]] order then?
>> Shouldn't we add a guarantee to [[enumerate]] that the subset of
>> enumerated own properties comes in insertion order as well?
> This is partly in reference to http://stackoverflow.com/a/30244410/1034448
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss