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

Side by Side Diff: runtime/vm/object.cc

Issue 22640019: Fix for running with --throw_on_javascript_int_overflow: recognize pattern (a << b) & mask and test… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 11491 matching lines...) Expand 10 before | Expand all | Expand 10 after
11502 } 11502 }
11503 11503
11504 11504
11505 // dart2js represents integers as double precision floats, which can represent 11505 // dart2js represents integers as double precision floats, which can represent
11506 // anything in the range -2^53 ... 2^53. 11506 // anything in the range -2^53 ... 2^53.
11507 static bool IsJavascriptInt(int64_t value) { 11507 static bool IsJavascriptInt(int64_t value) {
11508 return ((-0x20000000000000LL <= value) && (value <= 0x20000000000000LL)); 11508 return ((-0x20000000000000LL <= value) && (value <= 0x20000000000000LL));
11509 } 11509 }
11510 11510
11511 11511
11512 RawInteger* Integer::New(int64_t value, Heap::Space space) { 11512 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) {
11513 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 11513 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
11514 return Smi::New(value); 11514 return Smi::New(value);
11515 } 11515 }
11516 if (FLAG_throw_on_javascript_int_overflow && !IsJavascriptInt(value)) { 11516 if (!silent &&
11517 FLAG_throw_on_javascript_int_overflow &&
11518 !IsJavascriptInt(value)) {
11517 const Integer &i = Integer::Handle(Mint::New(value)); 11519 const Integer &i = Integer::Handle(Mint::New(value));
11518 ThrowJavascriptIntegerOverflow(i); 11520 ThrowJavascriptIntegerOverflow(i);
11519 } 11521 }
11520 return Mint::New(value, space); 11522 return Mint::New(value, space);
11521 } 11523 }
11522 11524
11523 11525
11524 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { 11526 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) {
11525 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { 11527 if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
11526 if (FLAG_throw_on_javascript_int_overflow) { 11528 if (FLAG_throw_on_javascript_int_overflow) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
11749 return BigintOperations::BitXor(op1, op2); 11751 return BigintOperations::BitXor(op1, op2);
11750 default: 11752 default:
11751 UNIMPLEMENTED(); 11753 UNIMPLEMENTED();
11752 } 11754 }
11753 } 11755 }
11754 return Integer::null(); 11756 return Integer::null();
11755 } 11757 }
11756 11758
11757 11759
11758 // TODO(srdjan): Clarify handling of negative right operand in a shift op. 11760 // TODO(srdjan): Clarify handling of negative right operand in a shift op.
11759 RawInteger* Smi::ShiftOp(Token::Kind kind, const Smi& other) const { 11761 RawInteger* Smi::ShiftOp(Token::Kind kind,
11762 const Smi& other,
11763 const bool silent) const {
11760 intptr_t result = 0; 11764 intptr_t result = 0;
11761 const intptr_t left_value = Value(); 11765 const intptr_t left_value = Value();
11762 const intptr_t right_value = other.Value(); 11766 const intptr_t right_value = other.Value();
11763 ASSERT(right_value >= 0); 11767 ASSERT(right_value >= 0);
11764 switch (kind) { 11768 switch (kind) {
11765 case Token::kSHL: { 11769 case Token::kSHL: {
11766 if ((left_value == 0) || (right_value == 0)) { 11770 if ((left_value == 0) || (right_value == 0)) {
11767 return raw(); 11771 return raw();
11768 } 11772 }
11769 { // Check for overflow. 11773 { // Check for overflow.
11770 int cnt = Utils::HighestBit(left_value); 11774 int cnt = Utils::HighestBit(left_value);
11771 if ((cnt + right_value) >= Smi::kBits) { 11775 if ((cnt + right_value) >= Smi::kBits) {
11772 if ((cnt + right_value) >= Mint::kBits) { 11776 if ((cnt + right_value) >= Mint::kBits) {
11773 return BigintOperations::ShiftLeft( 11777 return BigintOperations::ShiftLeft(
11774 Bigint::Handle(BigintOperations::NewFromSmi(*this)), 11778 Bigint::Handle(BigintOperations::NewFromSmi(*this)),
11775 right_value); 11779 right_value);
11776 } else { 11780 } else {
11777 int64_t left_64 = left_value; 11781 int64_t left_64 = left_value;
11778 return Integer::New(left_64 << right_value); 11782 return Integer::New(left_64 << right_value, Heap::kNew, silent);
11779 } 11783 }
11780 } 11784 }
11781 } 11785 }
11782 result = left_value << right_value; 11786 result = left_value << right_value;
11783 break; 11787 break;
11784 } 11788 }
11785 case Token::kSHR: { 11789 case Token::kSHR: {
11786 const intptr_t shift_amount = 11790 const intptr_t shift_amount =
11787 (right_value >= kBitsPerWord) ? (kBitsPerWord - 1) : right_value; 11791 (right_value >= kBitsPerWord) ? (kBitsPerWord - 1) : right_value;
11788 result = left_value >> shift_amount; 11792 result = left_value >> shift_amount;
(...skipping 2823 matching lines...) Expand 10 before | Expand all | Expand 10 after
14612 } 14616 }
14613 14617
14614 14618
14615 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14619 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14616 stream->OpenObject(); 14620 stream->OpenObject();
14617 stream->CloseObject(); 14621 stream->CloseObject();
14618 } 14622 }
14619 14623
14620 14624
14621 } // namespace dart 14625 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698