New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible ordering requirement in EnumerableOwnNames #205

Closed
rossberg opened this Issue Nov 18, 2015 · 10 comments

Comments

Projects
None yet
4 participants
@rossberg
Member

rossberg commented Nov 18, 2015

7.3.21 (EnumerableOwnNames(O)), step 5 requires to "order the elements of names so they are in the same relative order as would be produced by the Iterator that would be returned if the [[Enumerate]] internal method was invoked on O." That list of names was originally obtained from O.[[OwnPropertyKeys]].

Since O may be a proxy, this requirement is impossible to meet.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Nov 19, 2015

Member

Some other language which doesn't have these proxy implications can be found at the end of Object.keys (which calls EnumerableOwnNames):

If an implementation defines a specific order of enumeration for the for-in statement, the same order must be used for the elements of the array returned in step 3.

Not sure why this is in normative test and not a note, especially seeing this logic in EnumerableOwnNames; I brought this up previously at tc39/proposal-object-values-entries#6 .

We could do a similar thing here, maybe. For example,

5- If this is an ordinary object and an implementation defines a specific order of enumeration for [[Enumerate]] for this kind of Object, reorder the elements of names so they are in the same relative order as the output of [[Enumerate]].

Another funny thing about it is that a for-in loop/[[Enumerate]] will only have String keys, whereas EnumerableOwnNames may have Symbol keys, but maybe we can just assume that the Symbols are left at the end. So the spec text could read something like,

5- If this is an ordinary object and an implementation defines a specific order of enumeration for [[Enumerate]] for this kind of Object, reorder the elements of names so they are in the same relative order as the output of [[Enumerate]], leaving any Symbol elements at the end.

Member

littledan commented Nov 19, 2015

Some other language which doesn't have these proxy implications can be found at the end of Object.keys (which calls EnumerableOwnNames):

If an implementation defines a specific order of enumeration for the for-in statement, the same order must be used for the elements of the array returned in step 3.

Not sure why this is in normative test and not a note, especially seeing this logic in EnumerableOwnNames; I brought this up previously at tc39/proposal-object-values-entries#6 .

We could do a similar thing here, maybe. For example,

5- If this is an ordinary object and an implementation defines a specific order of enumeration for [[Enumerate]] for this kind of Object, reorder the elements of names so they are in the same relative order as the output of [[Enumerate]].

Another funny thing about it is that a for-in loop/[[Enumerate]] will only have String keys, whereas EnumerableOwnNames may have Symbol keys, but maybe we can just assume that the Symbols are left at the end. So the spec text could read something like,

5- If this is an ordinary object and an implementation defines a specific order of enumeration for [[Enumerate]] for this kind of Object, reorder the elements of names so they are in the same relative order as the output of [[Enumerate]], leaving any Symbol elements at the end.

@rossberg

This comment has been minimized.

Show comment
Hide comment
@rossberg

rossberg Nov 19, 2015

Member

Since [[Enumerate]] will normally group the properties per object on the prototype chain, I don't think it's right to put all symbols at the end. They'd at least have to be interleaved such that they are at the end of each respective object's group.

Member

rossberg commented Nov 19, 2015

Since [[Enumerate]] will normally group the properties per object on the prototype chain, I don't think it's right to put all symbols at the end. They'd at least have to be interleaved such that they are at the end of each respective object's group.

@anba

This comment has been minimized.

Show comment
Hide comment
@anba

anba Nov 19, 2015

Contributor

Symbol-valued property keys are already filtered in the EnumerableOwnNames loop.

Contributor

anba commented Nov 19, 2015

Symbol-valued property keys are already filtered in the EnumerableOwnNames loop.

@rossberg

This comment has been minimized.

Show comment
Hide comment
@rossberg

rossberg Nov 19, 2015

Member

Good point! :)

Member

rossberg commented Nov 19, 2015

Good point! :)

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Nov 19, 2015

Member

Oops, another spec misreading on my part! @anba what do you think of the rest of the rewording, clarifying that the correspondence with for-in is only guaranteed for ordinary Objects? I don't think this is a big normative change or needs discussion at TC39.

Member

littledan commented Nov 19, 2015

Oops, another spec misreading on my part! @anba what do you think of the rest of the rewording, clarifying that the correspondence with for-in is only guaranteed for ordinary Objects? I don't think this is a big normative change or needs discussion at TC39.

@anba

This comment has been minimized.

Show comment
Hide comment
@anba

anba Nov 19, 2015

Contributor

The reordering should also happen for Array or Arguments objects, so I'd propose to use:

  1. If O.[[Enumerate]] is the ordinary object [[Enumerate]] internal method (9.1.11), then
    1. Order the elements of names so they are in the same relative order as would be produced by the Iterator that would be returned if the [[Enumerate]] internal method was invoked on O.
Contributor

anba commented Nov 19, 2015

The reordering should also happen for Array or Arguments objects, so I'd propose to use:

  1. If O.[[Enumerate]] is the ordinary object [[Enumerate]] internal method (9.1.11), then
    1. Order the elements of names so they are in the same relative order as would be produced by the Iterator that would be returned if the [[Enumerate]] internal method was invoked on O.
@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Nov 19, 2015

Member

@anba How could you evaluate what order would be produced by the iterator if O is a Proxy?

Member

littledan commented Nov 19, 2015

@anba How could you evaluate what order would be produced by the iterator if O is a Proxy?

@anba

This comment has been minimized.

Show comment
Hide comment
@anba

anba Nov 19, 2015

Contributor

I don't understand that question. If O is a Proxy, then O.[[Enumerate]] is not the ordinary object [[Enumerate]] internal method.

Contributor

anba commented Nov 19, 2015

I don't understand that question. If O is a Proxy, then O.[[Enumerate]] is not the ordinary object [[Enumerate]] internal method.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Nov 21, 2015

Member

Oh, I see. Yes, that spec text looks good to me.

Member

littledan commented Nov 21, 2015

Oh, I see. Yes, that spec text looks good to me.

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Dec 8, 2015

Member

Sorry for the delay here. Going to implement @anba's proposal now.

Member

bterlson commented Dec 8, 2015

Sorry for the delay here. Going to implement @anba's proposal now.

@bterlson bterlson closed this in 8891350 Dec 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment