Comment #29 on issue 883 by brettz9: for in loops don't occur in defined order http://code.google.com/p/chromium/issues/detail?id=883
I'm confused by this statement, "ECMAScript 5 defines the order of iteration as being the order of insertion, that means this behaviour is now non-actual standard, in addition to just being non-defacto standard." From what I can see from 12.6.4 at http://www.ecmascript.org/docs/tc39-2009-043.pdf on the for...in loop, "The mechanics and order of enumerating the properties...is not specified". I'm also confused because it seems like Chrome 3.0.195.33 is working fine with for...in iteration. If it is true that "order of iteration" is the "order of insertion", being within for...in loops should presumably be an exception since properties inserted there are not supposed to be iterated ("If new properties are added to the object being enumerated during enumeration, the newly added properties are guaranteed not to be visited in the active enumeration." sec. 12.6.4)). One item I do not see specified in the spec is whether deletion of properties should require reinsertion of a given key to be added back retaining no memory of the previous deleted properties' order. Explorer does apparently retain such memory, preventing objects from being universally sortable across browsers (without the object itself being wholly redefined). Note that the problem in the following (in IE) is not for...in order, but retension of order info on deleted properties since reinserting a deleted property will see it added back in its previous relative order, not after the other properties: function reverseObj (obj) { var keys = [], vals = []; for (var p in obj) { keys.push(p); vals.push(obj[p]); delete obj[p]; } keys.reverse(); vals.reverse(); for (var i=0; i < keys.length; ++i) { obj[keys[i]] = vals[i]; // In IE the original property order is remembered, despite having been deleted above! } } var assoc = {a: 'orange', b: 'banana', c: 'apple', d: 'lemon'}; reverseObj(assoc); // No effect in IE, but does in all other browsers As someone who finds it extremely useful to not only iterate objects in order, but also have control over their sequence, I hope that if the new spec does require iteration to follow order of insertion, that insertion will also be required to disregard previously deleted properties. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings -- Automated mail from issue updates at http://crbug.com/ Subscription options: http://groups.google.com/group/chromium-bugs
