OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 // Slightly adapted for inclusion in V8. | 5 // Slightly adapted for inclusion in V8. |
6 // Copyright 2014 the V8 project authors. All rights reserved. | 6 // Copyright 2014 the V8 project authors. All rights reserved. |
7 | 7 |
8 #ifndef V8_BASE_SAFE_CONVERSIONS_IMPL_H_ | 8 #ifndef V8_BASE_SAFE_CONVERSIONS_IMPL_H_ |
9 #define V8_BASE_SAFE_CONVERSIONS_IMPL_H_ | 9 #define V8_BASE_SAFE_CONVERSIONS_IMPL_H_ |
10 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 enum RangeConstraint { | 93 enum RangeConstraint { |
94 RANGE_VALID = 0x0, // Value can be represented by the destination type. | 94 RANGE_VALID = 0x0, // Value can be represented by the destination type. |
95 RANGE_UNDERFLOW = 0x1, // Value would overflow. | 95 RANGE_UNDERFLOW = 0x1, // Value would overflow. |
96 RANGE_OVERFLOW = 0x2, // Value would underflow. | 96 RANGE_OVERFLOW = 0x2, // Value would underflow. |
97 RANGE_INVALID = RANGE_UNDERFLOW | RANGE_OVERFLOW // Invalid (i.e. NaN). | 97 RANGE_INVALID = RANGE_UNDERFLOW | RANGE_OVERFLOW // Invalid (i.e. NaN). |
98 }; | 98 }; |
99 | 99 |
100 // Helper function for coercing an int back to a RangeContraint. | 100 // Helper function for coercing an int back to a RangeContraint. |
101 inline RangeConstraint GetRangeConstraint(int integer_range_constraint) { | 101 inline RangeConstraint GetRangeConstraint(int integer_range_constraint) { |
102 ASSERT(integer_range_constraint >= RANGE_VALID && | 102 DCHECK(integer_range_constraint >= RANGE_VALID && |
103 integer_range_constraint <= RANGE_INVALID); | 103 integer_range_constraint <= RANGE_INVALID); |
104 return static_cast<RangeConstraint>(integer_range_constraint); | 104 return static_cast<RangeConstraint>(integer_range_constraint); |
105 } | 105 } |
106 | 106 |
107 // This function creates a RangeConstraint from an upper and lower bound | 107 // This function creates a RangeConstraint from an upper and lower bound |
108 // check by taking advantage of the fact that only NaN can be out of range in | 108 // check by taking advantage of the fact that only NaN can be out of range in |
109 // both directions at once. | 109 // both directions at once. |
110 inline RangeConstraint GetRangeConstraint(bool is_in_upper_bound, | 110 inline RangeConstraint GetRangeConstraint(bool is_in_upper_bound, |
111 bool is_in_lower_bound) { | 111 bool is_in_lower_bound) { |
112 return GetRangeConstraint((is_in_upper_bound ? 0 : RANGE_OVERFLOW) | | 112 return GetRangeConstraint((is_in_upper_bound ? 0 : RANGE_OVERFLOW) | |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 STATIC_ASSERT(std::numeric_limits<Src>::is_specialized); | 211 STATIC_ASSERT(std::numeric_limits<Src>::is_specialized); |
212 STATIC_ASSERT(std::numeric_limits<Dst>::is_specialized); | 212 STATIC_ASSERT(std::numeric_limits<Dst>::is_specialized); |
213 return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value); | 213 return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value); |
214 } | 214 } |
215 | 215 |
216 } // namespace internal | 216 } // namespace internal |
217 } // namespace base | 217 } // namespace base |
218 } // namespace v8 | 218 } // namespace v8 |
219 | 219 |
220 #endif // V8_BASE_SAFE_CONVERSIONS_IMPL_H_ | 220 #endif // V8_BASE_SAFE_CONVERSIONS_IMPL_H_ |
OLD | NEW |