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

    r27011 r27095  
    276276    // milliseconds
    277277    if (idx < numArgs) {
    278         milliseconds += roundValue(exec, args[idx]);
     278        milliseconds += args[idx]->toNumber(exec);
    279279    } else {
    280280        milliseconds += *ms;
     
    552552    return jsNumber(-gmtoffset(t) / minutesPerHour);
    553553  case SetTime:
    554     milli = roundValue(exec, args[0]);
     554    milli = timeClip(args[0]->toNumber(exec));
    555555    result = jsNumber(milli);
    556556    thisDateObj->setInternalValue(result);
     
    649649      t.month = args[1]->toInt32(exec);
    650650      t.monthDay = (numArgs >= 3) ? args[2]->toInt32(exec) : 1;
    651       t.hour = (numArgs >= 4) ? args[3]->toInt32(exec) : 0;
    652       t.minute = (numArgs >= 5) ? args[4]->toInt32(exec) : 0;
    653       t.second = (numArgs >= 6) ? args[5]->toInt32(exec) : 0;
     651      t.hour = args[3]->toInt32(exec);
     652      t.minute = args[4]->toInt32(exec);
     653      t.second = args[5]->toInt32(exec);
    654654      t.isDST = -1;
    655       double ms = (numArgs >= 7) ? roundValue(exec, args[6]) : 0;
     655      double ms = (numArgs >= 7) ? args[6]->toNumber(exec) : 0;
    656656      value = gregorianDateTimeToMS(t, ms, false);
    657657    }
     
    703703    t.month = args[1]->toInt32(exec);
    704704    t.monthDay = (n >= 3) ? args[2]->toInt32(exec) : 1;
    705     t.hour = (n >= 4) ? args[3]->toInt32(exec) : 0;
    706     t.minute = (n >= 5) ? args[4]->toInt32(exec) : 0;
    707     t.second = (n >= 6) ? args[5]->toInt32(exec) : 0;
    708     double ms = (n >= 7) ? roundValue(exec, args[6]) : 0;
     705    t.hour = args[3]->toInt32(exec);
     706    t.minute = args[4]->toInt32(exec);
     707    t.second = args[5]->toInt32(exec);
     708    double ms = (n >= 7) ? args[6]->toNumber(exec) : 0;
    709709    return jsNumber(gregorianDateTimeToMS(t, ms, true));
    710710  }
     
    10851085    if (!isfinite(t))
    10861086        return NaN;
    1087     double at = fabs(t);
    1088     if (at > 8.64E15)
     1087    if (fabs(t) > 8.64E15)
    10891088        return NaN;
    1090     return copysign(floor(at), t);
    1091 }
    1092 
    1093 }
     1089    return trunc(t);
     1090}
     1091
     1092}
Note: See TracChangeset for help on using the changeset viewer.