Changeset 101151 in webkit for trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
- Timestamp:
- Nov 24, 2011, 10:47:48 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r99812 r101151 278 278 static const int SizeOfInfinity = 8; 279 279 280 static bool isInfinity(const UChar* data, const UChar* end) 280 template <typename CharType> 281 static bool isInfinity(const CharType* data, const CharType* end) 281 282 { 282 283 return (end - data) >= SizeOfInfinity … … 292 293 293 294 // See ecma-262 9.3.1 294 static double jsHexIntegerLiteral(const UChar*& data, const UChar* end) 295 template <typename CharType> 296 static double jsHexIntegerLiteral(const CharType*& data, const CharType* end) 295 297 { 296 298 // Hex number. 297 299 data += 2; 298 const UChar* firstDigitPosition = data;300 const CharType* firstDigitPosition = data; 299 301 double number = 0; 300 302 while (true) { … … 313 315 314 316 // See ecma-262 9.3.1 315 static double jsStrDecimalLiteral(const UChar*& data, const UChar* end) 317 template <typename CharType> 318 static double jsStrDecimalLiteral(const CharType*& data, const CharType* end) 316 319 { 317 320 ASSERT(data < end); … … 319 322 // Copy the sting into a null-terminated byte buffer, and call strtod. 320 323 Vector<char, 32> byteBuffer; 321 for (const UChar* characters = data; characters < end; ++characters) {322 UCharcharacter = *characters;323 byteBuffer.append(isASCII(character) ? character: 0);324 for (const CharType* characters = data; characters < end; ++characters) { 325 CharType character = *characters; 326 byteBuffer.append(isASCII(character) ? static_cast<char>(character) : 0); 324 327 } 325 328 byteBuffer.append(0); … … 360 363 // Not a number. 361 364 return std::numeric_limits<double>::quiet_NaN(); 365 } 366 367 template <typename CharType> 368 static double toDouble(const CharType* characters, unsigned size) 369 { 370 const CharType* endCharacters = characters + size; 371 372 // Skip leading white space. 373 for (; characters < endCharacters; ++characters) { 374 if (!isStrWhiteSpace(*characters)) 375 break; 376 } 377 378 // Empty string. 379 if (characters == endCharacters) 380 return 0.0; 381 382 double number; 383 if (characters[0] == '0' && characters + 2 < endCharacters && (characters[1] | 0x20) == 'x' && isASCIIHexDigit(characters[2])) 384 number = jsHexIntegerLiteral(characters, endCharacters); 385 else 386 number = jsStrDecimalLiteral(characters, endCharacters); 387 388 // Allow trailing white space. 389 for (; characters < endCharacters; ++characters) { 390 if (!isStrWhiteSpace(*characters)) 391 break; 392 } 393 if (characters != endCharacters) 394 return std::numeric_limits<double>::quiet_NaN(); 395 396 return number; 362 397 } 363 398 … … 376 411 } 377 412 378 const UChar* data = s.characters(); 379 const UChar* end = data + size; 380 381 // Skip leading white space. 382 for (; data < end; ++data) { 383 if (!isStrWhiteSpace(*data)) 384 break; 385 } 386 387 // Empty string. 388 if (data == end) 389 return 0.0; 390 391 double number; 392 if (data[0] == '0' && data + 2 < end && (data[1] | 0x20) == 'x' && isASCIIHexDigit(data[2])) 393 number = jsHexIntegerLiteral(data, end); 394 else 395 number = jsStrDecimalLiteral(data, end); 396 397 // Allow trailing white space. 398 for (; data < end; ++data) { 399 if (!isStrWhiteSpace(*data)) 400 break; 401 } 402 if (data != end) 403 return std::numeric_limits<double>::quiet_NaN(); 404 405 return number; 413 if (s.is8Bit()) 414 return toDouble(s.characters8(), size); 415 return toDouble(s.characters16(), size); 406 416 } 407 417
Note:
See TracChangeset
for help on using the changeset viewer.