Ignore:
Timestamp:
Feb 2, 2004, 5:18:18 PM (21 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • fixed <rdar://problem/3546613>: array of negative size leads to crash (test page at oscar.the-rileys.net)
  • kjs/array_object.cpp: (ArrayInstanceImp::ArrayInstanceImp): If the length is greater than 10,000, don't allocate an array until we start putting values in. This prevents new Array(2147483647) from causing trouble. (ArrayObjectImp::construct): Check number as described in specification, and raise a range error if the number is out of range. This prevents new Array(-1) from causing trouble.
  • fixed <rdar://problem/3545756>: Math.round screws up on numbers bigger than 231 (incorrect results on HP-35 calculator page)
  • kjs/math_object.cpp: (MathFuncImp::call): Change implementation to be much simpler and not involve casting to int. Results now match those in other browsers.
File:
1 edited

Legend:

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

    r6025 r6028  
    4646  : ObjectImp(proto)
    4747  , length(initialLength)
    48   , storageLength(initialLength)
     48  , storageLength(initialLength < sparseArrayCutoff ? initialLength : 0)
    4949  , capacity(storageLength)
    5050  , storage(capacity ? (ValueImp **)calloc(capacity, sizeof(ValueImp *)) : 0)
     
    796796{
    797797  // a single numeric argument denotes the array size (!)
    798   if (args.size() == 1 && args[0].type() == NumberType)
    799     return Object(new ArrayInstanceImp(exec->interpreter()->builtinArrayPrototype().imp(), args[0].toUInt32(exec)));
     798  if (args.size() == 1 && args[0].type() == NumberType) {
     799    uint32_t n = args[0].toUInt32(exec);
     800    if (n != args[0].toNumber(exec)) {
     801      Object error = Error::create(exec, RangeError, "Array size is not a small enough positive integer.");
     802      exec->setException(error);
     803      return error;
     804    }
     805    return Object(new ArrayInstanceImp(exec->interpreter()->builtinArrayPrototype().imp(), n));
     806  }
    800807
    801808  // otherwise the array is constructed with the arguments in it
Note: See TracChangeset for help on using the changeset viewer.