Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 // String::toDouble() accepts leading + and whitespace characters, which are not valid here. | 100 // String::toDouble() accepts leading + and whitespace characters, which are not valid here. |
| 101 const UChar firstCharacter = string[0]; | 101 const UChar firstCharacter = string[0]; |
| 102 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha racter)) | 102 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha racter)) |
| 103 return fallbackValue; | 103 return fallbackValue; |
| 104 | 104 |
| 105 const Decimal value = Decimal::fromString(string); | 105 const Decimal value = Decimal::fromString(string); |
| 106 if (!value.isFinite()) | 106 if (!value.isFinite()) |
| 107 return fallbackValue; | 107 return fallbackValue; |
| 108 | 108 |
| 109 // Numbers are considered finite IEEE 754 single-precision floating point va lues. | 109 // Numbers are considered finite IEEE 754 single-precision floating point va lues. |
| 110 // See HTML5 2.5.4.3 `Real numbers.' | 110 // See HTML5 2.5.4.3 `Real numbers.' |
|
yosin_UTC9
2014/02/25 02:20:31
Please update this comment. Now we refer "2.4.4.3
Habib Virji
2014/02/25 10:09:27
Done.
| |
| 111 // FIXME: We should use numeric_limits<double>::max for number input type. | 111 const Decimal doubleMax = Decimal::fromDouble(std::numeric_limits<double>::m ax()); |
| 112 const Decimal floatMax = Decimal::fromDouble(std::numeric_limits<float>::max ()); | 112 if (value < -doubleMax || value > doubleMax) |
| 113 if (value < -floatMax || value > floatMax) | |
| 114 return fallbackValue; | 113 return fallbackValue; |
| 115 | 114 |
| 116 // We return +0 for -0 case. | 115 // We return +0 for -0 case. |
| 117 return value.isZero() ? Decimal(0) : value; | 116 return value.isZero() ? Decimal(0) : value; |
| 118 } | 117 } |
| 119 | 118 |
| 120 double parseToDoubleForNumberType(const String& string, double fallbackValue) | 119 double parseToDoubleForNumberType(const String& string, double fallbackValue) |
| 121 { | 120 { |
| 122 // See HTML5 2.5.4.3 `Real numbers.' | 121 // See HTML5 2.5.4.3 `Real numbers.' |
| 123 | 122 |
| 124 // String::toDouble() accepts leading + and whitespace characters, which are not valid here. | 123 // String::toDouble() accepts leading + and whitespace characters, which are not valid here. |
| 125 UChar firstCharacter = string[0]; | 124 UChar firstCharacter = string[0]; |
| 126 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha racter)) | 125 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha racter)) |
| 127 return fallbackValue; | 126 return fallbackValue; |
| 128 | 127 |
| 129 bool valid = false; | 128 bool valid = false; |
| 130 double value = string.toDouble(&valid); | 129 double value = string.toDouble(&valid); |
| 131 if (!valid) | 130 if (!valid) |
| 132 return fallbackValue; | 131 return fallbackValue; |
| 133 | 132 |
| 134 // NaN and infinity are considered valid by String::toDouble, but not valid here. | 133 // NaN and infinity are considered valid by String::toDouble, but not valid here. |
| 135 if (!std::isfinite(value)) | 134 if (!std::isfinite(value)) |
| 136 return fallbackValue; | 135 return fallbackValue; |
| 137 | 136 |
| 138 // Numbers are considered finite IEEE 754 single-precision floating point va lues. | 137 // Numbers are considered finite IEEE 754 single-precision floating point va lues. |
| 139 // See HTML5 2.5.4.3 `Real numbers.' | 138 // See HTML5 2.5.4.3 `Real numbers.' |
| 140 if (-std::numeric_limits<float>::max() > value || value > std::numeric_limit s<float>::max()) | 139 if (-std::numeric_limits<double>::max() > value || value > std::numeric_limi ts<double>::max()) |
| 141 return fallbackValue; | 140 return fallbackValue; |
| 142 | 141 |
| 143 // The following expression converts -0 to +0. | 142 // The following expression converts -0 to +0. |
| 144 return value ? value : 0; | 143 return value ? value : 0; |
| 145 } | 144 } |
| 146 | 145 |
| 147 template <typename CharacterType> | 146 template <typename CharacterType> |
| 148 static bool parseHTMLIntegerInternal(const CharacterType* position, const Charac terType* end, int& value) | 147 static bool parseHTMLIntegerInternal(const CharacterType* position, const Charac terType* end, int& value) |
| 149 { | 148 { |
| 150 // Step 3 | 149 // Step 3 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 // It's possible to have hash collisions between arbitrary strings and | 389 // It's possible to have hash collisions between arbitrary strings and |
| 391 // known identifiers (e.g. "bvvfg" collides with "script"). | 390 // known identifiers (e.g. "bvvfg" collides with "script"). |
| 392 // However ASSERTs in StringImpl::createStatic guard against there ever bein g collisions | 391 // However ASSERTs in StringImpl::createStatic guard against there ever bein g collisions |
| 393 // between static strings. | 392 // between static strings. |
| 394 if (!equal(it->value, characters, length)) | 393 if (!equal(it->value, characters, length)) |
| 395 return 0; | 394 return 0; |
| 396 return it->value; | 395 return it->value; |
| 397 } | 396 } |
| 398 | 397 |
| 399 } | 398 } |
| OLD | NEW |