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

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 11478 matching lines...) Expand 10 before | Expand all | Expand 10 after
11489 } 11489 }
11490 11490
11491 11491
11492 // dart2js represents integers as double precision floats, which can represent 11492 // dart2js represents integers as double precision floats, which can represent
11493 // anything in the range -2^53 ... 2^53. 11493 // anything in the range -2^53 ... 2^53.
11494 static bool IsJavascriptInt(int64_t value) { 11494 static bool IsJavascriptInt(int64_t value) {
11495 return ((-0x20000000000000LL <= value) && (value <= 0x20000000000000LL)); 11495 return ((-0x20000000000000LL <= value) && (value <= 0x20000000000000LL));
11496 } 11496 }
11497 11497
11498 11498
11499 RawInteger* Integer::New(int64_t value, Heap::Space space) { 11499 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) {
11500 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 11500 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
11501 return Smi::New(value); 11501 return Smi::New(value);
11502 } 11502 }
11503 if (FLAG_throw_on_javascript_int_overflow && !IsJavascriptInt(value)) { 11503 if (!silent &&
11504 FLAG_throw_on_javascript_int_overflow &&
11505 !IsJavascriptInt(value)) {
11504 const Integer &i = Integer::Handle(Mint::New(value)); 11506 const Integer &i = Integer::Handle(Mint::New(value));
11505 ThrowJavascriptIntegerOverflow(i); 11507 ThrowJavascriptIntegerOverflow(i);
11506 } 11508 }
11507 return Mint::New(value, space); 11509 return Mint::New(value, space);
11508 } 11510 }
11509 11511
11510 11512
11511 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { 11513 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) {
11512 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { 11514 if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
11513 if (FLAG_throw_on_javascript_int_overflow) { 11515 if (FLAG_throw_on_javascript_int_overflow) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
11736 return BigintOperations::BitXor(op1, op2); 11738 return BigintOperations::BitXor(op1, op2);
11737 default: 11739 default:
11738 UNIMPLEMENTED(); 11740 UNIMPLEMENTED();
11739 } 11741 }
11740 } 11742 }
11741 return Integer::null(); 11743 return Integer::null();
11742 } 11744 }
11743 11745
11744 11746
11745 // TODO(srdjan): Clarify handling of negative right operand in a shift op. 11747 // TODO(srdjan): Clarify handling of negative right operand in a shift op.
11746 RawInteger* Smi::ShiftOp(Token::Kind kind, const Smi& other) const { 11748 RawInteger* Smi::ShiftOp(Token::Kind kind,
11749 const Smi& other,
11750 const bool silent) const {
11747 intptr_t result = 0; 11751 intptr_t result = 0;
11748 const intptr_t left_value = Value(); 11752 const intptr_t left_value = Value();
11749 const intptr_t right_value = other.Value(); 11753 const intptr_t right_value = other.Value();
11750 ASSERT(right_value >= 0); 11754 ASSERT(right_value >= 0);
11751 switch (kind) { 11755 switch (kind) {
11752 case Token::kSHL: { 11756 case Token::kSHL: {
11753 if ((left_value == 0) || (right_value == 0)) { 11757 if ((left_value == 0) || (right_value == 0)) {
11754 return raw(); 11758 return raw();
11755 } 11759 }
11756 { // Check for overflow. 11760 { // Check for overflow.
11757 int cnt = Utils::HighestBit(left_value); 11761 int cnt = Utils::HighestBit(left_value);
11758 if ((cnt + right_value) >= Smi::kBits) { 11762 if ((cnt + right_value) >= Smi::kBits) {
11759 if ((cnt + right_value) >= Mint::kBits) { 11763 if ((cnt + right_value) >= Mint::kBits) {
11760 return BigintOperations::ShiftLeft( 11764 return BigintOperations::ShiftLeft(
11761 Bigint::Handle(BigintOperations::NewFromSmi(*this)), 11765 Bigint::Handle(BigintOperations::NewFromSmi(*this)),
11762 right_value); 11766 right_value);
11763 } else { 11767 } else {
11764 int64_t left_64 = left_value; 11768 int64_t left_64 = left_value;
11765 return Integer::New(left_64 << right_value); 11769 return Integer::New(left_64 << right_value, Heap::kNew, silent);
11766 } 11770 }
11767 } 11771 }
11768 } 11772 }
11769 result = left_value << right_value; 11773 result = left_value << right_value;
11770 break; 11774 break;
11771 } 11775 }
11772 case Token::kSHR: { 11776 case Token::kSHR: {
11773 const intptr_t shift_amount = 11777 const intptr_t shift_amount =
11774 (right_value >= kBitsPerWord) ? (kBitsPerWord - 1) : right_value; 11778 (right_value >= kBitsPerWord) ? (kBitsPerWord - 1) : right_value;
11775 result = left_value >> shift_amount; 11779 result = left_value >> shift_amount;
(...skipping 2834 matching lines...) Expand 10 before | Expand all | Expand 10 after
14610 } 14614 }
14611 14615
14612 14616
14613 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14617 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14614 stream->OpenObject(); 14618 stream->OpenObject();
14615 stream->CloseObject(); 14619 stream->CloseObject();
14616 } 14620 }
14617 14621
14618 14622
14619 } // namespace dart 14623 } // namespace dart
OLDNEW
« runtime/vm/ast.h ('K') | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698