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

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_incompatibility --warning_as_error --optimizat ion_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
srdjan 2014/05/08 18:11:05 Check that "hello" is int does not produce warning
regis 2014/05/09 21:03:42 I added a whole new section verifying that no warn
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 g(x, y) => f(x, y); // Test inlining calls.
61 h(x, y) => g(x, y);
62
63 // We don't test for _JavascriptCompatibilityError since it's not visible.
64 // It should not be visible since it doesn't exist on dart2js.
65 bool isJavascriptCompatibilityError(e) =>
66 e is Error && "$e".contains("javascript incompatibility");
67
68 main() {
69 // Since the warning (or error in case of --warning_as_error) is issued at
70 // most once per location, the Expect.throw must guard the whole loop.
71 Expect.throws(
72 () {
73 for (var i = 0; i < 20; i++) {
74 h(i, i * 1.0);
75 }
76 },
77 isJavascriptCompatibilityError);
78 }
79
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698