Changeset 26912 in webkit for trunk/JavaScriptCore/kjs/JSImmediate.h
- Timestamp:
- Oct 22, 2007, 11:44:27 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.