Changeset 26892 in webkit for trunk/JavaScriptCore/kjs/JSImmediate.h
- Timestamp:
- Oct 22, 2007, 11:39:46 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSImmediate.h
r26589 r26892 1 1 /* 2 * This file is part of the KDE libraries 3 * Copyright (C) 2003-2006 Apple Computer, Inc 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 4 3 * Copyright (C) 2006 Alexey Proskuryakov ([email protected]) 5 4 * … … 83 82 84 83 static JSValue* fromDouble(double d); 85 static double toDouble(const JSValue* v);86 static bool toBoolean(const JSValue* v);84 static double toDouble(const JSValue*); 85 static bool toBoolean(const JSValue*); 87 86 static JSObject* toObject(const JSValue*, ExecState*); 88 87 static UString toString(const JSValue*); 89 88 static JSType type(const JSValue*); 90 89 90 static bool toInt32(const JSValue*, int32_t&); 91 static bool toUInt32(const JSValue*, uint32_t&); 92 91 93 // It would nice just to use fromDouble() to create these values, but that would prevent them from 92 94 // turning into compile-time constants. … … 170 172 return floatUnion.asFloat; 171 173 } 174 175 static bool toInt32(const JSValue* v, int32_t& i) 176 { 177 ASSERT(isImmediate(v)); 178 179 FloatUnion floatUnion; 180 floatUnion.asBits = static_cast<uint32_t>(unTag(v)); 181 float f = floatUnion.asFloat; 182 if (!(f >= -2147483648.0F && f < 2147483648.0F)) 183 return false; 184 i = static_cast<int32_t>(f); 185 return isNumber(v); 186 } 187 188 static bool toUInt32(const JSValue* v, uint32_t& i) 189 { 190 ASSERT(isImmediate(v)); 191 192 FloatUnion floatUnion; 193 floatUnion.asBits = static_cast<uint32_t>(unTag(v)); 194 float f = floatUnion.asFloat; 195 if (!(f >= 0.0F && f < 4294967296.0F)) 196 return false; 197 i = static_cast<uint32_t>(f); 198 return isNumber(v); 199 } 172 200 }; 173 201 … … 196 224 doubleUnion.asBits = unTag(v); 197 225 return doubleUnion.asDouble; 226 } 227 228 static bool toInt32(const JSValue* v, int32_t& i) 229 { 230 double d = toDouble(v); 231 if (!(d >= -2147483648.0 && d < 2147483648.0)) 232 return false; 233 i = static_cast<int32_t>(d); 234 return isNumber(v); 235 } 236 237 static bool toUInt32(const JSValue* v, uint32_t& i) 238 { 239 double d = toDouble(v); 240 if (!(d >= 0.0 && d < 4294967296.0)) 241 return false; 242 i = static_cast<uint32_t>(d); 243 return isNumber(v); 198 244 } 199 245 }; … … 226 272 } 227 273 274 inline bool JSImmediate::toInt32(const JSValue* v, int32_t& i) 275 { 276 return FPBitValues<is32bit, is64bit>::toInt32(v, i); 277 } 278 279 inline bool JSImmediate::toUInt32(const JSValue* v, uint32_t& i) 280 { 281 return FPBitValues<is32bit, is64bit>::toUInt32(v, i); 282 } 283 228 284 } // namespace KJS 229 285
Note:
See TracChangeset
for help on using the changeset viewer.