[Webkit-unassigned] [Bug 37123] New: Sorting array of objects fails.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Apr 5 16:05:04 PDT 2010


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

           Summary: Sorting array of objects fails.
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: Macintosh Intel
        OS/Version: Mac OS X 10.6
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: berry at kerch.com


Debugging a cross browser bug in my company's product I came across this.  I'm
not certain what aspect of the JS sort method is involved.  The situation is we
have and array of objects, each of which has a "name" property that's a string.
 We want to sort the array, so I called

sorted_ar = ar.sort(function(a,b){
    return a.name > b.name;
});

This worked fine in Firefox on Windows and Snow Leopard, in Chrome on Windows
and Snow Leopard, but failed in IE7 (meh) and Safari on both platforms.  I
tried the WebKit nightly build (Version 4.0.4 (6531.21.10, r57054)) and it
failed there too.  

Here's a complete test case:

-----
var ar = new Array();
if (console == undefined) {
    var console = {
    log : function(s) { print(s) }
    }
 }
ar[0] = {name: "zzz"};
ar[1] = {name: "qqq"};
ar[2] = {name: "mmm"};
ar[3] = {name: "aaa"};

function dump(a) {
    for(i=0; i< a.length; i++) {
        console.log(i + ": "+a[i].name);
    }
}


dump(ar);
console.log("sorting");
sorted_ar = ar.sort(function(a,b){
    console.log("services.sort: comparing "+a.name+" to "+b.name);
    return a.name > b.name;
});

dump(ar);
-----
(I added the console definition so it would run in a command line JS shell).

The successful results look like this (FF/Mac):


----
0: zzz
1: qqq
2: mmm
3: aaa
sorting
services.sort: comparing zzz to qqq
services.sort: comparing zzz to mmm
services.sort: comparing qqq to mmm
services.sort: comparing zzz to aaa
services.sort: comparing qqq to aaa
services.sort: comparing mmm to aaa
0: aaa
1: mmm
2: qqq
3: zzz
----

and the failing ones like thi (Safari/Mac)s:

----
0: zzz
1: qqq
2: mmm
3: aaa
sorting
services.sort: comparing qqq to zzz
services.sort: comparing mmm to zzz
services.sort: comparing mmm to qqq
services.sort: comparing aaa to qqq
services.sort: comparing aaa to mmm
0: zzz
1: qqq
2: mmm
3: aaa
----

This should be easy to reproduce by opening a WebInspector window and pasting
the test code into the console.

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