| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VMOptions=--throw_on_javascript_int_overflow --optimization_counter_threshold
=10 | 5 // VMOptions=--throw_on_javascript_int_overflow --optimization_counter_threshold
=10 |
| 6 | 6 |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 | 23 |
| 24 | 24 |
| 25 int is_arg; | 25 int is_arg; |
| 26 int integer_shift() { | 26 int integer_shift() { |
| 27 return is_arg << 1; | 27 return is_arg << 1; |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 int max_add_throws() { | 31 int max_add_throws() { |
| 32 return 0xFFFFFFFFFFFFF + 1; | 32 return 0x1FFFFFFFFFFFFF + 1; |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 35 |
| 36 int min_sub_throws() { | 36 int min_sub_throws() { |
| 37 return -0xFFFFFFFFFFFFF - 2; | 37 return -0x1FFFFFFFFFFFFF - 1; |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 int n_arg; | 41 int n_arg; |
| 42 int negate() { | 42 int negate() { |
| 43 return -n_arg; | 43 return -n_arg; |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 int max_literal() { | 47 int max_literal() { |
| 48 return 0xFFFFFFFFFFFFF; | 48 return 0x1FFFFFFFFFFFFF; |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 int min_literal() { | 52 int min_literal() { |
| 53 var min_literal = -0xFFFFFFFFFFFFF - 1; | 53 var min_literal = -0x1FFFFFFFFFFFFF; |
| 54 return min_literal; | 54 return min_literal; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // We don't test for the _FiftyThreeBitOverflowError since it's not visible. | 57 // We don't test for the _FiftyFourBitOverflowError since it's not visible. |
| 58 // It's should not be visible since it doesn't exist on dart2js. | 58 // It should not be visible since it doesn't exist on dart2js. |
| 59 bool is53BitError(e) => e is Error && "$e".startsWith("53-bit Overflow:"); | 59 bool is54BitError(e) => e is Error && "$e".startsWith("54-bit Overflow:"); |
| 60 | 60 |
| 61 main() { | 61 main() { |
| 62 Expect.equals(0xFFFFFFFFFFFFF, max_literal()); | 62 Expect.equals(0x1FFFFFFFFFFFFF, max_literal()); |
| 63 Expect.equals(-0xFFFFFFFFFFFFF - 1, min_literal()); | 63 Expect.equals(-0x1FFFFFFFFFFFFF, min_literal()); |
| 64 | 64 |
| 65 // Run the tests once before optimizations. | 65 // Run the tests once before optimizations. |
| 66 dti_arg = 1.9e16; | 66 dti_arg = 1.9e16; |
| 67 Expect.throws(double_to_int, is53BitError); | 67 Expect.throws(double_to_int, is54BitError); |
| 68 | 68 |
| 69 ia_arg1 = (1 << 51); | 69 ia_arg1 = (1 << 52); |
| 70 ia_arg2 = (1 << 51); | 70 ia_arg2 = (1 << 52); |
| 71 Expect.throws(integer_add, is53BitError); | 71 Expect.throws(integer_add, is54BitError); |
| 72 | 72 |
| 73 n_arg = -0xFFFFFFFFFFFFF - 1; | 73 n_arg = -0x1FFFFFFFFFFFFF; |
| 74 Expect.throws(negate, is53BitError); | 74 Expect.equals(0x1FFFFFFFFFFFFF, negate()); |
| 75 | 75 |
| 76 is_arg = (1 << 51); | 76 is_arg = (1 << 52); |
| 77 Expect.throws(integer_shift, is53BitError); | 77 Expect.throws(integer_shift, is54BitError); |
| 78 | 78 |
| 79 Expect.throws(max_add_throws, is53BitError); | 79 Expect.throws(max_add_throws, is54BitError); |
| 80 Expect.throws(min_sub_throws, is53BitError); | 80 Expect.throws(min_sub_throws, is54BitError); |
| 81 | 81 |
| 82 for (int i = 0; i < 20; i++) { | 82 for (int i = 0; i < 20; i++) { |
| 83 dti_arg = i.toDouble(); | 83 dti_arg = i.toDouble(); |
| 84 // Expect.throws calls through the closure, so we have to here, too. | 84 // Expect.throws calls through the closure, so we have to here, too. |
| 85 var f = double_to_int; | 85 var f = double_to_int; |
| 86 Expect.equals(i, f()); | 86 Expect.equals(i, f()); |
| 87 | 87 |
| 88 ia_arg1 = i; | 88 ia_arg1 = i; |
| 89 ia_arg2 = i; | 89 ia_arg2 = i; |
| 90 f = integer_add; | 90 f = integer_add; |
| 91 Expect.equals(i + i, f()); | 91 Expect.equals(i + i, f()); |
| 92 | 92 |
| 93 n_arg = i; | 93 n_arg = i; |
| 94 f = negate; | 94 f = negate; |
| 95 Expect.equals(-i, f()); | 95 Expect.equals(-i, f()); |
| 96 | 96 |
| 97 is_arg = i; | 97 is_arg = i; |
| 98 f = integer_shift; | 98 f = integer_shift; |
| 99 Expect.equals(i << 1, f()); | 99 Expect.equals(i << 1, f()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // The optimized functions should now deoptimize and throw the error. | 102 // The optimized functions should now deoptimize and throw the error. |
| 103 dti_arg = 1.9e16; | 103 dti_arg = 1.9e16; |
| 104 Expect.throws(double_to_int, is53BitError); | 104 Expect.throws(double_to_int, is54BitError); |
| 105 | 105 |
| 106 ia_arg1 = (1 << 51); | 106 ia_arg1 = (1 << 52); |
| 107 ia_arg2 = (1 << 51); | 107 ia_arg2 = (1 << 52); |
| 108 Expect.throws(integer_add, is53BitError); | 108 Expect.throws(integer_add, is54BitError); |
| 109 | 109 |
| 110 n_arg = -0xFFFFFFFFFFFFF - 1; | 110 n_arg = -0x1FFFFFFFFFFFFF; |
| 111 Expect.throws(negate, is53BitError); | 111 Expect.equals(0x1FFFFFFFFFFFFF, negate()); |
| 112 | 112 |
| 113 is_arg = (1 << 51); | 113 is_arg = (1 << 52); |
| 114 Expect.throws(integer_shift, is53BitError); | 114 Expect.throws(integer_shift, is54BitError); |
| 115 | 115 |
| 116 Expect.throws(max_add_throws, is53BitError); | 116 Expect.throws(max_add_throws, is54BitError); |
| 117 Expect.throws(min_sub_throws, is53BitError); | 117 Expect.throws(min_sub_throws, is54BitError); |
| 118 } | 118 } |
| OLD | NEW |