Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1346)

Unified Diff: runtime/lib/typed_data.cc

Issue 15743017: Adds a flag to the standalone vm to throw an exception on 53-bit integer overflow. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_javascript_int_overflow);
+
// TypedData.
// Checks to see if offset_in_bytes is in the range.
@@ -261,6 +263,9 @@
} else { \
result = Integer::New(value); \
} \
+ if (FLAG_throw_on_javascript_int_overflow && !result.FitsIn53Bits()) { \
siva 2013/05/23 17:38:57 Ditto comment about the FitsIn53Bits check here.
+ Integer::CheckForFiftyThreeBitOverflow(result, "TypedData_getter"); \
+ } \
return result.raw(); \
} \
@@ -384,7 +389,11 @@
} else {
value = Utils::HostToBigEndian64(value);
}
- return Integer::New(value);
+ const Integer& i = Integer::Handle(Integer::New(value));
+ if (FLAG_throw_on_javascript_int_overflow && !i.FitsIn53Bits()) {
siva 2013/05/23 17:38:57 Ditto comment about the FitsIn53Bits check here.
+ Integer::CheckForFiftyThreeBitOverflow(i, "ByteData_ToEndianInt64");
+ }
+ return i.raw();
}
@@ -406,9 +415,19 @@
value = Utils::HostToBigEndian64(value);
}
if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
- return BigintOperations::NewFromUint64(value);
+ if (FLAG_throw_on_javascript_int_overflow) {
+ const Array& arg = Array::Handle(Array::New(1));
+ arg.SetAt(0, Object::Handle(String::New("ByteData_ToEndianUint64")));
+ Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, arg);
+ } else {
+ return BigintOperations::NewFromUint64(value);
+ }
}
- return Integer::New(value);
+ const Integer& i = Integer::Handle(Integer::New(value));
+ if (FLAG_throw_on_javascript_int_overflow && !i.FitsIn53Bits()) {
siva 2013/05/23 17:38:57 Ditto comment about FitsIn53Bits check here.
+ Integer::CheckForFiftyThreeBitOverflow(i, "ByteData_ToEndianUint64");
+ }
+ return i.raw();
}
« runtime/lib/double.cc ('K') | « runtime/lib/integers.cc ('k') | runtime/vm/exceptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698