Changeset 103922 in webkit for trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
- Timestamp:
- Jan 2, 2012, 8:32:00 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r102182 r103922 231 231 } 232 232 233 // ES5.1 15.1.2.2 233 234 template <typename CharType> 234 235 ALWAYS_INLINE 235 236 static double parseInt(const UString& s, const CharType* data, int radix) 236 237 { 238 // 1. Let inputString be ToString(string). 239 // 2. Let S be a newly created substring of inputString consisting of the first character that is not a 240 // StrWhiteSpaceChar and all characters following that character. (In other words, remove leading white 241 // space.) If inputString does not contain any such characters, let S be the empty string. 237 242 int length = s.length(); 238 243 int p = 0; 239 240 244 while (p < length && isStrWhiteSpace(data[p])) 241 245 ++p; 242 246 247 // 3. Let sign be 1. 248 // 4. If S is not empty and the first character of S is a minus sign -, let sign be -1. 249 // 5. If S is not empty and the first character of S is a plus sign + or a minus sign -, then remove the first character from S. 243 250 double sign = 1; 244 251 if (p < length) { … … 251 258 } 252 259 260 // 6. Let R = ToInt32(radix). 261 // 7. Let stripPrefix be true. 262 // 8. If R != 0,then 263 // b. If R != 16, let stripPrefix be false. 264 // 9. Else, R == 0 265 // a. LetR = 10. 266 // 10. If stripPrefix is true, then 267 // a. If the length of S is at least 2 and the first two characters of S are either ―0x or ―0X, 268 // then remove the first two characters from S and let R = 16. 269 // 11. If S contains any character that is not a radix-R digit, then let Z be the substring of S 270 // consisting of all characters before the first such character; otherwise, let Z be S. 253 271 if ((radix == 0 || radix == 16) && length - p >= 2 && data[p] == '0' && (data[p + 1] == 'x' || data[p + 1] == 'X')) { 254 272 radix = 16; 255 273 p += 2; 256 } else if (radix == 0) { 257 if (p < length && data[p] == '0') 258 radix = 8; 259 else 260 radix = 10; 261 } 262 274 } else if (radix == 0) 275 radix = 10; 276 277 // 8.a If R < 2 or R > 36, then return NaN. 263 278 if (radix < 2 || radix > 36) 264 279 return std::numeric_limits<double>::quiet_NaN(); 265 280 281 // 13. Let mathInt be the mathematical integer value that is represented by Z in radix-R notation, using the letters 282 // A-Z and a-z for digits with values 10 through 35. (However, if R is 10 and Z contains more than 20 significant 283 // digits, every significant digit after the 20th may be replaced by a 0 digit, at the option of the implementation; 284 // and if R is not 2, 4, 8, 10, 16, or 32, then mathInt may be an implementation-dependent approximation to the 285 // mathematical integer value that is represented by Z in radix-R notation.) 286 // 14. Let number be the Number value for mathInt. 266 287 int firstDigitPosition = p; 267 288 bool sawDigit = false; … … 276 297 ++p; 277 298 } 278 279 299 if (number >= mantissaOverflowLowerBound) { 280 300 if (radix == 10) … … 284 304 } 285 305 306 // 12. If Z is empty, return NaN. 286 307 if (!sawDigit) 287 308 return std::numeric_limits<double>::quiet_NaN(); 288 309 310 // 15. Return sign x number. 289 311 return sign * number; 290 312 }
Note:
See TracChangeset
for help on using the changeset viewer.