Chromium Code Reviews| Index: runtime/lib/typed_data.cc |
| =================================================================== |
| --- runtime/lib/typed_data.cc (revision 23032) |
| +++ runtime/lib/typed_data.cc (working copy) |
| @@ -13,6 +13,8 @@ |
| namespace dart { |
| +DECLARE_FLAG(bool, throw_on_53bit_overflow); |
| + |
| // TypedData. |
| // Checks to see if offset_in_bytes is in the range. |
| @@ -261,6 +263,11 @@ |
| } else { \ |
| result = Integer::New(value); \ |
| } \ |
| + if (FLAG_throw_on_53bit_overflow && !result.FitsIn53Bits()) { \ |
| + const Array& exc_args = Array::Handle(Array::New(1)); \ |
| + exc_args.SetAt(0, Object::Handle(String::New("TypedData_getter"))); \ |
| + Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args);\ |
| + } \ |
| return result.raw(); \ |
| } \ |
| @@ -384,7 +391,13 @@ |
| } else { |
| value = Utils::HostToBigEndian64(value); |
| } |
| - return Integer::New(value); |
| + const Integer& i = Integer::Handle(Integer::New(value)); |
| + if (FLAG_throw_on_53bit_overflow && !i.FitsIn53Bits()) { |
| + const Array& exc_args = Array::Handle(Array::New(1)); |
| + exc_args.SetAt(0, Object::Handle(String::New("ByteData_ToEndianInt64"))); |
| + Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args); |
| + } |
| + return i.AsValidInteger(); |
|
siva
2013/05/23 01:28:22
Ditto comment about the AsValidInteger.
zra
2013/05/23 15:59:07
Done.
|
| } |
| @@ -408,7 +421,13 @@ |
| if (value > static_cast<uint64_t>(Mint::kMaxValue)) { |
|
siva
2013/05/23 01:28:22
What about throwing an exception here?
zra
2013/05/23 15:59:07
Yes, I've added a throw here, too.
|
| return BigintOperations::NewFromUint64(value); |
| } |
| - return Integer::New(value); |
| + const Integer& i = Integer::Handle(Integer::New(value)); |
| + if (FLAG_throw_on_53bit_overflow && !i.FitsIn53Bits()) { |
| + const Array& exc_args = Array::Handle(Array::New(1)); |
| + exc_args.SetAt(0, Object::Handle(String::New("ByteData_ToEndianUint64"))); |
| + Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args); |
| + } |
| + return i.AsValidInteger(); |
|
siva
2013/05/23 01:28:22
Ditto comment about AsValidInteger
zra
2013/05/23 15:59:07
Done.
|
| } |