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/internal.cpp

    r5314 r6025  
    961961double KJS::roundValue(ExecState *exec, const Value &v)
    962962{
    963   if (v.type() == UndefinedType) /* TODO: see below */
    964     return 0.0;
    965963  Number n = v.toNumber(exec);
    966   if (n.value() == 0.0)   /* TODO: -0, NaN, Inf */
    967     return 0.0;
    968   double d = floor(fabs(n.value()));
    969   if (n.value() < 0)
    970     d *= -1;
    971 
    972   return d;
     964  double d = n.value();
     965  double ad = fabs(d);
     966  if (ad == 0 || isNaN(d) || isInf(d))
     967    return d;
     968  return copysign(floor(ad), d);
    973969}
    974970
Note: See TracChangeset for help on using the changeset viewer.