Chromium Code Reviews| 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 <math.h> | 5 #include <math.h> |
| 6 | 6 |
| 7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.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. |
| 11 #include "vm/double_conversion.h" | 11 #include "vm/double_conversion.h" |
| 12 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
| 13 #include "vm/native_entry.h" | 13 #include "vm/native_entry.h" |
| 14 #include "vm/object.h" | 14 #include "vm/object.h" |
| 15 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 | 18 |
| 19 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); | |
| 19 DECLARE_FLAG(bool, trace_intrinsified_natives); | 20 DECLARE_FLAG(bool, trace_intrinsified_natives); |
| 20 | 21 |
| 21 DEFINE_NATIVE_ENTRY(Double_doubleFromInteger, 2) { | 22 DEFINE_NATIVE_ENTRY(Double_doubleFromInteger, 2) { |
| 22 ASSERT(AbstractTypeArguments::CheckedHandle( | 23 ASSERT(AbstractTypeArguments::CheckedHandle( |
| 23 arguments->NativeArgAt(0)).IsNull()); | 24 arguments->NativeArgAt(0)).IsNull()); |
| 24 const Integer& value = Integer::CheckedHandle(arguments->NativeArgAt(1)); | 25 const Integer& value = Integer::CheckedHandle(arguments->NativeArgAt(1)); |
| 25 if (FLAG_trace_intrinsified_natives) { | 26 if (FLAG_trace_intrinsified_natives) { |
| 26 OS::Print("Double_doubleFromInteger %s\n", value.ToCString()); | 27 OS::Print("Double_doubleFromInteger %s\n", value.ToCString()); |
| 27 } | 28 } |
| 28 return Double::New(value.AsDoubleValue()); | 29 return Double::New(value.AsDoubleValue()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 | 75 |
| 75 | 76 |
| 76 static RawInteger* DoubleToInteger(double val, const char* error_msg) { | 77 static RawInteger* DoubleToInteger(double val, const char* error_msg) { |
| 77 if (isinf(val) || isnan(val)) { | 78 if (isinf(val) || isnan(val)) { |
| 78 const Array& args = Array::Handle(Array::New(1)); | 79 const Array& args = Array::Handle(Array::New(1)); |
| 79 args.SetAt(0, String::Handle(String::New(error_msg))); | 80 args.SetAt(0, String::Handle(String::New(error_msg))); |
| 80 Exceptions::ThrowByType(Exceptions::kUnsupported, args); | 81 Exceptions::ThrowByType(Exceptions::kUnsupported, args); |
| 81 } | 82 } |
| 82 const Bigint& big = Bigint::Handle(BigintOperations::NewFromDouble(val)); | 83 const Bigint& big = Bigint::Handle(BigintOperations::NewFromDouble(val)); |
| 83 if (BigintOperations::FitsIntoInt64(big)) { | 84 if (BigintOperations::FitsIntoInt64(big)) { |
| 84 return Integer::New(BigintOperations::ToInt64(big)); | 85 const Integer& i = Integer::Handle( |
| 86 Integer::New(BigintOperations::ToInt64(big))); | |
| 87 if (FLAG_throw_on_javascript_int_overflow && !i.FitsIn53Bits()) { | |
|
siva
2013/05/23 17:38:57
just
if (FLAG_throw_on_javascript_int_overflow) {
| |
| 88 Integer::CheckForFiftyThreeBitOverflow(i, "DoubleToInteger"); | |
| 89 } | |
| 90 return i.raw(); | |
| 85 } else { | 91 } else { |
| 86 return big.raw(); | 92 return big.raw(); |
| 87 } | 93 } |
| 88 } | 94 } |
| 89 | 95 |
| 90 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { | 96 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { |
| 91 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); | 97 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); |
| 92 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); | 98 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); |
| 93 double right = right_object.value(); | 99 double right = right_object.value(); |
| 94 if (FLAG_trace_intrinsified_natives) { | 100 if (FLAG_trace_intrinsified_natives) { |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 | 362 |
| 357 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 363 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
| 358 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 364 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 359 // Include negative zero, infinity. | 365 // Include negative zero, infinity. |
| 360 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 366 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); |
| 361 } | 367 } |
| 362 | 368 |
| 363 // Add here only functions using/referring to old-style casts. | 369 // Add here only functions using/referring to old-style casts. |
| 364 | 370 |
| 365 } // namespace dart | 371 } // namespace dart |
| OLD | NEW |