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

Side by Side Diff: tests/standalone/javascript_int_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
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
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 _JavascriptIntegerOverflowError 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 isJavascriptIntError(e) =>
60 e is Error && "$e".startsWith("Javascript Integer Overflow:");
60 61
61 main() { 62 main() {
62 Expect.equals(0xFFFFFFFFFFFFF, max_literal()); 63 Expect.equals(0x1FFFFFFFFFFFFF, max_literal());
63 Expect.equals(-0xFFFFFFFFFFFFF - 1, min_literal()); 64 Expect.equals(-0x1FFFFFFFFFFFFF, min_literal());
64 65
65 // Run the tests once before optimizations. 66 // Run the tests once before optimizations.
66 dti_arg = 1.9e16; 67 dti_arg = 1.9e16;
67 Expect.throws(double_to_int, is53BitError); 68 Expect.throws(double_to_int, isJavascriptIntError);
68 69
69 ia_arg1 = (1 << 51); 70 ia_arg1 = (1 << 52);
70 ia_arg2 = (1 << 51); 71 ia_arg2 = (1 << 52);
71 Expect.throws(integer_add, is53BitError); 72 Expect.throws(integer_add, isJavascriptIntError);
72 73
73 n_arg = -0xFFFFFFFFFFFFF - 1; 74 n_arg = -0x1FFFFFFFFFFFFF;
74 Expect.throws(negate, is53BitError); 75 Expect.equals(0x1FFFFFFFFFFFFF, negate());
75 76
76 is_arg = (1 << 51); 77 is_arg = (1 << 52);
77 Expect.throws(integer_shift, is53BitError); 78 Expect.throws(integer_shift, isJavascriptIntError);
78 79
79 Expect.throws(max_add_throws, is53BitError); 80 Expect.throws(max_add_throws, isJavascriptIntError);
80 Expect.throws(min_sub_throws, is53BitError); 81 Expect.throws(min_sub_throws, isJavascriptIntError);
81 82
82 for (int i = 0; i < 20; i++) { 83 for (int i = 0; i < 20; i++) {
83 dti_arg = i.toDouble(); 84 dti_arg = i.toDouble();
84 // 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.
85 var f = double_to_int; 86 var f = double_to_int;
86 Expect.equals(i, f()); 87 Expect.equals(i, f());
87 88
88 ia_arg1 = i; 89 ia_arg1 = i;
89 ia_arg2 = i; 90 ia_arg2 = i;
90 f = integer_add; 91 f = integer_add;
91 Expect.equals(i + i, f()); 92 Expect.equals(i + i, f());
92 93
93 n_arg = i; 94 n_arg = i;
94 f = negate; 95 f = negate;
95 Expect.equals(-i, f()); 96 Expect.equals(-i, f());
96 97
97 is_arg = i; 98 is_arg = i;
98 f = integer_shift; 99 f = integer_shift;
99 Expect.equals(i << 1, f()); 100 Expect.equals(i << 1, f());
100 } 101 }
101 102
102 // The optimized functions should now deoptimize and throw the error. 103 // The optimized functions should now deoptimize and throw the error.
103 dti_arg = 1.9e16; 104 dti_arg = 1.9e16;
104 Expect.throws(double_to_int, is53BitError); 105 Expect.throws(double_to_int, isJavascriptIntError);
105 106
106 ia_arg1 = (1 << 51); 107 ia_arg1 = (1 << 52);
107 ia_arg2 = (1 << 51); 108 ia_arg2 = (1 << 52);
108 Expect.throws(integer_add, is53BitError); 109 Expect.throws(integer_add, isJavascriptIntError);
109 110
110 n_arg = -0xFFFFFFFFFFFFF - 1; 111 n_arg = -0x1FFFFFFFFFFFFF;
111 Expect.throws(negate, is53BitError); 112 Expect.equals(0x1FFFFFFFFFFFFF, negate());
112 113
113 is_arg = (1 << 51); 114 is_arg = (1 << 52);
114 Expect.throws(integer_shift, is53BitError); 115 Expect.throws(integer_shift, isJavascriptIntError);
115 116
116 Expect.throws(max_add_throws, is53BitError); 117 Expect.throws(max_add_throws, isJavascriptIntError);
117 Expect.throws(min_sub_throws, is53BitError); 118 Expect.throws(min_sub_throws, isJavascriptIntError);
118 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698