Status: Unconfirmed
Owner: ----
Labels: Type-Bug Pri-2 OS-All Area-Misc

New issue 21497 by nulldevice.eu: Object and Array property handling is a  
mess; properties are returned in unpredictable order
http://code.google.com/p/chromium/issues/detail?id=21497

Chrome Version       : 2.0.172.43
URLs (if applicable) : http://www.nulldevice.de/2009/09/chrome-bug-tester/
Other browsers tested:
   Add OK or FAIL after other browsers where you have tested this issue:
      Safari 4: OK
   Firefox 3.5: OK
          IE 7: OK
          IE 8: OK
Opera 10: OK

What steps will reproduce the problem?
1. Create an array or object with a number of elements, preferably numbers  
> 1034 or mixed
number/string keys for objects
2. Loop over it with for(var i in object)

What is the expected result?
All tests are green.

Values are returned in the order, in which they were added. This is not  
needed for Arrays, but at
least for normal Objects. Having a predictable order also has a benefit for  
polymorphic inline
caching, because the address offset probably is probably different, if the  
values are stored in
different orders.

Otherwise, it causes overhead to store values in a certain order in JS. So  
this behavior makes a
lot of sense and is used in many existing applications.

The behavior of Objects and Arrays is the same in Chrome, and that's why I  
tested it this way,
because there is just one base object class and the rest is implemented via  
JS afterwards. JSC is
different in this respect. I just wanted to make sure, the code I saw  
corresponds to the observed
behavior.

What happens instead?
Chrome returns values in pseudo-random order and handles small ints  
differently than string
keys and large number keys > 1034.

Please provide any additional information below. Attach a screenshot if
possible.

I suggest storing the properties like JavaScriptCore does it:

inline JSValue JSObject::get(ExecState* exec, const Identifier&  
propertyName) const
{
PropertySlot slot(this);
if (const_cast(this)->getPropertySlot(exec, propertyName, slot))
return slot.getValue(exec, propertyName);

return jsUndefined();
}

Also see this comment in JSC, which states that a predictable object order  
is a de-facto standard:

// lastIndexUsed is an ever-increasing index used to identify the order  
items
// were inserted into the property map. It’s required that  
getEnumerablePropertyNames
// return the properties in the order they were added for compatibility  
with other
// browsers’ JavaScript implementations.

--
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to