| OLD | NEW |
| (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 and optimized code. | |
| 11 1 is double; /// 00: ok | |
| 12 if (1 is double) { x++; } /// 01: ok | |
| 13 try { 1 as double; } on CastError catch (e) { } /// 02: ok | |
| 14 try { var y = 1 as double; } on CastError catch (e) { } /// 03: ok | |
| 15 1.0 is int; /// 04: ok | |
| 16 if (1.0 is int) { x++; } /// 05: ok | |
| 17 try { 1.0 as int; } on CastError catch (e) { } /// 06: ok | |
| 18 try { var z = 1.0 as int; } on CastError catch (e) { } /// 07: ok | |
| 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 // It is a compile-time error if evaluation of a constant object results in | |
| 30 // an uncaught exception being thrown, a JavascriptCompatibilityError here. | |
| 31 "${1.0}"; /// 20: compile-time error | |
| 32 var z = "${1.0}"; /// 21: compile-time error | |
| 33 | |
| 34 (1.0).toString(); /// 22: ok | |
| 35 var z = (1.0).toString(); /// 23: ok | |
| 36 "$y"; /// 24: ok | |
| 37 var z = "$y"; /// 25: ok | |
| 38 y.toString(); /// 26: ok | |
| 39 var z = y.toString(); /// 27: ok | |
| 40 | |
| 41 var a = "yz"; | |
| 42 var b = "xyz"; | |
| 43 b = b.substring(1); | |
| 44 if (identical(a, b)) { } /// 28: ok | |
| 45 | |
| 46 if (identical(x, y)) { } /// 29: ok | |
| 47 if (identical(y, x)) { } /// 30: ok | |
| 48 | |
| 49 if (x > 10) { | |
| 50 // Optimized code. | |
| 51 x is double; /// 40: ok | |
| 52 if (x is double) { } /// 41: ok | |
| 53 try { x as double; } on CastError catch (e) { } /// 42: ok | |
| 54 try { var z = x as double; } on CastError catch (e) { } /// 43: ok | |
| 55 y is int; /// 44: ok | |
| 56 if (y is int) { } /// 45: ok | |
| 57 try { y as int; } on CastError catch (e) { } /// 46: ok | |
| 58 try { var z = y as int; } on CastError catch (e) { } /// 47: ok | |
| 59 | |
| 60 "${1.0}"; /// 50: compile-time error | |
| 61 var z = "${1.0}"; /// 51: compile-time error | |
| 62 | |
| 63 (1.0).toString(); /// 52: ok | |
| 64 var z = (1.0).toString(); /// 53: ok | |
| 65 "$y"; /// 54: ok | |
| 66 var z = "$y"; /// 55: ok | |
| 67 y.toString(); /// 56: ok | |
| 68 var z = y.toString(); /// 57: ok | |
| 69 | |
| 70 var a = "yz"; | |
| 71 var b = "xyz"; | |
| 72 b = b.substring(1); | |
| 73 if (identical(a, b)) { } /// 58: ok | |
| 74 | |
| 75 if (identical(x, y)) { } /// 59: ok | |
| 76 if (identical(y, x)) { } /// 60: ok | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 k(x, y) { | |
| 81 // Unoptimized and optimized code. | |
| 82 1.5 is double; | |
| 83 if (1.5 is double) { x++; } | |
| 84 try { 1.5 as double; } on CastError catch (e) { } | |
| 85 try { var y = 1.5 as double; } on CastError catch (e) { } | |
| 86 1.5 is int; | |
| 87 if (1.5 is int) { x++; } | |
| 88 try { 1.5 as int; } on CastError catch (e) { } | |
| 89 try { var z = 1.5 as int; } on CastError catch (e) { } | |
| 90 | |
| 91 1.5 is double; | |
| 92 if (1.5 is double) { x++; } | |
| 93 try { 1.5 as double; } on CastError catch (e) { } | |
| 94 try { var y = 1.5 as double; } on CastError catch (e) { } | |
| 95 1.5 is int; | |
| 96 if (1.5 is int) { x++; } | |
| 97 try { 1.5 as int; } on CastError catch (e) { } | |
| 98 try { var z = 1.5 as int; } on CastError catch (e) { } | |
| 99 | |
| 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 var a = "xyz"; | |
| 119 var b = "xyz"; | |
| 120 b = b.substring(1); | |
| 121 if (identical(a, b)) { } | |
| 122 | |
| 123 if (identical(x, y)) { } | |
| 124 if (identical(y, x)) { } | |
| 125 | |
| 126 if (x > 10) { | |
| 127 // Optimized code. | |
| 128 x is double; | |
| 129 if (x is double) { } | |
| 130 try { x as double; } on CastError catch (e) { } | |
| 131 try { var z = x as double; } on CastError catch (e) { } | |
| 132 y is int; | |
| 133 if (y is int) { } | |
| 134 try { y as int; } on CastError catch (e) { } | |
| 135 try { var z = y as int; } on CastError catch (e) { } | |
| 136 | |
| 137 "${1.5}"; | |
| 138 var z = "${1.5}"; | |
| 139 (1.5).toString(); | |
| 140 z = (1.5).toString(); | |
| 141 "$y"; | |
| 142 z = "$y"; | |
| 143 y.toString(); | |
| 144 z = y.toString(); | |
| 145 | |
| 146 var a = "xyz"; | |
| 147 var b = "xyz"; | |
| 148 b = b.substring(1); | |
| 149 if (identical(a, b)) { } | |
| 150 | |
| 151 if (identical(x, y)) { } | |
| 152 if (identical(y, x)) { } | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 g(x, y) => f(x, y); // Test inlining calls. | |
| 157 h(x, y) => g(x, y); | |
| 158 | |
| 159 // We don't test for _JavascriptCompatibilityError since it's not visible. | |
| 160 // It should not be visible since it doesn't exist on dart2js. | |
| 161 bool isJavascriptCompatibilityError(e) => | |
| 162 e is Error && "$e".contains("Javascript Compatibility Error"); | |
| 163 | |
| 164 main() { | |
| 165 // The warning (or error in case of --warning_as_error) is issued at | |
| 166 // most once per location. | |
| 167 var numWarnings = 0; | |
| 168 for (var i = 0; i < 20; i++) { | |
| 169 try { | |
| 170 h(i, i * 1.0); | |
| 171 } catch(e) { | |
| 172 Expect.isTrue(isJavascriptCompatibilityError(e)); | |
| 173 numWarnings++; | |
| 174 } | |
| 175 } | |
| 176 Expect.equals(1, numWarnings); | |
| 177 // No warnings (errors) should be issued after this point. | |
| 178 for (var i = 0; i < 20; i++) { | |
| 179 k(i * 1.0, i); | |
| 180 k(i * 1.0, i + 0.5); | |
| 181 } | |
| 182 } | |
| 183 | |
| OLD | NEW |