| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 15928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15939 ASSERT(!big.FitsIntoInt64()); | 15939 ASSERT(!big.FitsIntoInt64()); |
| 15940 return big.raw(); | 15940 return big.raw(); |
| 15941 } | 15941 } |
| 15942 if (Smi::IsValid(value)) { | 15942 if (Smi::IsValid(value)) { |
| 15943 return Smi::New(static_cast<intptr_t>(value)); | 15943 return Smi::New(static_cast<intptr_t>(value)); |
| 15944 } | 15944 } |
| 15945 return Mint::NewCanonical(value); | 15945 return Mint::NewCanonical(value); |
| 15946 } | 15946 } |
| 15947 | 15947 |
| 15948 | 15948 |
| 15949 // dart2js represents integers as double precision floats, which can represent | |
| 15950 // anything in the range -2^53 ... 2^53. | |
| 15951 static bool IsJavascriptInt(int64_t value) { | |
| 15952 return ((-0x20000000000000LL <= value) && (value <= 0x20000000000000LL)); | |
| 15953 } | |
| 15954 | |
| 15955 | |
| 15956 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) { | 15949 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) { |
| 15957 const bool is_smi = Smi::IsValid(value); | 15950 const bool is_smi = Smi::IsValid(value); |
| 15958 if (!silent && | 15951 if (!silent && |
| 15959 FLAG_throw_on_javascript_int_overflow && | 15952 FLAG_throw_on_javascript_int_overflow && |
| 15960 !IsJavascriptInt(value)) { | 15953 !Utils::IsJavascriptInt(value)) { |
| 15961 const Integer& i = is_smi ? | 15954 const Integer& i = is_smi ? |
| 15962 Integer::Handle(Smi::New(static_cast<intptr_t>(value))) : | 15955 Integer::Handle(Smi::New(static_cast<intptr_t>(value))) : |
| 15963 Integer::Handle(Mint::New(value, space)); | 15956 Integer::Handle(Mint::New(value, space)); |
| 15964 ThrowJavascriptIntegerOverflow(i); | 15957 ThrowJavascriptIntegerOverflow(i); |
| 15965 } | 15958 } |
| 15966 if (is_smi) { | 15959 if (is_smi) { |
| 15967 return Smi::New(static_cast<intptr_t>(value)); | 15960 return Smi::New(static_cast<intptr_t>(value)); |
| 15968 } | 15961 } |
| 15969 return Mint::New(value, space); | 15962 return Mint::New(value, space); |
| 15970 } | 15963 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16048 value = AsInt64Value(); | 16041 value = AsInt64Value(); |
| 16049 } else if (IsMint()) { | 16042 } else if (IsMint()) { |
| 16050 Mint& mint = Mint::Handle(); | 16043 Mint& mint = Mint::Handle(); |
| 16051 mint ^= raw(); | 16044 mint ^= raw(); |
| 16052 value = mint.value(); | 16045 value = mint.value(); |
| 16053 } else { | 16046 } else { |
| 16054 if (Bigint::Cast(*this).FitsIntoInt64()) { | 16047 if (Bigint::Cast(*this).FitsIntoInt64()) { |
| 16055 value = AsInt64Value(); | 16048 value = AsInt64Value(); |
| 16056 } | 16049 } |
| 16057 } | 16050 } |
| 16058 return !IsJavascriptInt(value); | 16051 return !Utils::IsJavascriptInt(value); |
| 16059 } | 16052 } |
| 16060 | 16053 |
| 16061 | 16054 |
| 16062 RawInteger* Integer::AsValidInteger() const { | 16055 RawInteger* Integer::AsValidInteger() const { |
| 16063 if (FLAG_throw_on_javascript_int_overflow && | 16056 if (FLAG_throw_on_javascript_int_overflow && |
| 16064 CheckJavascriptIntegerOverflow()) { | 16057 CheckJavascriptIntegerOverflow()) { |
| 16065 ThrowJavascriptIntegerOverflow(*this); | 16058 ThrowJavascriptIntegerOverflow(*this); |
| 16066 } | 16059 } |
| 16067 if (IsSmi()) return raw(); | 16060 if (IsSmi()) return raw(); |
| 16068 if (IsMint()) { | 16061 if (IsMint()) { |
| (...skipping 4661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20730 return tag_label.ToCString(); | 20723 return tag_label.ToCString(); |
| 20731 } | 20724 } |
| 20732 | 20725 |
| 20733 | 20726 |
| 20734 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20727 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20735 Instance::PrintJSONImpl(stream, ref); | 20728 Instance::PrintJSONImpl(stream, ref); |
| 20736 } | 20729 } |
| 20737 | 20730 |
| 20738 | 20731 |
| 20739 } // namespace dart | 20732 } // namespace dart |
| OLD | NEW |