Chromium Code Reviews| Index: runtime/vm/object.cc |
| =================================================================== |
| --- runtime/vm/object.cc (revision 23771) |
| +++ runtime/vm/object.cc (working copy) |
| @@ -10412,6 +10412,14 @@ |
| } |
| +// Throw FiftyThreeBitOverflow exception. |
| +static void ThrowFiftyThreeBitOverflow(const Integer& i) { |
| + const Array& exc_args = Array::Handle(Array::New(1)); |
| + exc_args.SetAt(0, i); |
| + Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args); |
| +} |
| + |
| + |
| RawInteger* Integer::New(const String& str, Heap::Space space) { |
| // We are not supposed to have integers represented as two byte strings. |
| ASSERT(str.IsOneByteString()); |
| @@ -10420,12 +10428,19 @@ |
| const Bigint& big = Bigint::Handle(Bigint::New(str, space)); |
| ASSERT(!BigintOperations::FitsIntoSmi(big)); |
| ASSERT(!BigintOperations::FitsIntoInt64(big)); |
| + if (FLAG_throw_on_javascript_int_overflow) { |
| + ThrowFiftyThreeBitOverflow(big); |
| + } |
| return big.raw(); |
| } |
| return Integer::New(value, space); |
| } |
| +// This is called from LiteralToken::New() in the parser, so we can't |
| +// raise an exception for 53-bit overflow here. Instead we do it in |
| +// Parser::CurrentIntegerLiteral(), which is the point in the parser where |
| +// integer literals escape, so we can call Parser::ErrorMsg(). |
| RawInteger* Integer::NewCanonical(const String& str) { |
| // We are not supposed to have integers represented as two byte strings. |
| ASSERT(str.IsOneByteString()); |
| @@ -10443,14 +10458,6 @@ |
| } |
| -// Throw FiftyThreeBitOverflow exception. |
| -static void ThrowFiftyThreeBitOverflow(const Integer& i) { |
| - const Array& exc_args = Array::Handle(Array::New(1)); |
| - exc_args.SetAt(0, i); |
| - Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args); |
| -} |
| - |
| - |
| RawInteger* Integer::New(int64_t value, Heap::Space space) { |
| if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
| return Smi::New(value); |
| @@ -10495,31 +10502,33 @@ |
| } |
| -static void CheckFiftyThreeBitOverflow(const Integer &i) { |
| +// Returns true if the signed Integer i requires more than 53 bits. |
|
srdjan
2013/06/07 21:03:42
There is no 'i' that is mentioned in the comment.
zra
2013/06/07 21:28:28
Removed from comment.
|
| +bool Integer::CheckFiftyThreeBitOverflow() const { |
| // Always overflow if the value doesn't fit into an int64_t. |
| int64_t value = 1ULL << 63; |
| - if (i.IsSmi()) { |
| - value = i.AsInt64Value(); |
| - } else if (i.IsMint()) { |
| + if (IsSmi()) { |
| + value = AsInt64Value(); |
| + } else if (IsMint()) { |
| Mint& mint = Mint::Handle(); |
| - mint ^= i.raw(); |
| + mint ^= raw(); |
| value = mint.value(); |
| } else { |
| - ASSERT(i.IsBigint()); |
| + ASSERT(IsBigint()); |
| Bigint& big_value = Bigint::Handle(); |
| - big_value ^= i.raw(); |
| + big_value ^= raw(); |
| if (BigintOperations::FitsIntoInt64(big_value)) { |
| value = BigintOperations::ToInt64(big_value); |
| } |
| } |
| - if (Utils::IsInt(53, value)) return; |
| - ThrowFiftyThreeBitOverflow(i); |
| + if (Utils::IsInt(53, value)) return false; |
| + return true; |
|
srdjan
2013/06/07 21:03:42
return !Utils::IsInt(53, value);
zra
2013/06/07 21:28:28
Done.
|
| } |
| RawInteger* Integer::AsValidInteger() const { |
| - if (FLAG_throw_on_javascript_int_overflow) { |
| - CheckFiftyThreeBitOverflow(*this); |
| + if (FLAG_throw_on_javascript_int_overflow && |
| + CheckFiftyThreeBitOverflow()) { |
| + ThrowFiftyThreeBitOverflow(*this); |
| } |
| if (IsSmi()) return raw(); |
| if (IsMint()) { |