Changeset 26912 in webkit for trunk/JavaScriptCore
- Timestamp:
- Oct 22, 2007, 11:44:27 PM (18 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r26899 r26912 1 2007-10-22 Darin Adler <[email protected]> 2 3 Reviewed by Maciej. 4 5 - fix http://bugs.webkit.org/show_bug.cgi?id=15636 6 some JavaScriptCore regression tests are failing due to numeric conversion 7 8 This should restore correctness and make speed better too, restoring some 9 of the optimization we lost in my last check-in. 10 11 * kjs/JSImmediate.h: 12 (KJS::JSImmediate::getTruncatedInt32): Added. Uses the range checking idiom 13 I used in my patch yesterday. 14 (KJS::JSImmediate::getTruncatedUInt32): Ditto. 15 16 * kjs/internal.h: Removed getInt32 and added getTruncatedInt/UInt32. 17 * kjs/internal.cpp: 18 (KJS::NumberImp::getUInt32): Changed to always use double, since I can't find 19 a way to write this more efficiently for float. 20 (KJS::NumberImp::getTruncatedInt32): Added. 21 (KJS::NumberImp::getTruncatedUInt32): Added. 22 23 * kjs/value.h: Removed getInt32 and added getTruncatedInt/UInt32. 24 (KJS::JSValue::getUInt32): 25 (KJS::JSValue::getTruncatedInt32): Added. 26 (KJS::JSValue::getTruncatedUInt32): Added. 27 (KJS::JSValue::toInt32): Changed getInt32 call to getTruncatedInt32. 28 (KJS::JSValue::toUInt32): Changed getUInt32 call to getTruncatedUInt32. 29 * kjs/value.cpp: 30 (KJS::JSCell::getTruncatedInt32): Added. 31 (KJS::JSCell::getTruncatedUInt32): Added. 32 (KJS::JSValue::toInteger): Changed getUInt32 call to getTruncatedInt32. 33 (KJS::JSValue::toInt32SlowCase): Removed extra getInt32 call I accidentally 34 had left in here. 35 (KJS::JSValue::toUInt32SlowCase): Ditto. 36 (KJS::JSValue::toUInt16): Changed getUInt32 call to getTruncatedUInt32. 37 38 * JavaScriptCore.exp: Updated. 39 1 40 2007-10-22 Darin Adler <[email protected]> 2 41 -
trunk/JavaScriptCore/JavaScriptCore.exp
r26892 r26912 243 243 __ZNK3KJS4List2atEi 244 244 __ZNK3KJS4List8copyTailEv 245 __ZNK3KJS6JSCell8getInt32ERi 245 __ZNK3KJS6JSCell17getTruncatedInt32ERi 246 __ZNK3KJS6JSCell18getTruncatedUInt32ERj 246 247 __ZNK3KJS6JSCell9getNumberERd 247 248 __ZNK3KJS6JSCell9getNumberEv -
trunk/JavaScriptCore/kjs/JSImmediate.h
r26899 r26912 88 88 static JSType type(const JSValue*); 89 89 90 static bool getInt32(const JSValue*, int32_t&);91 90 static bool getUInt32(const JSValue*, uint32_t&); 91 static bool getTruncatedInt32(const JSValue*, int32_t&); 92 static bool getTruncatedUInt32(const JSValue*, uint32_t&); 92 93 93 94 // It would nice just to use fromDouble() to create these values, but that would prevent them from … … 163 164 } 164 165 165 static double toDouble(const JSValue* v)166 static float toFloat(const JSValue* v) 166 167 { 167 168 ASSERT(isImmediate(v)); … … 172 173 } 173 174 174 static bool getInt32(const JSValue* v, int32_t& i) 175 { 176 ASSERT(isImmediate(v)); 177 178 FloatUnion floatUnion; 179 floatUnion.asBits = static_cast<uint32_t>(unTag(v)); 180 float f = floatUnion.asFloat; 175 static double toDouble(const JSValue* v) 176 { 177 return toFloat(v); 178 } 179 180 static bool getTruncatedInt32(const JSValue* v, int32_t& i) 181 { 182 float f = toFloat(v); 183 if (!(f >= -2147483648.0F && f < 2147483648.0F)) 184 return false; 181 185 i = static_cast<int32_t>(f); 182 return isNumber(v) && i == f; 183 } 184 185 static bool getUInt32(const JSValue* v, uint32_t& i) 186 { 187 ASSERT(isImmediate(v)); 188 189 FloatUnion floatUnion; 190 floatUnion.asBits = static_cast<uint32_t>(unTag(v)); 191 float f = floatUnion.asFloat; 186 return isNumber(v); 187 } 188 189 static bool getTruncatedUInt32(const JSValue* v, uint32_t& i) 190 { 191 float f = toFloat(v); 192 if (!(f >= 0.0F && f < 4294967296.0F)) 193 return false; 192 194 i = static_cast<uint32_t>(f); 193 return isNumber(v) && i == f;195 return isNumber(v); 194 196 } 195 197 }; … … 221 223 } 222 224 223 static bool get Int32(const JSValue* v, int32_t& i)225 static bool getTruncatedInt32(const JSValue* v, int32_t& i) 224 226 { 225 227 double d = toDouble(v); 228 if (!(d >= -2147483648.0 && d < 2147483648.0)) 229 return false; 226 230 i = static_cast<int32_t>(d); 227 return isNumber(v) && i == d;228 } 229 230 static bool get UInt32(const JSValue* v, uint32_t& i)231 return isNumber(v); 232 } 233 234 static bool getTruncatedUInt32(const JSValue* v, uint32_t& i) 231 235 { 232 236 double d = toDouble(v); 237 if (!(d >= 0.0 && d < 4294967296.0)) 238 return false; 233 239 i = static_cast<uint32_t>(d); 234 return isNumber(v) && i == d;240 return isNumber(v); 235 241 } 236 242 }; … … 263 269 } 264 270 265 inline bool JSImmediate::getInt32(const JSValue* v, int32_t& i)266 {267 return FPBitValues<is32bit, is64bit>::getInt32(v, i);268 }269 270 271 inline bool JSImmediate::getUInt32(const JSValue* v, uint32_t& i) 271 272 { 272 return FPBitValues<is32bit, is64bit>::getUInt32(v, i); 273 double d = toDouble(v); 274 i = static_cast<uint32_t>(d); 275 return isNumber(v) && i == d; 276 } 277 278 inline bool JSImmediate::getTruncatedInt32(const JSValue* v, int32_t& i) 279 { 280 return FPBitValues<is32bit, is64bit>::getTruncatedInt32(v, i); 281 } 282 283 inline bool JSImmediate::getTruncatedUInt32(const JSValue* v, uint32_t& i) 284 { 285 return FPBitValues<is32bit, is64bit>::getTruncatedUInt32(v, i); 273 286 } 274 287 -
trunk/JavaScriptCore/kjs/internal.cpp
r26899 r26912 112 112 } 113 113 114 bool NumberImp::getInt32(int32_t& int32) const115 {116 int32 = static_cast<int32_t>(val);117 return int32 == val;118 }119 120 114 bool NumberImp::getUInt32(uint32_t& uint32) const 121 115 { 122 116 uint32 = static_cast<uint32_t>(val); 123 117 return uint32 == val; 118 } 119 120 bool NumberImp::getTruncatedInt32(int32_t& int32) const 121 { 122 if (!(val >= -2147483648.0 && val < 2147483648.0)) 123 return false; 124 int32 = static_cast<int32_t>(val); 125 return true; 126 } 127 128 bool NumberImp::getTruncatedUInt32(uint32_t& uint32) const 129 { 130 if (!(val >= 0.0 && val < 4294967296.0)) 131 return false; 132 uint32 = static_cast<uint32_t>(val); 133 return true; 124 134 } 125 135 -
trunk/JavaScriptCore/kjs/internal.h
r26892 r26912 81 81 NumberImp(double v) : val(v) { } 82 82 83 virtual bool getInt32(int32_t&) const;84 83 virtual bool getUInt32(uint32_t&) const; 84 virtual bool getTruncatedInt32(int32_t&) const; 85 virtual bool getTruncatedUInt32(uint32_t&) const; 85 86 86 87 double val; -
trunk/JavaScriptCore/kjs/value.cpp
r26892 r26912 41 41 } 42 42 43 bool JSCell::get Int32(int32_t&) const43 bool JSCell::getUInt32(uint32_t&) const 44 44 { 45 45 return false; 46 46 } 47 47 48 bool JSCell::getUInt32(uint32_t&) const 48 bool JSCell::getTruncatedInt32(int32_t&) const 49 { 50 return false; 51 } 52 53 bool JSCell::getTruncatedUInt32(uint32_t&) const 49 54 { 50 55 return false; … … 54 59 double JSValue::toInteger(ExecState *exec) const 55 60 { 56 uint32_t i;57 if (get UInt32(i))61 int32_t i; 62 if (getTruncatedInt32(i)) 58 63 return i; 59 64 return roundValue(exec, const_cast<JSValue*>(this)); … … 63 68 { 64 69 ok = true; 65 66 int32_t i;67 if (getInt32(i))68 return i;69 70 70 71 double d = roundValue(exec, const_cast<JSValue*>(this)); … … 90 91 ok = true; 91 92 92 uint32_t i;93 if (getUInt32(i))94 return i;95 96 93 double d = roundValue(exec, const_cast<JSValue*>(this)); 97 94 if (d >= 0.0 && d < D32) … … 113 110 { 114 111 uint32_t i; 115 if (get UInt32(i))112 if (getTruncatedUInt32(i)) 116 113 return static_cast<uint16_t>(i); 117 114 -
trunk/JavaScriptCore/kjs/value.h
r26899 r26912 77 77 78 78 // Extracting integer values. 79 bool getInt32(int32_t&) const;80 79 bool getUInt32(uint32_t&) const; 80 bool getTruncatedInt32(int32_t&) const; 81 bool getTruncatedUInt32(uint32_t&) const; 81 82 82 83 // Basic conversions. … … 141 142 142 143 // Extracting integer values. 143 virtual bool getInt32(int32_t&) const;144 144 virtual bool getUInt32(uint32_t&) const; 145 virtual bool getTruncatedInt32(int32_t&) const; 146 virtual bool getTruncatedUInt32(uint32_t&) const; 145 147 146 148 // Basic conversions. … … 333 335 } 334 336 335 inline bool JSValue::getInt32(int32_t& v) const336 {337 return JSImmediate::isImmediate(this) ? JSImmediate::getInt32(this, v) : asCell()->getInt32(v);338 }339 340 337 inline bool JSValue::getUInt32(uint32_t& v) const 341 338 { 342 339 return JSImmediate::isImmediate(this) ? JSImmediate::getUInt32(this, v) : asCell()->getUInt32(v); 340 } 341 342 inline bool JSValue::getTruncatedInt32(int32_t& v) const 343 { 344 return JSImmediate::isImmediate(this) ? JSImmediate::getTruncatedInt32(this, v) : asCell()->getTruncatedInt32(v); 345 } 346 347 inline bool JSValue::getTruncatedUInt32(uint32_t& v) const 348 { 349 return JSImmediate::isImmediate(this) ? JSImmediate::getTruncatedUInt32(this, v) : asCell()->getTruncatedUInt32(v); 343 350 } 344 351 … … 387 394 { 388 395 int32_t i; 389 if (JSImmediate::isImmediate(this) && JSImmediate::get Int32(this, i))396 if (JSImmediate::isImmediate(this) && JSImmediate::getTruncatedInt32(this, i)) 390 397 return i; 391 398 bool ok; … … 396 403 { 397 404 uint32_t i; 398 if (JSImmediate::isImmediate(this) && JSImmediate::get UInt32(this, i))405 if (JSImmediate::isImmediate(this) && JSImmediate::getTruncatedUInt32(this, i)) 399 406 return i; 400 407 bool ok; … … 405 412 { 406 413 int32_t i; 407 if (JSImmediate::isImmediate(this) && JSImmediate::get Int32(this, i)) {414 if (JSImmediate::isImmediate(this) && JSImmediate::getTruncatedInt32(this, i)) { 408 415 ok = true; 409 416 return i; … … 415 422 { 416 423 uint32_t i; 417 if (JSImmediate::isImmediate(this) && JSImmediate::get UInt32(this, i)) {424 if (JSImmediate::isImmediate(this) && JSImmediate::getTruncatedUInt32(this, i)) { 418 425 ok = true; 419 426 return i;
Note:
See TracChangeset
for help on using the changeset viewer.