Changeset 5436 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Nov 10, 2003, 8:31:34 AM (22 years ago)
Author:
darin
Message:

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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r4792 r5436  
    280280{
    281281    ExecState *exec = execForCompareByStringForQSort;
    282     return compare(Value(*(ValueImp **)a).toString(exec), Value(*(ValueImp **)b).toString(exec));
     282    ValueImp *va = *(ValueImp **)a;
     283    ValueImp *vb = *(ValueImp **)b;
     284    if (va->dispatchType() == UndefinedType) {
     285        return vb->dispatchType() == UndefinedType ? 0 : 1;
     286    }
     287    if (vb->dispatchType() == UndefinedType) {
     288        return -1;
     289    }
     290    return compare(va->dispatchToString(exec), vb->dispatchToString(exec));
    283291}
    284292
     
    313321{
    314322    CompareWithCompareFunctionArguments *args = compareWithCompareFunctionArguments;
    315    
     323
     324    ValueImp *va = *(ValueImp **)a;
     325    ValueImp *vb = *(ValueImp **)b;
     326    if (va->dispatchType() == UndefinedType) {
     327        return vb->dispatchType() == UndefinedType ? 0 : 1;
     328    }
     329    if (vb->dispatchType() == UndefinedType) {
     330        return -1;
     331    }
     332
    316333    args->arguments.clear();
    317     args->arguments.append(*(ValueImp **)a);
    318     args->arguments.append(*(ValueImp **)b);
    319     return args->compareFunction->call(args->exec, args->globalObject, args->arguments)
    320         .toInt32(args->exec);
     334    args->arguments.append(va);
     335    args->arguments.append(vb);
     336    double compareResult = args->compareFunction->call
     337        (args->exec, args->globalObject, args->arguments).toNumber(args->exec);
     338    return compareResult < 0 ? -1 : compareResult > 0 ? 1 : 0;
    321339}
    322340
     
    626644          {
    627645            Value jObj = thisObj.get(exec,j);
    628             int cmp;
     646            double cmp;
    629647            if (jObj.type() == UndefinedType) {
    630               cmp = 1;
     648              cmp = 1; // don't check minObj because there's no need to differentiate == (0) from > (1)
    631649            } else if (minObj.type() == UndefinedType) {
    632650              cmp = -1;
     
    635653                l.append(jObj);
    636654                l.append(minObj);
    637                 cmp = sortFunction.call(exec, exec->interpreter()->globalObject(), l).toInt32(exec);
     655                cmp = sortFunction.call(exec, exec->interpreter()->globalObject(), l).toNumber(exec);
    638656            } else {
    639657              cmp = (jObj.toString(exec) < minObj.toString(exec)) ? -1 : 1;
Note: See TracChangeset for help on using the changeset viewer.