OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 String* string, | 68 String* string, |
69 int flags, | 69 int flags, |
70 double empty_string_val = 0.0); | 70 double empty_string_val = 0.0); |
71 | 71 |
72 | 72 |
73 inline bool TryNumberToSize(Isolate* isolate, | 73 inline bool TryNumberToSize(Isolate* isolate, |
74 Object* number, size_t* result) { | 74 Object* number, size_t* result) { |
75 SealHandleScope shs(isolate); | 75 SealHandleScope shs(isolate); |
76 if (number->IsSmi()) { | 76 if (number->IsSmi()) { |
77 int value = Smi::cast(number)->value(); | 77 int value = Smi::cast(number)->value(); |
78 ASSERT( | 78 ASSERT(static_cast<unsigned>(Smi::kMaxValue) |
79 static_cast<unsigned>(Smi::kMaxValue) | 79 <= std::numeric_limits<size_t>::max()); |
80 <= std::numeric_limits<size_t>::max()); | |
81 if (value >= 0) { | 80 if (value >= 0) { |
82 *result = static_cast<size_t>(value); | 81 *result = static_cast<size_t>(value); |
83 return true; | 82 return true; |
84 } | 83 } |
85 return false; | 84 return false; |
86 } else { | 85 } else { |
87 ASSERT(number->IsHeapNumber()); | 86 ASSERT(number->IsHeapNumber()); |
88 double value = HeapNumber::cast(number)->value(); | 87 double value = HeapNumber::cast(number)->value(); |
89 if (value >= 0 && | 88 if (value >= 0 && |
90 value <= std::numeric_limits<size_t>::max()) { | 89 value <= std::numeric_limits<size_t>::max()) { |
(...skipping 10 matching lines...) Expand all Loading... |
101 Object* number) { | 100 Object* number) { |
102 size_t result = 0; | 101 size_t result = 0; |
103 bool is_valid = TryNumberToSize(isolate, number, &result); | 102 bool is_valid = TryNumberToSize(isolate, number, &result); |
104 CHECK(is_valid); | 103 CHECK(is_valid); |
105 return result; | 104 return result; |
106 } | 105 } |
107 | 106 |
108 } } // namespace v8::internal | 107 } } // namespace v8::internal |
109 | 108 |
110 #endif // V8_V8CONVERSIONS_H_ | 109 #endif // V8_V8CONVERSIONS_H_ |
OLD | NEW |