OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 | 6 |
7 #include "platform/math.h" | 7 #include "platform/math.h" |
8 | 8 |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/code_generator.h" // DartModulo. | 10 #include "vm/code_generator.h" // DartModulo. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 // MAC OSX math library produces old style cast warning. | 175 // MAC OSX math library produces old style cast warning. |
176 #pragma GCC diagnostic ignored "-Wold-style-cast" | 176 #pragma GCC diagnostic ignored "-Wold-style-cast" |
177 #endif | 177 #endif |
178 | 178 |
179 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { | 179 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { |
180 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 180 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
181 return DoubleToInteger(arg.value(), "Infinity or NaN toInt"); | 181 return DoubleToInteger(arg.value(), "Infinity or NaN toInt"); |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 DEFINE_NATIVE_ENTRY(Double_parse, 1) { | 185 DEFINE_NATIVE_ENTRY(Double_parse, 3) { |
186 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); | 186 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); |
187 GET_NON_NULL_NATIVE_ARGUMENT(Integer, startValue, arguments->NativeArgAt(1)); | |
188 GET_NON_NULL_NATIVE_ARGUMENT(Integer, endValue, arguments->NativeArgAt(2)); | |
187 | 189 |
190 const intptr_t start = startValue.AsTruncatedUint32Value(); | |
191 const intptr_t end = endValue.AsTruncatedUint32Value(); | |
188 const intptr_t len = value.Length(); | 192 const intptr_t len = value.Length(); |
189 | 193 |
194 // Indices should be inside the string, and 0 <= start < end <= len. | |
190 // The native function only accepts one-byte strings. The Dart side converts | 195 // The native function only accepts one-byte strings. The Dart side converts |
Vyacheslav Egorov (Google)
2014/07/01 11:36:18
This comment does not seem to be valid anymore.
Lasse Reichstein Nielsen
2014/07/01 11:54:18
Well spotted.
| |
191 // other types of strings to one-byte strings, if necessary. | 196 // other types of strings to one-byte strings, if necessary. |
192 if ((!value.IsOneByteString() && !value.IsExternalOneByteString()) | 197 if (0 <= start && start < end && end <= len) { |
193 || (len == 0)) { | 198 double double_value; |
194 return Object::null(); | 199 if (String::ParseDouble(value, start, end, &double_value)) { |
200 return Double::New(double_value); | |
201 } | |
195 } | 202 } |
196 | 203 return Object::null(); |
197 double double_value; | |
198 const char* cstr = value.ToCString(); | |
199 ASSERT(cstr != NULL); | |
200 if (CStringToDouble(cstr, len, &double_value)) { | |
201 return Double::New(double_value); | |
202 } else { | |
203 return Object::null(); | |
204 } | |
205 } | 204 } |
206 | 205 |
207 | 206 |
208 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) { | 207 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) { |
209 // The boundaries are exclusive. | 208 // The boundaries are exclusive. |
210 static const double kLowerBoundary = -1e21; | 209 static const double kLowerBoundary = -1e21; |
211 static const double kUpperBoundary = 1e21; | 210 static const double kUpperBoundary = 1e21; |
212 | 211 |
213 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 212 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
214 GET_NON_NULL_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->NativeArgAt(1)); | 213 GET_NON_NULL_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->NativeArgAt(1)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 270 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
272 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 271 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
273 // Include negative zero, infinity. | 272 // Include negative zero, infinity. |
274 double dval = arg.value(); | 273 double dval = arg.value(); |
275 return Bool::Get(signbit(dval) && !isnan(dval)).raw(); | 274 return Bool::Get(signbit(dval) && !isnan(dval)).raw(); |
276 } | 275 } |
277 | 276 |
278 // Add here only functions using/referring to old-style casts. | 277 // Add here only functions using/referring to old-style casts. |
279 | 278 |
280 } // namespace dart | 279 } // namespace dart |
OLD | NEW |