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

Side by Side Diff: runtime/vm/object.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10368 matching lines...) Expand 10 before | Expand all | Expand 10 after
10379 10379
10380 10380
10381 RawInteger* Integer::New(int64_t value, Heap::Space space) { 10381 RawInteger* Integer::New(int64_t value, Heap::Space space) {
10382 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 10382 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
10383 return Smi::New(value); 10383 return Smi::New(value);
10384 } 10384 }
10385 return Mint::New(value, space); 10385 return Mint::New(value, space);
10386 } 10386 }
10387 10387
10388 10388
10389 // Throw kFiftyThreeBitOverflow if the result of an operation overflows
10390 // 53 bits.
10391 void Integer::CheckForFiftyThreeBitOverflow(const Integer& i, const char* msg) {
10392 if (i.FitsIn53Bits()) return;
10393 const Array& exc_args = Array::Handle(Array::New(1));
10394 exc_args.SetAt(0, Object::Handle(String::New(msg)));
10395 Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args);
10396 return;
10397 }
10398
10399
10389 double Integer::AsDoubleValue() const { 10400 double Integer::AsDoubleValue() const {
10390 UNIMPLEMENTED(); 10401 UNIMPLEMENTED();
10391 return 0.0; 10402 return 0.0;
10392 } 10403 }
10393 10404
10394 10405
10395 int64_t Integer::AsInt64Value() const { 10406 int64_t Integer::AsInt64Value() const {
10396 UNIMPLEMENTED(); 10407 UNIMPLEMENTED();
10397 return 0; 10408 return 0;
10398 } 10409 }
10399 10410
10400 10411
10412 bool Integer::FitsIn53Bits() const {
10413 UNIMPLEMENTED();
10414 return false;
10415 }
10416
10417
10401 int Integer::CompareWith(const Integer& other) const { 10418 int Integer::CompareWith(const Integer& other) const {
10402 UNIMPLEMENTED(); 10419 UNIMPLEMENTED();
10403 return 0; 10420 return 0;
10404 } 10421 }
10405 10422
10406 10423
10407 RawInteger* Integer::AsValidInteger() const { 10424 RawInteger* Integer::AsValidInteger() const {
10408 if (IsSmi()) return raw(); 10425 if (IsSmi()) return raw();
10409 if (IsMint()) { 10426 if (IsMint()) {
10410 Mint& mint = Mint::Handle(); 10427 Mint& mint = Mint::Handle();
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
10765 double Mint::AsDoubleValue() const { 10782 double Mint::AsDoubleValue() const {
10766 return static_cast<double>(this->value()); 10783 return static_cast<double>(this->value());
10767 } 10784 }
10768 10785
10769 10786
10770 int64_t Mint::AsInt64Value() const { 10787 int64_t Mint::AsInt64Value() const {
10771 return this->value(); 10788 return this->value();
10772 } 10789 }
10773 10790
10774 10791
10792 bool Mint::FitsIn53Bits() const {
10793 int64_t v = AsInt64Value();
10794 return Utils::IsInt(53, v);
10795 }
10796
10797
10775 int Mint::CompareWith(const Integer& other) const { 10798 int Mint::CompareWith(const Integer& other) const {
10776 ASSERT(!FitsIntoSmi(*this)); 10799 ASSERT(!FitsIntoSmi(*this));
10777 if (other.IsMint() || other.IsSmi()) { 10800 if (other.IsMint() || other.IsSmi()) {
10778 int64_t a = AsInt64Value(); 10801 int64_t a = AsInt64Value();
10779 int64_t b = other.AsInt64Value(); 10802 int64_t b = other.AsInt64Value();
10780 if (a < b) { 10803 if (a < b) {
10781 return -1; 10804 return -1;
10782 } else if (a > b) { 10805 } else if (a > b) {
10783 return 1; 10806 return 1;
10784 } else { 10807 } else {
(...skipping 2482 matching lines...) Expand 10 before | Expand all | Expand 10 after
13267 } 13290 }
13268 return result.raw(); 13291 return result.raw();
13269 } 13292 }
13270 13293
13271 13294
13272 const char* WeakProperty::ToCString() const { 13295 const char* WeakProperty::ToCString() const {
13273 return "_WeakProperty"; 13296 return "_WeakProperty";
13274 } 13297 }
13275 13298
13276 } // namespace dart 13299 } // namespace dart
OLDNEW
« runtime/lib/typed_data.cc ('K') | « runtime/vm/object.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698