Ignore:
Timestamp:
Feb 2, 2004, 1:23:17 PM (21 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • fixed <rdar://problem/3519285>: integer operations on large negative numbers yield bad results (discovered with "HTMLCrypt")
  • fixed other related overflow issues
  • kjs/value.h: Changed return types of toInteger, toInt32, toUInt32, and toUInt16.
  • kjs/value.cpp: (ValueImp::toInteger): Change to return a double, since this operation, from the ECMA specification, must not restrict values to the range of a particular integer type. (ValueImp::toInt32): Used a sized integer type for the result of this function, and also added proper handling for negative results from fmod. (ValueImp::toUInt32): Ditto. (ValueImp::toUInt16): Ditto. (ValueImp::dispatchToUInt32): Changed result type from unsigned to uint32_t.
  • kjs/array_object.cpp: (ArrayProtoFuncImp::call): Use a double instead of an int to handle out-of-integer-range values better in the slice function.
  • kjs/internal.cpp: (KJS::roundValue): Streamline the function, handling NAN and infinity properly.
  • kjs/number_object.cpp: (NumberProtoFuncImp::call): Use a double instead of an int to handle out-of-integer-range values better in the toString function.
  • kjs/string_object.cpp: (StringProtoFuncImp::call): Use a double instead of an int to handle out-of-integer-range values better in the charAt, charCodeAt, indexOf, lastIndexOf, slice, and substr functions.
File:
1 edited

Legend:

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

    r5645 r6025  
    581581    Object resObj = Object::dynamicCast(exec->interpreter()->builtinArray().construct(exec,List::empty()));
    582582    result = resObj;
    583     int begin = args[0].toInteger(exec);
    584     if ( begin < 0 )
    585       begin = maxInt( begin + length, 0 );
    586     else
    587       begin = minInt( begin, length );
    588     int end = length;
    589     if (args[1].type() != UndefinedType)
    590     {
     583    double begin = args[0].toInteger(exec);
     584    if (begin < 0) {
     585      begin += length;
     586      if (begin < 0)
     587        begin = 0;
     588    } else {
     589      if (begin > length)
     590        begin = length;
     591    }
     592    double end = length;
     593    if (args[1].type() != UndefinedType) {
    591594      end = args[1].toInteger(exec);
    592       if ( end < 0 )
    593         end = maxInt( end + length, 0 );
    594       else
    595         end = minInt( end, length );
     595      if (end < 0) {
     596        end += length;
     597        if (end < 0)
     598          end = 0;
     599      } else {
     600        if (end > length)
     601          end = length;
     602      }
    596603    }
    597604
    598605    //printf( "Slicing from %d to %d \n", begin, end );
    599606    int n = 0;
    600     for(int k = begin; k < end; k++, n++) {
     607    int b = static_cast<int>(begin);
     608    int e = static_cast<int>(end);
     609    for(int k = b; k < e; k++, n++) {
    601610      if (thisObj.hasProperty(exec, k)) {
    602611        Value obj = thisObj.get(exec, k);
Note: See TracChangeset for help on using the changeset viewer.