[Webkit-unassigned] [Bug 95309] New: Sorting array with objects using a custom function returns strange result if array length > 10

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Aug 29 01:17:20 PDT 2012


https://bugs.webkit.org/show_bug.cgi?id=95309

           Summary: Sorting array with objects using a custom function
                    returns strange result if array length > 10
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: Macintosh Intel
        OS/Version: Mac OS X 10.7
            Status: UNCONFIRMED
          Severity: Major
          Priority: P3
         Component: JavaScriptCore
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: mail at ickata.net


I have array with objects, which have a key on which I want to sort. It's obvious I have to use custom sorting fn. 

When the array length is <= 10 everything works as it should. But if the array has > 10 elements in it sorting screws up.

Here are two examples:

1. Open JavaScript console in Google Chrome/Apple Safari browser and copy paste the following code & execute:

JSON.stringify( [{p:'03'},{p:'06'},{p:'10'},{p:'01'},{p:'04'},{p:'02'},{p:'05'},{p:'08'},{p:'07'},{p:'09'}].sort( function ( a, b ) {
  return b.p < a.p;
}) );

Returned result is correct:

"[{"p":"01"},{"p":"02"},{"p":"03"},{"p":"04"},{"p":"05"},{"p":"06"},{"p":"07"},{"p":"08"},{"p":"09"},{"p":"10"}]"

2. Now lets add 1 more element to the array:

JSON.stringify( [{p:'03'},{p:'06'},{p:'10'},{p:'01'},{p:'04'},{p:'02'},{p:'05'},{p:'08'},{p:'07'},{p:'09'},{p:'11'}].sort( function ( a, b ) {
  return b.p < a.p;
}) );

Returned result is wrong:

"[{"p":"02"},{"p":"03"},{"p":"01"},{"p":"04"},{"p":"05"},{"p":"06"},{"p":"07"},{"p":"08"},{"p":"09"},{"p":"10"},{"p":"11"}]"

Issue not observed in all non-webkit browsers (Firefox, IE).

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list