Ignore:
Timestamp:
Sep 15, 2008, 2:39:26 AM (17 years ago)
Author:
[email protected]
Message:

2008-09-15 Cameron Zwarich <[email protected]>

Reviewed by Maciej Stachowiak.

Bug 20851: REGRESSION (r36410): fast/js/kde/GlobalObject.html fails
<https://bugs.webkit.org/show_bug.cgi?id=20851>

r36410 introduced an optimization for parseInt() that is incorrect when
its argument is larger than the range of a 32-bit integer. If the
argument is a number that is not an immediate integer, then the correct
behaviour is to return the floor of its value, unless it is an infinite
value, in which case the correct behaviour is to return 0.

JavaScriptCore:

  • kjs/JSGlobalObjectFunctions.cpp: (JSC::globalFuncParseInt):

LayoutTests:

  • fast/js/numeric-conversion-expected.txt:
  • fast/js/resources/numeric-conversion.js:
File:
1 edited

Legend:

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

    r36410 r36434  
    298298    int32_t radix = args.at(exec, 1)->toInt32(exec);
    299299
    300     if (value->isNumber() && (radix == 0 || radix == 10))
    301         return jsNumber(exec, value->toInt32(exec));
     300    if (value->isNumber() && (radix == 0 || radix == 10)) {
     301        if (JSImmediate::isImmediate(value))
     302            return value;
     303        double d = value->uncheckedGetNumber();
     304        if (!isfinite(d))
     305            return JSImmediate::zeroImmediate();
     306        return jsNumber(exec, floor(d));
     307    }
    302308
    303309    return jsNumber(exec, parseInt(value->toString(exec), radix));
Note: See TracChangeset for help on using the changeset viewer.