| 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 --no-use-osr |
| 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 |
| 11 | 11 |
| 12 double dti_arg; | 12 double dti_arg; |
| 13 int double_to_int() { | 13 int double_to_int() { |
| 14 return dti_arg.toInt(); | 14 return dti_arg.toInt(); |
| 15 } | 15 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 int max_literal() { | 47 int max_literal() { |
| 48 return 0x20000000000000; | 48 return 0x20000000000000; |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 int min_literal() { | 52 int min_literal() { |
| 53 var min_literal = -0x20000000000000; | 53 var min_literal = -0x20000000000000; |
| 54 return min_literal; | 54 return min_literal; |
| 55 } | 55 } |
| 56 | 56 |
| 57 |
| 58 int doNotThrow1(a, b) { |
| 59 return (a << b) & 0xFFFFFFFF; |
| 60 } |
| 61 |
| 62 int doNotThrow2(a, b) { |
| 63 return (a << b) & 0xFFFFFFFF; |
| 64 } |
| 65 |
| 66 |
| 67 int doNotThrow3(a, b) { |
| 68 return (a << b) & 0x7FFFFFFF; |
| 69 } |
| 70 |
| 71 |
| 72 int doNotThrow4(a, b) { |
| 73 return (a << b) & 0x7FFFFFFF; |
| 74 } |
| 75 |
| 76 |
| 57 // We don't test for the _JavascriptIntegerOverflowError since it's not visible. | 77 // We don't test for the _JavascriptIntegerOverflowError since it's not visible. |
| 58 // It should not be visible since it doesn't exist on dart2js. | 78 // It should not be visible since it doesn't exist on dart2js. |
| 59 bool isJavascriptIntError(e) => | 79 bool isJavascriptIntError(e) => |
| 60 e is Error && "$e".startsWith("Javascript Integer Overflow:"); | 80 e is Error && "$e".startsWith("Javascript Integer Overflow:"); |
| 61 | 81 |
| 62 main() { | 82 main() { |
| 63 Expect.equals(0x20000000000000, max_literal()); | 83 Expect.equals(0x20000000000000, max_literal()); |
| 64 Expect.equals(-0x20000000000000, min_literal()); | 84 Expect.equals(-0x20000000000000, min_literal()); |
| 65 | 85 |
| 66 // Run the tests once before optimizations. | 86 // Run the tests once before optimizations. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 Expect.throws(integer_add, isJavascriptIntError); | 129 Expect.throws(integer_add, isJavascriptIntError); |
| 110 | 130 |
| 111 n_arg = -0x20000000000000; | 131 n_arg = -0x20000000000000; |
| 112 Expect.equals(0x20000000000000, negate()); | 132 Expect.equals(0x20000000000000, negate()); |
| 113 | 133 |
| 114 is_arg = (1 << 53); | 134 is_arg = (1 << 53); |
| 115 Expect.throws(integer_shift, isJavascriptIntError); | 135 Expect.throws(integer_shift, isJavascriptIntError); |
| 116 | 136 |
| 117 Expect.throws(max_add_throws, isJavascriptIntError); | 137 Expect.throws(max_add_throws, isJavascriptIntError); |
| 118 Expect.throws(min_sub_throws, isJavascriptIntError); | 138 Expect.throws(min_sub_throws, isJavascriptIntError); |
| 139 |
| 140 for (int i = 0; i < 20; i++) { |
| 141 Expect.equals(0xAFAFA000, doNotThrow1(0xFAFAFA, 12)); |
| 142 Expect.equals(0x2FAFA000, doNotThrow3(0xFAFAFA, 12)); |
| 143 Expect.equals(0xABABA000, doNotThrow2(0xFAFAFAABABA, 12)); |
| 144 Expect.equals(0x2BABA000, doNotThrow4(0xFAFAFAABABA, 12)); |
| 145 } |
| 146 for (int i = 0; i < 20; i++) { |
| 147 Expect.equals(0xABABA000, doNotThrow1(0xFAFAFAABABA, 12)); |
| 148 Expect.equals(0x2BABA000, doNotThrow3(0xFAFAFAABABA, 12)); |
| 149 } |
| 150 |
| 119 } | 151 } |
| OLD | NEW |