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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return DoubleToInt32(number->Number()); | 57 return DoubleToInt32(number->Number()); |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 inline uint32_t NumberToUint32(Object* number) { | 61 inline uint32_t NumberToUint32(Object* number) { |
62 if (number->IsSmi()) return Smi::cast(number)->value(); | 62 if (number->IsSmi()) return Smi::cast(number)->value(); |
63 return DoubleToUint32(number->Number()); | 63 return DoubleToUint32(number->Number()); |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 // Converts a string into a double value according to ECMA-262 9.3.1 | |
68 double StringToDouble(UnicodeCache* unicode_cache, | 67 double StringToDouble(UnicodeCache* unicode_cache, |
69 String* str, | 68 String* string, |
70 int flags, | 69 int flags, |
71 double empty_string_val = 0); | 70 double empty_string_val = 0.0); |
72 | 71 |
73 // Converts a string into an integer. | |
74 double StringToInt(UnicodeCache* unicode_cache, String* str, int radix); | |
75 | 72 |
76 inline bool TryNumberToSize(Isolate* isolate, | 73 inline bool TryNumberToSize(Isolate* isolate, |
77 Object* number, size_t* result) { | 74 Object* number, size_t* result) { |
78 SealHandleScope shs(isolate); | 75 SealHandleScope shs(isolate); |
79 if (number->IsSmi()) { | 76 if (number->IsSmi()) { |
80 int value = Smi::cast(number)->value(); | 77 int value = Smi::cast(number)->value(); |
81 ASSERT( | 78 ASSERT( |
82 static_cast<unsigned>(Smi::kMaxValue) | 79 static_cast<unsigned>(Smi::kMaxValue) |
83 <= std::numeric_limits<size_t>::max()); | 80 <= std::numeric_limits<size_t>::max()); |
84 if (value >= 0) { | 81 if (value >= 0) { |
(...skipping 19 matching lines...) Expand all Loading... |
104 Object* number) { | 101 Object* number) { |
105 size_t result = 0; | 102 size_t result = 0; |
106 bool is_valid = TryNumberToSize(isolate, number, &result); | 103 bool is_valid = TryNumberToSize(isolate, number, &result); |
107 CHECK(is_valid); | 104 CHECK(is_valid); |
108 return result; | 105 return result; |
109 } | 106 } |
110 | 107 |
111 } } // namespace v8::internal | 108 } } // namespace v8::internal |
112 | 109 |
113 #endif // V8_V8CONVERSIONS_H_ | 110 #endif // V8_V8CONVERSIONS_H_ |
OLD | NEW |