| 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 |
| 190 // The native function only accepts one-byte strings. The Dart side converts | 194 // Indices should be inside the string, and 0 <= start < end <= len. |
| 191 // other types of strings to one-byte strings, if necessary. | 195 if (0 <= start && start < end && end <= len) { |
| 192 if ((!value.IsOneByteString() && !value.IsExternalOneByteString()) | 196 double double_value; |
| 193 || (len == 0)) { | 197 if (String::ParseDouble(value, start, end, &double_value)) { |
| 194 return Object::null(); | 198 return Double::New(double_value); |
| 199 } |
| 195 } | 200 } |
| 196 | 201 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 } | 202 } |
| 206 | 203 |
| 207 | 204 |
| 208 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) { | 205 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) { |
| 209 // The boundaries are exclusive. | 206 // The boundaries are exclusive. |
| 210 static const double kLowerBoundary = -1e21; | 207 static const double kLowerBoundary = -1e21; |
| 211 static const double kUpperBoundary = 1e21; | 208 static const double kUpperBoundary = 1e21; |
| 212 | 209 |
| 213 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 210 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 214 GET_NON_NULL_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->NativeArgAt(1)); | 211 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) { | 268 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
| 272 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 269 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 273 // Include negative zero, infinity. | 270 // Include negative zero, infinity. |
| 274 double dval = arg.value(); | 271 double dval = arg.value(); |
| 275 return Bool::Get(signbit(dval) && !isnan(dval)).raw(); | 272 return Bool::Get(signbit(dval) && !isnan(dval)).raw(); |
| 276 } | 273 } |
| 277 | 274 |
| 278 // Add here only functions using/referring to old-style casts. | 275 // Add here only functions using/referring to old-style casts. |
| 279 | 276 |
| 280 } // namespace dart | 277 } // namespace dart |
| OLD | NEW |