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 0x1FFFFFFFFFFFFF + 1; | 32 return 0x20000000000000 + 1; |
33 } | 33 } |
34 | 34 |
35 | 35 |
36 int min_sub_throws() { | 36 int min_sub_throws() { |
37 return -0x1FFFFFFFFFFFFF - 1; | 37 return -0x20000000000000 - 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 0x1FFFFFFFFFFFFF; | 48 return 0x20000000000000; |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 int min_literal() { | 52 int min_literal() { |
53 var min_literal = -0x1FFFFFFFFFFFFF; | 53 var min_literal = -0x20000000000000; |
54 return min_literal; | 54 return min_literal; |
55 } | 55 } |
56 | 56 |
57 // We don't test for the _JavascriptIntegerOverflowError since it's not visible. | 57 // 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. | 58 // It should not be visible since it doesn't exist on dart2js. |
59 bool isJavascriptIntError(e) => | 59 bool isJavascriptIntError(e) => |
60 e is Error && "$e".startsWith("Javascript Integer Overflow:"); | 60 e is Error && "$e".startsWith("Javascript Integer Overflow:"); |
61 | 61 |
62 main() { | 62 main() { |
63 Expect.equals(0x1FFFFFFFFFFFFF, max_literal()); | 63 Expect.equals(0x20000000000000, max_literal()); |
64 Expect.equals(-0x1FFFFFFFFFFFFF, min_literal()); | 64 Expect.equals(-0x20000000000000, min_literal()); |
65 | 65 |
66 // Run the tests once before optimizations. | 66 // Run the tests once before optimizations. |
67 dti_arg = 1.9e16; | 67 dti_arg = 1.9e17; |
68 Expect.throws(double_to_int, isJavascriptIntError); | 68 Expect.throws(double_to_int, isJavascriptIntError); |
69 | 69 |
70 ia_arg1 = (1 << 52); | 70 ia_arg1 = (1 << 53); |
71 ia_arg2 = (1 << 52); | 71 ia_arg2 = (1 << 53); |
72 Expect.throws(integer_add, isJavascriptIntError); | 72 Expect.throws(integer_add, isJavascriptIntError); |
73 | 73 |
74 n_arg = -0x1FFFFFFFFFFFFF; | 74 n_arg = -0x20000000000000; |
75 Expect.equals(0x1FFFFFFFFFFFFF, negate()); | 75 Expect.equals(0x20000000000000, negate()); |
76 | 76 |
77 is_arg = (1 << 52); | 77 is_arg = (1 << 53); |
78 Expect.throws(integer_shift, isJavascriptIntError); | 78 Expect.throws(integer_shift, isJavascriptIntError); |
79 | 79 |
80 Expect.throws(max_add_throws, isJavascriptIntError); | 80 Expect.throws(max_add_throws, isJavascriptIntError); |
81 Expect.throws(min_sub_throws, isJavascriptIntError); | 81 Expect.throws(min_sub_throws, isJavascriptIntError); |
82 | 82 |
83 for (int i = 0; i < 20; i++) { | 83 for (int i = 0; i < 20; i++) { |
84 dti_arg = i.toDouble(); | 84 dti_arg = i.toDouble(); |
85 // Expect.throws calls through the closure, so we have to here, too. | 85 // Expect.throws calls through the closure, so we have to here, too. |
86 var f = double_to_int; | 86 var f = double_to_int; |
87 Expect.equals(i, f()); | 87 Expect.equals(i, f()); |
88 | 88 |
89 ia_arg1 = i; | 89 ia_arg1 = i; |
90 ia_arg2 = i; | 90 ia_arg2 = i; |
91 f = integer_add; | 91 f = integer_add; |
92 Expect.equals(i + i, f()); | 92 Expect.equals(i + i, f()); |
93 | 93 |
94 n_arg = i; | 94 n_arg = i; |
95 f = negate; | 95 f = negate; |
96 Expect.equals(-i, f()); | 96 Expect.equals(-i, f()); |
97 | 97 |
98 is_arg = i; | 98 is_arg = i; |
99 f = integer_shift; | 99 f = integer_shift; |
100 Expect.equals(i << 1, f()); | 100 Expect.equals(i << 1, f()); |
101 } | 101 } |
102 | 102 |
103 // The optimized functions should now deoptimize and throw the error. | 103 // The optimized functions should now deoptimize and throw the error. |
104 dti_arg = 1.9e16; | 104 dti_arg = 1.9e17; |
105 Expect.throws(double_to_int, isJavascriptIntError); | 105 Expect.throws(double_to_int, isJavascriptIntError); |
106 | 106 |
107 ia_arg1 = (1 << 52); | 107 ia_arg1 = (1 << 53); |
108 ia_arg2 = (1 << 52); | 108 ia_arg2 = (1 << 53); |
109 Expect.throws(integer_add, isJavascriptIntError); | 109 Expect.throws(integer_add, isJavascriptIntError); |
110 | 110 |
111 n_arg = -0x1FFFFFFFFFFFFF; | 111 n_arg = -0x20000000000000; |
112 Expect.equals(0x1FFFFFFFFFFFFF, negate()); | 112 Expect.equals(0x20000000000000, negate()); |
113 | 113 |
114 is_arg = (1 << 52); | 114 is_arg = (1 << 53); |
115 Expect.throws(integer_shift, isJavascriptIntError); | 115 Expect.throws(integer_shift, isJavascriptIntError); |
116 | 116 |
117 Expect.throws(max_add_throws, isJavascriptIntError); | 117 Expect.throws(max_add_throws, isJavascriptIntError); |
118 Expect.throws(min_sub_throws, isJavascriptIntError); | 118 Expect.throws(min_sub_throws, isJavascriptIntError); |
119 } | 119 } |
OLD | NEW |