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

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

Issue 260713008: Add support for javascript incompatibility warnings. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // VMOptions=--warn_on_javascript_compatibility --warning_as_error --optimizatio n_counter_threshold=5
6
7 import "package:expect/expect.dart";
8
9 f(x, y) {
10 // Unoptimized code.
11 1 is double; /// 00: 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
14 try { var y = 1 as double; } on CastError catch (e) { } /// 03: compile-time error
15 1.0 is int; /// 04: 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
18 try { var z = 1.0 as int; } on CastError catch (e) { } /// 07: compile-time e rror
19
20 x is double; /// 10: ok
21 if (x is double) { } /// 11: ok
22 try { x as double; } on CastError catch (e) { } /// 12: ok
23 try { var z = x as double; } on CastError catch (e) { } /// 13: ok
24 y is int; /// 14: ok
25 if (y is int) { } /// 15: ok
26 try { y as int; } on CastError catch (e) { } /// 16: ok
27 try { var z = y as int; } on CastError catch (e) { } /// 17: ok
28
29 "${1.0}"; /// 20: compile-time error
30 var z = "${1.0}"; /// 21: compile-time error
31 (1.0).toString(); /// 22: ok
32 var z = (1.0).toString(); /// 23: ok
33 "$y"; /// 24: ok
34 var z = "$y"; /// 25: ok
35 y.toString(); /// 26: ok
36 var z = y.toString(); /// 27: ok
37
38 if (x > 10) {
39 // Optimized code.
40 x is double; /// 30: ok
41 if (x is double) { } /// 31: ok
42 try { x as double; } on CastError catch (e) { } /// 32: ok
43 try { var z = x as double; } on CastError catch (e) { } /// 33: ok
44 y is int; /// 34: ok
45 if (y is int) { } /// 35: ok
46 try { y as int; } on CastError catch (e) { } /// 36: ok
47 try { var z = y as int; } on CastError catch (e) { } /// 37: ok
48
49 "${1.0}"; /// 40: compile-time error
50 var z = "${1.0}"; /// 41: compile-time error
51 (1.0).toString(); /// 42: ok
52 var z = (1.0).toString(); /// 43: ok
53 "$y"; /// 44: ok
54 var z = "$y"; /// 45: ok
55 y.toString(); /// 46: ok
56 var z = y.toString(); /// 47: ok
57 }
58 }
59
60 k(x, y) {
61 // Unoptimized code.
62 1.5 is double;
63 if (1.5 is double) { x++; }
64 try { 1.5 as double; } on CastError catch (e) { }
65 try { var y = 1.5 as double; } on CastError catch (e) { }
66 1.5 is int;
67 if (1.5 is int) { x++; }
68 try { 1.5 as int; } on CastError catch (e) { }
69 try { var z = 1.5 as int; } on CastError catch (e) { }
70
71 1.5 is double;
72 if (1.5 is double) { x++; }
73 try { 1.5 as double; } on CastError catch (e) { }
74 try { var y = 1.5 as double; } on CastError catch (e) { }
75 1.5 is int;
76 if (1.5 is int) { x++; }
77 try { 1.5 as int; } on CastError catch (e) { }
78 try { var z = 1.5 as int; } on CastError catch (e) { }
79
80 x is double;
81 if (x is double) { }
82 try { x as double; } on CastError catch (e) { }
83 try { var z = x as double; } on CastError catch (e) { }
84 y is int;
85 if (y is int) { }
86 try { y as int; } on CastError catch (e) { }
87 try { var z = y as int; } on CastError catch (e) { }
88
89 "${1.5}";
90 var z = "${1.5}";
91 (1.5).toString();
92 z = (1.5).toString();
93 "$y";
94 z = "$y";
95 y.toString();
96 z = y.toString();
97
98 if (x > 10) {
99 // Optimized code.
100 x is double;
101 if (x is double) { }
102 try { x as double; } on CastError catch (e) { }
103 try { var z = x as double; } on CastError catch (e) { }
104 y is int;
105 if (y is int) { }
106 try { y as int; } on CastError catch (e) { }
107 try { var z = y as int; } on CastError catch (e) { }
108
109 "${1.5}";
110 var z = "${1.5}";
111 (1.5).toString();
112 z = (1.5).toString();
113 "$y";
114 z = "$y";
115 y.toString();
116 z = y.toString();
117 }
118 }
119
120 g(x, y) => f(x, y); // Test inlining calls.
121 h(x, y) => g(x, y);
122
123 // We don't test for _JavascriptCompatibilityError since it's not visible.
124 // It should not be visible since it doesn't exist on dart2js.
125 bool isJavascriptCompatibilityError(e) =>
126 e is Error && "$e".contains("Javascript Compatibility Error");
127
128 main() {
129 // Since the warning (or error in case of --warning_as_error) is issued at
130 // most once per location, the Expect.throw must guard the whole loop.
131 Expect.throws(
132 () {
133 for (var i = 0; i < 20; i++) {
134 h(i, i * 1.0);
135 }
136 },
137 isJavascriptCompatibilityError);
138
139 // No warnings (errors) should be issued after this point.
140 for (var i = 0; i < 20; i++) {
141 k(i * 1.0, i);
142 k(i * 1.0, i + 0.5);
143 }
144 }
145
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698