Ignore:
Timestamp:
Oct 26, 2007, 12:51:25 AM (18 years ago)
Author:
darin
Message:

JavaScriptCore:

Reviewed by Maciej.

Gives about 1% gain on SunSpider.

  • kjs/value.h: Added toIntegerPreserveNan, removed toUInt16. (KJS::JSValue::toInt32): Changed to call getTruncatedInt32 in a way that works with both immediate and number values. (KJS::JSValue::toUInt32): Ditto.
  • kjs/value.cpp: (KJS::JSValue::toInteger): Moved the logic from roundValue here, with a couple differences. One is that it now correctly returns 0 for NaN, and another is that there's no special case for 0 or infinity, since the general case already handles those correctly. (KJS::JSValue::toIntegerPreserveNaN): Added. Like toInteger, but without the check for NaN. (KJS::JSValue::toInt32SlowCase): Call toNumber instead of roundValue. The truncation done by the typecast already does the necessary truncation that roundValue was doing. (KJS::JSValue::toUInt32SlowCase): Ditto. (KJS::JSValue::toUInt16): Removed.
  • kjs/internal.h: Removed roundValue.
  • kjs/internal.cpp: Ditto.
  • kjs/array_object.cpp: (KJS::ArrayProtoFunc::callAsFunction): Remove unneeded code to handle NaN in Array.slice; toInteger now never returns NaN as specified.
  • kjs/date_object.cpp: (KJS::fillStructuresUsingTimeArgs): Replaced call to roundValue with a call to toNumber as specified. (KJS::DateProtoFunc::callAsFunction): In SetTime case, replaced call to roundValue with a call to toNumber and timeClip as specified. (KJS::DateObjectImp::construct): Removed unnecessary checks of numArgs in cases where the default behavior of toInt32 (returning 0) was already correct. Replaced call to roundValue with a call to toNumber as specified. (KJS::DateObjectFuncImp::callAsFunction): Ditto.
  • kjs/math_object.cpp: (MathFuncImp::callAsFunction): Removed unnecessary special cases for the pow function that the library already handles correctly.
  • kjs/number_object.cpp: (NumberProtoFunc::callAsFunction): Changed ToString to call toIntegerPreserveNaN, so we can continue to handle the NaN case differently. The real toInteger now returns 0 for NaN. Took out unneeded special case in ToFixed for undefined; was only needed because our toInteger was wrong. Same thing in ToExponential. Changed ToPrecision to call toIntegerPreserveNaN.
  • kjs/string_object.cpp: (KJS::StringProtoFunc::callAsFunction): Took out CharAt and CharCodeAt special cases for undefined that were only needed because toInteger was wrong. Same in IndexOf, and was able to remove some special cases. In LastIndexOf, used toIntegerPreserveNaN, but was able to remove some special cases there too. Changed Substr implementation to preserve correct behavior with the change to toInteger and match the specification. Also made sure we weren't converting an out of range double to an int. (KJS::StringObjectFuncImp::callAsFunction): Changed constructor to just use toUInt32, because truncating toUInt32 to 16 bits is the same thing and there's no reason to have toUInt16 as a second, less-optimized function that's only called at this one call site.
  • wtf/MathExtras.h: Added trunc function for Windows.

LayoutTests:

Reviewed by Maciej.

  • fast/js/resources/char-at.js: Updated test to expect that we get the first character if we pass NaN to charAt and charCodeAt; it's what the specification asks for and matches other browsers too.
  • fast/js/char-at-expected.txt: Updated.
File:
1 edited

Legend:

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

    r27011 r27095  
    254254    JSObject *resObj = static_cast<JSObject *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty()));
    255255    result = resObj;
    256     double begin = 0;
    257     if (!args[0]->isUndefined()) {
    258         begin = args[0]->toInteger(exec);
    259         if (begin >= 0) { // false for NaN
    260             if (begin > length)
    261                 begin = length;
    262         } else {
    263             begin += length;
    264             if (!(begin >= 0)) // true for NaN
    265                 begin = 0;
    266         }
    267     }
    268     double end = length;
    269     if (!args[1]->isUndefined()) {
     256    double begin = args[0]->toInteger(exec);
     257    if (begin >= 0) {
     258      if (begin > length)
     259        begin = length;
     260    } else {
     261      begin += length;
     262      if (begin < 0)
     263        begin = 0;
     264    }
     265    double end;
     266    if (args[1]->isUndefined())
     267      end = length;
     268    else {
    270269      end = args[1]->toInteger(exec);
    271       if (end < 0) { // false for NaN
     270      if (end < 0) {
    272271        end += length;
    273272        if (end < 0)
    274273          end = 0;
    275274      } else {
    276         if (!(end <= length)) // true for NaN
     275        if (end > length)
    277276          end = length;
    278277      }
    279278    }
    280279
    281     //printf( "Slicing from %d to %d \n", begin, end );
    282280    int n = 0;
    283281    int b = static_cast<int>(begin);
     
    550548
    551549    int index = length - 1;
    552     double d = args[1]->toInteger(exec);
     550    double d = args[1]->toIntegerPreserveNaN(exec);
    553551
    554552    if (d < 0) {
Note: See TracChangeset for help on using the changeset viewer.