Changeset 26899 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Oct 22, 2007, 4:36:36 PM (18 years ago)
Author:
darin
Message:

JavaScriptCore:

Reviewed by Geoff.

One of the JavaScriptCore tests was failing; it failed because of
my change to NumberImp::getUInt32. The incorrect code I copied was
from JSImmediate::getUInt32, and was a pre-existing bug.

This patch fixes correctness, but will surely slow down SunSpider.
We may be able to code this tighter and get the speed back.

  • kjs/JSImmediate.h: (KJS::JSImmediate::getInt32): Renamed from toInt32 to more accurately reflect the fact that this function only returns true if the value is accurate (no fractional part, etc.). Changed code so that it returns false when the value has a fraction. (KJS::JSImmediate::getUInt32): Ditto.
  • kjs/internal.cpp: (KJS::NumberImp::getInt32): Changed code so that it returns false when the value has a fraction. Restores the old behavior. (KJS::NumberImp::getUInt32): Ditto.
  • kjs/value.h: (KJS::JSValue::getInt32): Updated for name change. (KJS::JSValue::getUInt32): Ditto. (KJS::JSValue::toInt32): Ditto. (KJS::JSValue::toUInt32): Ditto.

LayoutTests:

Reviewed by Geoff.

Added tests for cases where you use something that looks like an array
index, but it has a fractional part.

  • fast/js/kde/resources/Array.js: Added tests.
  • fast/js/kde/Array-expected.txt: Updated.
Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r26897 r26899  
     12007-10-22  Darin Adler  <[email protected]>
     2
     3        Reviewed by Geoff.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=15632
     6          js1_5/Array/array-001.js test failing
     7
     8        One of the JavaScriptCore tests was failing; it failed because of
     9        my change to NumberImp::getUInt32. The incorrect code I copied was
     10        from JSImmediate::getUInt32, and was a pre-existing bug.
     11
     12        This patch fixes correctness, but will surely slow down SunSpider.
     13        We may be able to code this tighter and get the speed back.
     14
     15        * kjs/JSImmediate.h:
     16        (KJS::JSImmediate::getInt32): Renamed from toInt32 to more accurately
     17        reflect the fact that this function only returns true if the value is
     18        accurate (no fractional part, etc.). Changed code so that it returns
     19        false when the value has a fraction.
     20        (KJS::JSImmediate::getUInt32): Ditto.
     21
     22        * kjs/internal.cpp:
     23        (KJS::NumberImp::getInt32): Changed code so that it returns false when
     24        the value has a fraction. Restores the old behavior.
     25        (KJS::NumberImp::getUInt32): Ditto.
     26
     27        * kjs/value.h:
     28        (KJS::JSValue::getInt32): Updated for name change.
     29        (KJS::JSValue::getUInt32): Ditto.
     30        (KJS::JSValue::toInt32): Ditto.
     31        (KJS::JSValue::toUInt32): Ditto.
     32
    1332007-10-22  Darin Adler  <[email protected]>
    234
  • trunk/JavaScriptCore/kjs/JSImmediate.h

    r26893 r26899  
    8888    static JSType type(const JSValue*);
    8989
    90     static bool toInt32(const JSValue*, int32_t&);
    91     static bool toUInt32(const JSValue*, uint32_t&);
     90    static bool getInt32(const JSValue*, int32_t&);
     91    static bool getUInt32(const JSValue*, uint32_t&);
    9292
    9393    // It would nice just to use fromDouble() to create these values, but that would prevent them from
     
    172172    }
    173173
    174     static bool toInt32(const JSValue* v, int32_t& i)
     174    static bool getInt32(const JSValue* v, int32_t& i)
    175175    {
    176176        ASSERT(isImmediate(v));
     
    179179        floatUnion.asBits = static_cast<uint32_t>(unTag(v));
    180180        float f = floatUnion.asFloat;
    181         if (!(f >= -2147483648.0F && f < 2147483648.0F))
    182             return false;
    183181        i = static_cast<int32_t>(f);
    184         return isNumber(v);
    185     }
    186 
    187     static bool toUInt32(const JSValue* v, uint32_t& i)
     182        return isNumber(v) && i == f;
     183    }
     184
     185    static bool getUInt32(const JSValue* v, uint32_t& i)
    188186    {
    189187        ASSERT(isImmediate(v));
     
    192190        floatUnion.asBits = static_cast<uint32_t>(unTag(v));
    193191        float f = floatUnion.asFloat;
    194         if (!(f >= 0.0F && f < 4294967296.0F))
    195             return false;
    196192        i = static_cast<uint32_t>(f);
    197         return isNumber(v);
     193        return isNumber(v) && i == f;
    198194    }
    199195};
     
    225221    }
    226222
    227     static bool toInt32(const JSValue* v, int32_t& i)
     223    static bool getInt32(const JSValue* v, int32_t& i)
    228224    {
    229225        double d = toDouble(v);
    230         if (!(d >= -2147483648.0 && d < 2147483648.0))
    231             return false;
    232226        i = static_cast<int32_t>(d);
    233         return isNumber(v);
    234     }
    235 
    236     static bool toUInt32(const JSValue* v, uint32_t& i)
     227        return isNumber(v) && i == d;
     228    }
     229
     230    static bool getUInt32(const JSValue* v, uint32_t& i)
    237231    {
    238232        double d = toDouble(v);
    239         if (!(d >= 0.0 && d < 4294967296.0))
    240             return false;
    241233        i = static_cast<uint32_t>(d);
    242         return isNumber(v);
     234        return isNumber(v) && i == d;
    243235    }
    244236};
     
    271263}
    272264
    273 inline bool JSImmediate::toInt32(const JSValue* v, int32_t& i)
    274 {
    275     return FPBitValues<is32bit, is64bit>::toInt32(v, i);
    276 }
    277 
    278 inline bool JSImmediate::toUInt32(const JSValue* v, uint32_t& i)
    279 {
    280     return FPBitValues<is32bit, is64bit>::toUInt32(v, i);
     265inline bool JSImmediate::getInt32(const JSValue* v, int32_t& i)
     266{
     267    return FPBitValues<is32bit, is64bit>::getInt32(v, i);
     268}
     269
     270inline bool JSImmediate::getUInt32(const JSValue* v, uint32_t& i)
     271{
     272    return FPBitValues<is32bit, is64bit>::getUInt32(v, i);
    281273}
    282274
  • trunk/JavaScriptCore/kjs/internal.cpp

    r26892 r26899  
    114114bool NumberImp::getInt32(int32_t& int32) const
    115115{
    116     if (!(val >= -2147483648.0 && val < 2147483648.0))
    117         return false;
    118116    int32 = static_cast<int32_t>(val);
    119     return true;
     117    return int32 == val;
    120118}
    121119
    122120bool NumberImp::getUInt32(uint32_t& uint32) const
    123121{
    124     if (!(val >= 0.0 && val < 4294967296.0))
    125         return false;
    126122    uint32 = static_cast<uint32_t>(val);
    127     return true;
     123    return uint32 == val;
    128124}
    129125
  • trunk/JavaScriptCore/kjs/value.h

    r26892 r26899  
    335335inline bool JSValue::getInt32(int32_t& v) const
    336336{
    337     return JSImmediate::isImmediate(this) ? JSImmediate::toInt32(this, v) : asCell()->getInt32(v);
     337    return JSImmediate::isImmediate(this) ? JSImmediate::getInt32(this, v) : asCell()->getInt32(v);
    338338}
    339339
    340340inline bool JSValue::getUInt32(uint32_t& v) const
    341341{
    342     return JSImmediate::isImmediate(this) ? JSImmediate::toUInt32(this, v) : asCell()->getUInt32(v);
     342    return JSImmediate::isImmediate(this) ? JSImmediate::getUInt32(this, v) : asCell()->getUInt32(v);
    343343}
    344344
     
    387387{
    388388    int32_t i;
    389     if (JSImmediate::isImmediate(this) && JSImmediate::toInt32(this, i))
     389    if (JSImmediate::isImmediate(this) && JSImmediate::getInt32(this, i))
    390390        return i;
    391391    bool ok;
     
    396396{
    397397    uint32_t i;
    398     if (JSImmediate::isImmediate(this) && JSImmediate::toUInt32(this, i))
     398    if (JSImmediate::isImmediate(this) && JSImmediate::getUInt32(this, i))
    399399        return i;
    400400    bool ok;
     
    405405{
    406406    int32_t i;
    407     if (JSImmediate::isImmediate(this) && JSImmediate::toInt32(this, i)) {
     407    if (JSImmediate::isImmediate(this) && JSImmediate::getInt32(this, i)) {
    408408        ok = true;
    409409        return i;
     
    415415{
    416416    uint32_t i;
    417     if (JSImmediate::isImmediate(this) && JSImmediate::toUInt32(this, i)) {
     417    if (JSImmediate::isImmediate(this) && JSImmediate::getUInt32(this, i)) {
    418418        ok = true;
    419419        return i;
Note: See TracChangeset for help on using the changeset viewer.