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

Side by Side Diff: tests/standalone/javascript_compatibility_errors_test.dart

Issue 317793003: Add javascript compatibility warnings for integer values and integral double (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 | « runtime/lib/identical.cc ('k') | tests/standalone/javascript_compatibility_warnings_test.dart » ('j') | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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=--warn_on_javascript_compatibility --warning_as_error --optimizatio n_counter_threshold=5 5 // VMOptions=--warn_on_javascript_compatibility --warning_as_error --optimizatio n_counter_threshold=5
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 8
9 f(x, y) { 9 f(x, y) {
10 // Unoptimized code. 10 // Unoptimized and optimized code.
11 1 is double; /// 00: compile-time error 11 1 is double; /// 00: compile-time error
12 if (1 is double) { x++; } /// 01: compile-time error 12 if (1 is double) { x++; } /// 01: compile-time error
13 try { 1 as double; } on CastError catch (e) { } /// 02: compile-time error 13 try { 1 as double; } on CastError catch (e) { } /// 02: compile-time error
14 try { var y = 1 as double; } on CastError catch (e) { } /// 03: compile-time error 14 try { var y = 1 as double; } on CastError catch (e) { } /// 03: compile-time error
15 1.0 is int; /// 04: compile-time error 15 1.0 is int; /// 04: compile-time error
16 if (1.0 is int) { x++; } /// 05: compile-time error 16 if (1.0 is int) { x++; } /// 05: compile-time error
17 try { 1.0 as int; } on CastError catch (e) { } /// 06: compile-time error 17 try { 1.0 as int; } on CastError catch (e) { } /// 06: compile-time error
18 try { var z = 1.0 as int; } on CastError catch (e) { } /// 07: compile-time e rror 18 try { var z = 1.0 as int; } on CastError catch (e) { } /// 07: compile-time e rror
19 19
20 x is double; /// 10: ok 20 x is double; /// 10: ok
(...skipping 12 matching lines...) Expand all
33 "$y"; /// 24: ok 33 "$y"; /// 24: ok
34 var z = "$y"; /// 25: ok 34 var z = "$y"; /// 25: ok
35 y.toString(); /// 26: ok 35 y.toString(); /// 26: ok
36 var z = y.toString(); /// 27: ok 36 var z = y.toString(); /// 27: ok
37 37
38 var a = "yz"; 38 var a = "yz";
39 var b = "xyz"; 39 var b = "xyz";
40 b = b.substring(1); 40 b = b.substring(1);
41 if (identical(a, b)) { } /// 28: ok 41 if (identical(a, b)) { } /// 28: ok
42 42
43 if (identical(x, y)) { } /// 29: ok
44 if (identical(y, x)) { } /// 30: ok
45
43 if (x > 10) { 46 if (x > 10) {
44 // Optimized code. 47 // Optimized code.
45 x is double; /// 30: ok 48 x is double; /// 40: ok
46 if (x is double) { } /// 31: ok 49 if (x is double) { } /// 41: ok
47 try { x as double; } on CastError catch (e) { } /// 32: ok 50 try { x as double; } on CastError catch (e) { } /// 42: ok
48 try { var z = x as double; } on CastError catch (e) { } /// 33: ok 51 try { var z = x as double; } on CastError catch (e) { } /// 43: ok
49 y is int; /// 34: ok 52 y is int; /// 44: ok
50 if (y is int) { } /// 35: ok 53 if (y is int) { } /// 45: ok
51 try { y as int; } on CastError catch (e) { } /// 36: ok 54 try { y as int; } on CastError catch (e) { } /// 46: ok
52 try { var z = y as int; } on CastError catch (e) { } /// 37: ok 55 try { var z = y as int; } on CastError catch (e) { } /// 47: ok
53 56
54 "${1.0}"; /// 40: compile-time error 57 "${1.0}"; /// 50: compile-time error
55 var z = "${1.0}"; /// 41: compile-time error 58 var z = "${1.0}"; /// 51: compile-time error
56 (1.0).toString(); /// 42: ok 59 (1.0).toString(); /// 52: ok
57 var z = (1.0).toString(); /// 43: ok 60 var z = (1.0).toString(); /// 53: ok
58 "$y"; /// 44: ok 61 "$y"; /// 54: ok
59 var z = "$y"; /// 45: ok 62 var z = "$y"; /// 55: ok
60 y.toString(); /// 46: ok 63 y.toString(); /// 56: ok
61 var z = y.toString(); /// 47: ok 64 var z = y.toString(); /// 57: ok
62 65
63 var a = "yz"; 66 var a = "yz";
64 var b = "xyz"; 67 var b = "xyz";
65 b = b.substring(1); 68 b = b.substring(1);
66 if (identical(a, b)) { } /// 48: ok 69 if (identical(a, b)) { } /// 58: ok
70
71 if (identical(x, y)) { } /// 59: ok
72 if (identical(y, x)) { } /// 60: ok
67 } 73 }
68 } 74 }
69 75
70 k(x, y) { 76 k(x, y) {
71 // Unoptimized code. 77 // Unoptimized and optimized code.
72 1.5 is double; 78 1.5 is double;
73 if (1.5 is double) { x++; } 79 if (1.5 is double) { x++; }
74 try { 1.5 as double; } on CastError catch (e) { } 80 try { 1.5 as double; } on CastError catch (e) { }
75 try { var y = 1.5 as double; } on CastError catch (e) { } 81 try { var y = 1.5 as double; } on CastError catch (e) { }
76 1.5 is int; 82 1.5 is int;
77 if (1.5 is int) { x++; } 83 if (1.5 is int) { x++; }
78 try { 1.5 as int; } on CastError catch (e) { } 84 try { 1.5 as int; } on CastError catch (e) { }
79 try { var z = 1.5 as int; } on CastError catch (e) { } 85 try { var z = 1.5 as int; } on CastError catch (e) { }
80 86
81 1.5 is double; 87 1.5 is double;
(...skipping 16 matching lines...) Expand all
98 104
99 "${1.5}"; 105 "${1.5}";
100 var z = "${1.5}"; 106 var z = "${1.5}";
101 (1.5).toString(); 107 (1.5).toString();
102 z = (1.5).toString(); 108 z = (1.5).toString();
103 "$y"; 109 "$y";
104 z = "$y"; 110 z = "$y";
105 y.toString(); 111 y.toString();
106 z = y.toString(); 112 z = y.toString();
107 113
114 var a = "xyz";
115 var b = "xyz";
116 b = b.substring(1);
117 if (identical(a, b)) { }
118
119 if (identical(x, y)) { }
120 if (identical(y, x)) { }
121
108 if (x > 10) { 122 if (x > 10) {
109 // Optimized code. 123 // Optimized code.
110 x is double; 124 x is double;
111 if (x is double) { } 125 if (x is double) { }
112 try { x as double; } on CastError catch (e) { } 126 try { x as double; } on CastError catch (e) { }
113 try { var z = x as double; } on CastError catch (e) { } 127 try { var z = x as double; } on CastError catch (e) { }
114 y is int; 128 y is int;
115 if (y is int) { } 129 if (y is int) { }
116 try { y as int; } on CastError catch (e) { } 130 try { y as int; } on CastError catch (e) { }
117 try { var z = y as int; } on CastError catch (e) { } 131 try { var z = y as int; } on CastError catch (e) { }
118 132
119 "${1.5}"; 133 "${1.5}";
120 var z = "${1.5}"; 134 var z = "${1.5}";
121 (1.5).toString(); 135 (1.5).toString();
122 z = (1.5).toString(); 136 z = (1.5).toString();
123 "$y"; 137 "$y";
124 z = "$y"; 138 z = "$y";
125 y.toString(); 139 y.toString();
126 z = y.toString(); 140 z = y.toString();
141
142 var a = "xyz";
143 var b = "xyz";
144 b = b.substring(1);
145 if (identical(a, b)) { }
146
147 if (identical(x, y)) { }
148 if (identical(y, x)) { }
127 } 149 }
128 } 150 }
129 151
130 g(x, y) => f(x, y); // Test inlining calls. 152 g(x, y) => f(x, y); // Test inlining calls.
131 h(x, y) => g(x, y); 153 h(x, y) => g(x, y);
132 154
133 // We don't test for _JavascriptCompatibilityError since it's not visible. 155 // We don't test for _JavascriptCompatibilityError since it's not visible.
134 // It should not be visible since it doesn't exist on dart2js. 156 // It should not be visible since it doesn't exist on dart2js.
135 bool isJavascriptCompatibilityError(e) => 157 bool isJavascriptCompatibilityError(e) =>
136 e is Error && "$e".contains("Javascript Compatibility Error"); 158 e is Error && "$e".contains("Javascript Compatibility Error");
137 159
138 main() { 160 main() {
139 // Since the warning (or error in case of --warning_as_error) is issued at 161 // Since the warning (or error in case of --warning_as_error) is issued at
140 // most once per location, the Expect.throw must guard the whole loop. 162 // most once per location, the Expect.throw must guard the whole loop.
141 Expect.throws( 163 Expect.throws(
142 () { 164 () {
143 for (var i = 0; i < 20; i++) { 165 for (var i = 0; i < 20; i++) {
144 h(i, i * 1.0); 166 h(i, i * 1.0);
145 } 167 }
146 }, 168 },
147 isJavascriptCompatibilityError); 169 isJavascriptCompatibilityError);
148 170
149 // No warnings (errors) should be issued after this point. 171 // No warnings (errors) should be issued after this point.
150 for (var i = 0; i < 20; i++) { 172 for (var i = 0; i < 20; i++) {
151 k(i * 1.0, i); 173 k(i * 1.0, i);
152 k(i * 1.0, i + 0.5); 174 k(i * 1.0, i + 0.5);
153 } 175 }
154 } 176 }
155 177
OLDNEW
« no previous file with comments | « runtime/lib/identical.cc ('k') | tests/standalone/javascript_compatibility_warnings_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698