Reviewed by Geoff.
- fix http://bugs.webkit.org/show_bug.cgi?id=15632
js1_5/Array/array-001.js test failing
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.
- tests for http://bugs.webkit.org/show_bug.cgi?id=15632
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.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@26899
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-10-22 Darin Adler <darin@apple.com>
+
+ Reviewed by Geoff.
+
+ - fix http://bugs.webkit.org/show_bug.cgi?id=15632
+ js1_5/Array/array-001.js test failing
+
+ 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.
+
2007-10-22 Darin Adler <darin@apple.com>
Reviewed by Brady.
static UString toString(const JSValue*);
static JSType type(const JSValue*);
- static bool toInt32(const JSValue*, int32_t&);
- static bool toUInt32(const JSValue*, uint32_t&);
+ static bool getInt32(const JSValue*, int32_t&);
+ static bool getUInt32(const JSValue*, uint32_t&);
// It would nice just to use fromDouble() to create these values, but that would prevent them from
// turning into compile-time constants.
return floatUnion.asFloat;
}
- static bool toInt32(const JSValue* v, int32_t& i)
+ static bool getInt32(const JSValue* v, int32_t& i)
{
ASSERT(isImmediate(v));
FloatUnion floatUnion;
floatUnion.asBits = static_cast<uint32_t>(unTag(v));
float f = floatUnion.asFloat;
- if (!(f >= -2147483648.0F && f < 2147483648.0F))
- return false;
i = static_cast<int32_t>(f);
- return isNumber(v);
+ return isNumber(v) && i == f;
}
- static bool toUInt32(const JSValue* v, uint32_t& i)
+ static bool getUInt32(const JSValue* v, uint32_t& i)
{
ASSERT(isImmediate(v));
FloatUnion floatUnion;
floatUnion.asBits = static_cast<uint32_t>(unTag(v));
float f = floatUnion.asFloat;
- if (!(f >= 0.0F && f < 4294967296.0F))
- return false;
i = static_cast<uint32_t>(f);
- return isNumber(v);
+ return isNumber(v) && i == f;
}
};
return doubleUnion.asDouble;
}
- static bool toInt32(const JSValue* v, int32_t& i)
+ static bool getInt32(const JSValue* v, int32_t& i)
{
double d = toDouble(v);
- if (!(d >= -2147483648.0 && d < 2147483648.0))
- return false;
i = static_cast<int32_t>(d);
- return isNumber(v);
+ return isNumber(v) && i == d;
}
- static bool toUInt32(const JSValue* v, uint32_t& i)
+ static bool getUInt32(const JSValue* v, uint32_t& i)
{
double d = toDouble(v);
- if (!(d >= 0.0 && d < 4294967296.0))
- return false;
i = static_cast<uint32_t>(d);
- return isNumber(v);
+ return isNumber(v) && i == d;
}
};
return FPBitValues<is32bit, is64bit>::toDouble(v);
}
-inline bool JSImmediate::toInt32(const JSValue* v, int32_t& i)
+inline bool JSImmediate::getInt32(const JSValue* v, int32_t& i)
{
- return FPBitValues<is32bit, is64bit>::toInt32(v, i);
+ return FPBitValues<is32bit, is64bit>::getInt32(v, i);
}
-inline bool JSImmediate::toUInt32(const JSValue* v, uint32_t& i)
+inline bool JSImmediate::getUInt32(const JSValue* v, uint32_t& i)
{
- return FPBitValues<is32bit, is64bit>::toUInt32(v, i);
+ return FPBitValues<is32bit, is64bit>::getUInt32(v, i);
}
} // namespace KJS
bool NumberImp::getInt32(int32_t& int32) const
{
- if (!(val >= -2147483648.0 && val < 2147483648.0))
- return false;
int32 = static_cast<int32_t>(val);
- return true;
+ return int32 == val;
}
bool NumberImp::getUInt32(uint32_t& uint32) const
{
- if (!(val >= 0.0 && val < 4294967296.0))
- return false;
uint32 = static_cast<uint32_t>(val);
- return true;
+ return uint32 == val;
}
// --------------------------- GetterSetterImp ---------------------------------
inline bool JSValue::getInt32(int32_t& v) const
{
- return JSImmediate::isImmediate(this) ? JSImmediate::toInt32(this, v) : asCell()->getInt32(v);
+ return JSImmediate::isImmediate(this) ? JSImmediate::getInt32(this, v) : asCell()->getInt32(v);
}
inline bool JSValue::getUInt32(uint32_t& v) const
{
- return JSImmediate::isImmediate(this) ? JSImmediate::toUInt32(this, v) : asCell()->getUInt32(v);
+ return JSImmediate::isImmediate(this) ? JSImmediate::getUInt32(this, v) : asCell()->getUInt32(v);
}
inline void JSValue::mark()
ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const
{
int32_t i;
- if (JSImmediate::isImmediate(this) && JSImmediate::toInt32(this, i))
+ if (JSImmediate::isImmediate(this) && JSImmediate::getInt32(this, i))
return i;
bool ok;
return toInt32SlowCase(exec, ok);
inline uint32_t JSValue::toUInt32(ExecState* exec) const
{
uint32_t i;
- if (JSImmediate::isImmediate(this) && JSImmediate::toUInt32(this, i))
+ if (JSImmediate::isImmediate(this) && JSImmediate::getUInt32(this, i))
return i;
bool ok;
return toUInt32SlowCase(exec, ok);
inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
{
int32_t i;
- if (JSImmediate::isImmediate(this) && JSImmediate::toInt32(this, i)) {
+ if (JSImmediate::isImmediate(this) && JSImmediate::getInt32(this, i)) {
ok = true;
return i;
}
inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
{
uint32_t i;
- if (JSImmediate::isImmediate(this) && JSImmediate::toUInt32(this, i)) {
+ if (JSImmediate::isImmediate(this) && JSImmediate::getUInt32(this, i)) {
ok = true;
return i;
}
+2007-10-22 Darin Adler <darin@apple.com>
+
+ Reviewed by Geoff.
+
+ - tests for http://bugs.webkit.org/show_bug.cgi?id=15632
+
+ 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.
+
2007-10-22 Darin Adler <darin@apple.com>
* fast/js/kde/resources/Array.js: Added tests to cover missing value behavior
PASS arr[maxint] is undefined
PASS arr.length is maxint
PASS arr[maxint-1] is "test2"
+PASS arr.length is 40
+PASS arr[55.5] is "test"
+PASS arr[65.11111111111111111111111111111] is "test"
+PASS arr.length is 40
+PASS arr[55.5] is undefined
+PASS arr[65.11111111111111111111111111111] is undefined
PASS propnames.length is 3
PASS propnames[0] is '0'
PASS propnames[1] is '1'
shouldBe("arr.length","maxint");
shouldBe("arr[maxint-1]","\"test2\"");
+// Floating point numbers also should not be treated as valid array indices.
+arr.length = 40;
+arr[55.5] = "test"; // does fit in a JSImmediate number
+arr[65.11111111111111111111111111111] = "test"; // does not fit in a JSImmediate number
+shouldBe("arr.length","40");
+shouldBe("arr[55.5]","\"test\"");
+shouldBe("arr[65.11111111111111111111111111111]","\"test\"");
+delete arr[55.5];
+delete arr[65.11111111111111111111111111111];
+shouldBe("arr.length","40");
+shouldBe("arr[55.5]","undefined");
+shouldBe("arr[65.11111111111111111111111111111]","undefined");
+
arr = new Array('a','b','c');
arr.__proto__ = { 1: 'x' };
var propnames = new Array();