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

Side by Side Diff: tests/standalone/53bit_overflow_test.dart

Issue 17361004: Move FiftythreeBitOverflowError to VM-only patch file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adding rationale to error test. Created 7 years, 6 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
« no previous file with comments | « sdk/lib/core/errors.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 int max_literal() { 47 int max_literal() {
48 return 0xFFFFFFFFFFFFF; 48 return 0xFFFFFFFFFFFFF;
49 } 49 }
50 50
51 51
52 int min_literal() { 52 int min_literal() {
53 var min_literal = -0xFFFFFFFFFFFFF - 1; 53 var min_literal = -0xFFFFFFFFFFFFF - 1;
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.
58 // It's should not be visible since it doesn't exist on dart2js.
59 bool is53BitError(e) => e is Error && "$e".startsWith("53-bit Overflow:");
57 60
58 main() { 61 main() {
59 Expect.equals(0xFFFFFFFFFFFFF, max_literal()); 62 Expect.equals(0xFFFFFFFFFFFFF, max_literal());
60 Expect.equals(-0xFFFFFFFFFFFFF - 1, min_literal()); 63 Expect.equals(-0xFFFFFFFFFFFFF - 1, min_literal());
61 64
62 // Run the tests once before optimizations. 65 // Run the tests once before optimizations.
63 dti_arg = 1.9e16; 66 dti_arg = 1.9e16;
64 Expect.throws(double_to_int, (e) => e is FiftyThreeBitOverflowError); 67 Expect.throws(double_to_int, is53BitError);
65 68
66 ia_arg1 = (1 << 51); 69 ia_arg1 = (1 << 51);
67 ia_arg2 = (1 << 51); 70 ia_arg2 = (1 << 51);
68 Expect.throws(integer_add, (e) => e is FiftyThreeBitOverflowError); 71 Expect.throws(integer_add, is53BitError);
69 72
70 n_arg = -0xFFFFFFFFFFFFF - 1; 73 n_arg = -0xFFFFFFFFFFFFF - 1;
71 Expect.throws(negate, (e) => e is FiftyThreeBitOverflowError); 74 Expect.throws(negate, is53BitError);
72 75
73 is_arg = (1 << 51); 76 is_arg = (1 << 51);
74 Expect.throws(integer_shift, (e) => e is FiftyThreeBitOverflowError); 77 Expect.throws(integer_shift, is53BitError);
75 78
76 Expect.throws(max_add_throws, (e) => e is FiftyThreeBitOverflowError); 79 Expect.throws(max_add_throws, is53BitError);
77 Expect.throws(min_sub_throws, (e) => e is FiftyThreeBitOverflowError); 80 Expect.throws(min_sub_throws, is53BitError);
78 81
79 for (int i = 0; i < 20; i++) { 82 for (int i = 0; i < 20; i++) {
80 dti_arg = i.toDouble(); 83 dti_arg = i.toDouble();
81 // 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.
82 var f = double_to_int; 85 var f = double_to_int;
83 Expect.equals(i, f()); 86 Expect.equals(i, f());
84 87
85 ia_arg1 = i; 88 ia_arg1 = i;
86 ia_arg2 = i; 89 ia_arg2 = i;
87 f = integer_add; 90 f = integer_add;
88 Expect.equals(i + i, f()); 91 Expect.equals(i + i, f());
89 92
90 n_arg = i; 93 n_arg = i;
91 f = negate; 94 f = negate;
92 Expect.equals(-i, f()); 95 Expect.equals(-i, f());
93 96
94 is_arg = i; 97 is_arg = i;
95 f = integer_shift; 98 f = integer_shift;
96 Expect.equals(i << 1, f()); 99 Expect.equals(i << 1, f());
97 } 100 }
98 101
99 // The optimized functions should now deoptimize and throw the error. 102 // The optimized functions should now deoptimize and throw the error.
100 dti_arg = 1.9e16; 103 dti_arg = 1.9e16;
101 Expect.throws(double_to_int, (e) => e is FiftyThreeBitOverflowError); 104 Expect.throws(double_to_int, is53BitError);
102 105
103 ia_arg1 = (1 << 51); 106 ia_arg1 = (1 << 51);
104 ia_arg2 = (1 << 51); 107 ia_arg2 = (1 << 51);
105 Expect.throws(integer_add, (e) => e is FiftyThreeBitOverflowError); 108 Expect.throws(integer_add, is53BitError);
106 109
107 n_arg = -0xFFFFFFFFFFFFF - 1; 110 n_arg = -0xFFFFFFFFFFFFF - 1;
108 Expect.throws(negate, (e) => e is FiftyThreeBitOverflowError); 111 Expect.throws(negate, is53BitError);
109 112
110 is_arg = (1 << 51); 113 is_arg = (1 << 51);
111 Expect.throws(integer_shift, (e) => e is FiftyThreeBitOverflowError); 114 Expect.throws(integer_shift, is53BitError);
112 115
113 Expect.throws(max_add_throws, (e) => e is FiftyThreeBitOverflowError); 116 Expect.throws(max_add_throws, is53BitError);
114 Expect.throws(min_sub_throws, (e) => e is FiftyThreeBitOverflowError); 117 Expect.throws(min_sub_throws, is53BitError);
115 } 118 }
OLDNEW
« no previous file with comments | « sdk/lib/core/errors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698