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

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

Issue 21301003: Fixes javascript integer overflow check. (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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // VMOptions=--throw_on_javascript_int_overflow --optimization_counter_threshold =10
6
7
8 import "package:expect/expect.dart";
9 import 'dart:typed_data';
10
11
12 double dti_arg;
13 int double_to_int() {
14 return dti_arg.toInt();
15 }
16
17
18 int ia_arg1;
19 int ia_arg2;
20 int integer_add() {
21 return ia_arg1 + ia_arg2;
22 }
23
24
25 int is_arg;
26 int integer_shift() {
27 return is_arg << 1;
28 }
29
30
31 int max_add_throws() {
32 return 0xFFFFFFFFFFFFF + 1;
33 }
34
35
36 int min_sub_throws() {
37 return -0xFFFFFFFFFFFFF - 2;
38 }
39
40
41 int n_arg;
42 int negate() {
43 return -n_arg;
44 }
45
46
47 int max_literal() {
48 return 0xFFFFFFFFFFFFF;
49 }
50
51
52 int min_literal() {
53 var min_literal = -0xFFFFFFFFFFFFF - 1;
54 return min_literal;
55 }
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:");
60
61 main() {
62 Expect.equals(0xFFFFFFFFFFFFF, max_literal());
63 Expect.equals(-0xFFFFFFFFFFFFF - 1, min_literal());
64
65 // Run the tests once before optimizations.
66 dti_arg = 1.9e16;
67 Expect.throws(double_to_int, is53BitError);
68
69 ia_arg1 = (1 << 51);
70 ia_arg2 = (1 << 51);
71 Expect.throws(integer_add, is53BitError);
72
73 n_arg = -0xFFFFFFFFFFFFF - 1;
74 Expect.throws(negate, is53BitError);
75
76 is_arg = (1 << 51);
77 Expect.throws(integer_shift, is53BitError);
78
79 Expect.throws(max_add_throws, is53BitError);
80 Expect.throws(min_sub_throws, is53BitError);
81
82 for (int i = 0; i < 20; i++) {
83 dti_arg = i.toDouble();
84 // Expect.throws calls through the closure, so we have to here, too.
85 var f = double_to_int;
86 Expect.equals(i, f());
87
88 ia_arg1 = i;
89 ia_arg2 = i;
90 f = integer_add;
91 Expect.equals(i + i, f());
92
93 n_arg = i;
94 f = negate;
95 Expect.equals(-i, f());
96
97 is_arg = i;
98 f = integer_shift;
99 Expect.equals(i << 1, f());
100 }
101
102 // The optimized functions should now deoptimize and throw the error.
103 dti_arg = 1.9e16;
104 Expect.throws(double_to_int, is53BitError);
105
106 ia_arg1 = (1 << 51);
107 ia_arg2 = (1 << 51);
108 Expect.throws(integer_add, is53BitError);
109
110 n_arg = -0xFFFFFFFFFFFFF - 1;
111 Expect.throws(negate, is53BitError);
112
113 is_arg = (1 << 51);
114 Expect.throws(integer_shift, is53BitError);
115
116 Expect.throws(max_add_throws, is53BitError);
117 Expect.throws(min_sub_throws, is53BitError);
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698