[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:10:35 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 4b5e64449d1b57cf5792a8e75f751c3400895672
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Nov 10 16:31:34 2003 +0000

            Reviewed by John.
    
            - fixed 3477528 -- array.sort(function) fails if the function returns a non-zero value that rounds to zero
    
            * kjs/array_object.cpp:
            (compareByStringForQSort): Added checks for undefined values to match what the specification calls for.
            (compareWithCompareFunctionForQSort): Added checks for undefined values as above, and also changed the
            code that looks at the compare function result to look at the number returned without rounding to an integer.
            (ArrayProtoFuncImp::call): Changed the code that looks at the compare function result to look at the number
            returned without rounding to an integer.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5436 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 407a140..d001139 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,16 @@
+2003-11-08  Darin Adler  <darin at apple.com>
+
+        Reviewed by John.
+
+        - fixed 3477528 -- array.sort(function) fails if the function returns a non-zero value that rounds to zero
+
+        * kjs/array_object.cpp:
+        (compareByStringForQSort): Added checks for undefined values to match what the specification calls for.
+        (compareWithCompareFunctionForQSort): Added checks for undefined values as above, and also changed the
+        code that looks at the compare function result to look at the number returned without rounding to an integer.
+        (ArrayProtoFuncImp::call): Changed the code that looks at the compare function result to look at the number
+        returned without rounding to an integer.
+
 === Safari-113 ===
 
 2003-11-03  Vicki Murley <vicki at apple.com>
diff --git a/JavaScriptCore/kjs/array_object.cpp b/JavaScriptCore/kjs/array_object.cpp
index f25790a..61fe2ff 100644
--- a/JavaScriptCore/kjs/array_object.cpp
+++ b/JavaScriptCore/kjs/array_object.cpp
@@ -279,7 +279,15 @@ static ExecState *execForCompareByStringForQSort;
 static int compareByStringForQSort(const void *a, const void *b)
 {
     ExecState *exec = execForCompareByStringForQSort;
-    return compare(Value(*(ValueImp **)a).toString(exec), Value(*(ValueImp **)b).toString(exec));
+    ValueImp *va = *(ValueImp **)a;
+    ValueImp *vb = *(ValueImp **)b;
+    if (va->dispatchType() == UndefinedType) {
+        return vb->dispatchType() == UndefinedType ? 0 : 1;
+    }
+    if (vb->dispatchType() == UndefinedType) {
+        return -1;
+    }
+    return compare(va->dispatchToString(exec), vb->dispatchToString(exec));
 }
 
 void ArrayInstanceImp::sort(ExecState *exec)
@@ -312,12 +320,22 @@ static CompareWithCompareFunctionArguments *compareWithCompareFunctionArguments;
 static int compareWithCompareFunctionForQSort(const void *a, const void *b)
 {
     CompareWithCompareFunctionArguments *args = compareWithCompareFunctionArguments;
-    
+
+    ValueImp *va = *(ValueImp **)a;
+    ValueImp *vb = *(ValueImp **)b;
+    if (va->dispatchType() == UndefinedType) {
+        return vb->dispatchType() == UndefinedType ? 0 : 1;
+    }
+    if (vb->dispatchType() == UndefinedType) {
+        return -1;
+    }
+
     args->arguments.clear();
-    args->arguments.append(*(ValueImp **)a);
-    args->arguments.append(*(ValueImp **)b);
-    return args->compareFunction->call(args->exec, args->globalObject, args->arguments)
-        .toInt32(args->exec);
+    args->arguments.append(va);
+    args->arguments.append(vb);
+    double compareResult = args->compareFunction->call
+        (args->exec, args->globalObject, args->arguments).toNumber(args->exec);
+    return compareResult < 0 ? -1 : compareResult > 0 ? 1 : 0;
 }
 
 void ArrayInstanceImp::sort(ExecState *exec, Object &compareFunction)
@@ -625,16 +643,16 @@ Value ArrayProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args
         for ( unsigned int j = i+1 ; j<length ; ++j )
           {
             Value jObj = thisObj.get(exec,j);
-            int cmp;
+            double cmp;
             if (jObj.type() == UndefinedType) {
-              cmp = 1;
+              cmp = 1; // don't check minObj because there's no need to differentiate == (0) from > (1)
             } else if (minObj.type() == UndefinedType) {
               cmp = -1;
             } else if (useSortFunction) {
                 List l;
                 l.append(jObj);
                 l.append(minObj);
-                cmp = sortFunction.call(exec, exec->interpreter()->globalObject(), l).toInt32(exec);
+                cmp = sortFunction.call(exec, exec->interpreter()->globalObject(), l).toNumber(exec);
             } else {
               cmp = (jObj.toString(exec) < minObj.toString(exec)) ? -1 : 1;
             }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list