Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_CONVERSIONS_INL_H_ | 5 #ifndef V8_CONVERSIONS_INL_H_ |
| 6 #define V8_CONVERSIONS_INL_H_ | 6 #define V8_CONVERSIONS_INL_H_ |
| 7 | 7 |
| 8 #include <float.h> // Required for DBL_MAX and on Win32 for finite() | 8 #include <float.h> // Required for DBL_MAX and on Win32 for finite() |
| 9 #include <limits.h> // Required for INT_MAX etc. | 9 #include <limits.h> // Required for INT_MAX etc. |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 DCHECK(static_cast<unsigned>(Smi::kMaxValue) <= | 147 DCHECK(static_cast<unsigned>(Smi::kMaxValue) <= |
| 148 std::numeric_limits<size_t>::max()); | 148 std::numeric_limits<size_t>::max()); |
| 149 if (value >= 0) { | 149 if (value >= 0) { |
| 150 *result = static_cast<size_t>(value); | 150 *result = static_cast<size_t>(value); |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 return false; | 153 return false; |
| 154 } else { | 154 } else { |
| 155 DCHECK(number->IsHeapNumber()); | 155 DCHECK(number->IsHeapNumber()); |
| 156 double value = HeapNumber::cast(number)->value(); | 156 double value = HeapNumber::cast(number)->value(); |
| 157 if (value >= 0 && value <= std::numeric_limits<size_t>::max()) { | 157 if (value >= 0 && value <= std::numeric_limits<size_t>::max()) { |
|
ahaas
2016/12/07 16:20:38
The problem here is that if you compare a double w
qiuyi.zqy
2016/12/07 18:13:36
Done.
| |
| 158 *result = static_cast<size_t>(value); | 158 *result = static_cast<size_t>(value); |
| 159 // Cast error. Could happen when value is slightly larger than | |
| 160 // the limit of size_t but has a floating number precision loss. | |
| 161 if (value > 0 && *result == 0) { | |
| 162 return false; | |
| 163 } | |
| 159 return true; | 164 return true; |
| 160 } else { | 165 } else { |
| 161 return false; | 166 return false; |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 166 size_t NumberToSize(Object* number) { | 171 size_t NumberToSize(Object* number) { |
| 167 size_t result = 0; | 172 size_t result = 0; |
| 168 bool is_valid = TryNumberToSize(number, &result); | 173 bool is_valid = TryNumberToSize(number, &result); |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 buffer[buffer_pos] = '\0'; | 770 buffer[buffer_pos] = '\0'; |
| 766 | 771 |
| 767 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 772 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
| 768 return (sign == NEGATIVE) ? -converted : converted; | 773 return (sign == NEGATIVE) ? -converted : converted; |
| 769 } | 774 } |
| 770 | 775 |
| 771 } // namespace internal | 776 } // namespace internal |
| 772 } // namespace v8 | 777 } // namespace v8 |
| 773 | 778 |
| 774 #endif // V8_CONVERSIONS_INL_H_ | 779 #endif // V8_CONVERSIONS_INL_H_ |
| OLD | NEW |