Skip to content
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

Enumeration order incorrect with deletes #4486

Open
bterlson opened this issue Dec 29, 2017 · 2 comments
Open

Enumeration order incorrect with deletes #4486

bterlson opened this issue Dec 29, 2017 · 2 comments

Comments

@bterlson
Copy link
Contributor

let obj = {x: 1, y: 2};
obj.p1 = 1;
obj.p2 = 2;
delete obj.p1;
obj.p1 = 1;

let str = '';
for (prop in obj) {
    str += '<' + prop + '> ';
}

print(str);

┌─────────────────────┬───────────────────┐
│ Chakra              │ <x> <y> <p1> <p2> │
├─────────────────────┼───────────────────┤
│ JavaScriptCore      │ <x> <y> <p2> <p1> │
│ SpiderMonkey        │                   │
│ V8                  │                   │
└─────────────────────┴───────────────────┘

JSC, SM, and V8 have the proper behavior here. The spec requires that own properties are enumerated in order of creation. In the example above, p1 is the last property created and so should be last (the fact that it existed before is not relevant).

@VSadov
Copy link
Contributor

VSadov commented Apr 19, 2018

possibly the same as #3505

@bakkot
Copy link

bakkot commented Sep 11, 2018

The spec does not actually require this (or any) order for for-in, though I would like it to and may try to get consensus on a normative change. But this is observable with for example Reflect.ownKeys, which uses OrdinaryOwnPropertyKeys directly without the "The mechanics and order of enumerating the properties is not specified" escape hatch present in EnumerateObjectProperties (which is what for-in uses).

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

No branches or pull requests

7 participants