| OLD | NEW |
| 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 // VMOptions=--optimization-counter-threshold=10 --no-background-compilation | 4 // VMOptions=--optimization-counter-threshold=10 --no-background-compilation |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 maythrow(x) { | 8 maythrow(x) { |
| 9 if (x == null) throw 42; | 9 if (x == null) throw 42; |
| 10 return 99; | 10 return 99; |
| 11 } | 11 } |
| 12 | 12 |
| 13 | |
| 14 f1(x) { | 13 f1(x) { |
| 15 var result = 123; | 14 var result = 123; |
| 16 try { | 15 try { |
| 17 result = maythrow(x); | 16 result = maythrow(x); |
| 18 if (result > 100) throw 42; | 17 if (result > 100) throw 42; |
| 19 } catch(e) { | 18 } catch (e) { |
| 20 Expect.equals(result, 123); | 19 Expect.equals(result, 123); |
| 21 Expect.equals(42, e); | 20 Expect.equals(42, e); |
| 22 result = 0; | 21 result = 0; |
| 23 } | 22 } |
| 24 return result; | 23 return result; |
| 25 } | 24 } |
| 26 | 25 |
| 27 | |
| 28 class A { | 26 class A { |
| 29 maythrow(x) { | 27 maythrow(x) { |
| 30 if (x == null) throw 42; | 28 if (x == null) throw 42; |
| 31 return 99; | 29 return 99; |
| 32 } | 30 } |
| 33 } | 31 } |
| 34 | 32 |
| 35 | |
| 36 f2(x) { | 33 f2(x) { |
| 37 var result = 123; | 34 var result = 123; |
| 38 var a = new A(); | 35 var a = new A(); |
| 39 try { | 36 try { |
| 40 result++; | 37 result++; |
| 41 result = a.maythrow(x); | 38 result = a.maythrow(x); |
| 42 } catch(e) { | 39 } catch (e) { |
| 43 Expect.equals(124, result); | 40 Expect.equals(124, result); |
| 44 result = x; | 41 result = x; |
| 45 } | 42 } |
| 46 return result; | 43 return result; |
| 47 } | 44 } |
| 48 | 45 |
| 49 | |
| 50 f3(x, y) { | 46 f3(x, y) { |
| 51 var result = 123; | 47 var result = 123; |
| 52 var a = new A(); | 48 var a = new A(); |
| 53 try { | 49 try { |
| 54 result++; | 50 result++; |
| 55 result = a.maythrow(x); | 51 result = a.maythrow(x); |
| 56 } catch(e) { | 52 } catch (e) { |
| 57 result = y + 1; // Deopt on overflow | 53 result = y + 1; // Deopt on overflow |
| 58 } | 54 } |
| 59 return result; | 55 return result; |
| 60 } | 56 } |
| 61 | 57 |
| 62 | |
| 63 f4(x) { | 58 f4(x) { |
| 64 try { | 59 try { |
| 65 maythrow(x); | 60 maythrow(x); |
| 66 } catch(e) { | 61 } catch (e) { |
| 67 check_f4(e, "abc"); | 62 check_f4(e, "abc"); |
| 68 } | 63 } |
| 69 } | 64 } |
| 70 | 65 |
| 71 check_f4(e, s) { | 66 check_f4(e, s) { |
| 72 if (e != 42) throw "ERROR"; | 67 if (e != 42) throw "ERROR"; |
| 73 if (s != "abc") throw "ERROR"; | 68 if (s != "abc") throw "ERROR"; |
| 74 } | 69 } |
| 75 | 70 |
| 76 | |
| 77 f5(x) { | 71 f5(x) { |
| 78 try { | 72 try { |
| 79 maythrow(x); | 73 maythrow(x); |
| 80 } catch(e) { | 74 } catch (e) { |
| 81 check_f5(e, "abc"); | 75 check_f5(e, "abc"); |
| 82 } | 76 } |
| 83 | 77 |
| 84 try { | 78 try { |
| 85 maythrow(x); | 79 maythrow(x); |
| 86 } catch(e) { | 80 } catch (e) { |
| 87 check_f5(e, "abc"); | 81 check_f5(e, "abc"); |
| 88 } | 82 } |
| 89 } | 83 } |
| 90 | 84 |
| 91 check_f5(e, s) { | 85 check_f5(e, s) { |
| 92 if (e != 42) throw "ERROR"; | 86 if (e != 42) throw "ERROR"; |
| 93 if (s != "abc") throw "ERROR"; | 87 if (s != "abc") throw "ERROR"; |
| 94 } | 88 } |
| 95 | 89 |
| 96 | |
| 97 f6(x, y) { | 90 f6(x, y) { |
| 98 var a = x; | 91 var a = x; |
| 99 var b = y; | 92 var b = y; |
| 100 var c = 123; | 93 var c = 123; |
| 101 check_f6(42, null, 1, 123, null, 1); | 94 check_f6(42, null, 1, 123, null, 1); |
| 102 try { | 95 try { |
| 103 maythrow(x); | 96 maythrow(x); |
| 104 } catch(e) { | 97 } catch (e) { |
| 105 check_f6(e, a, b, c, x, y); | 98 check_f6(e, a, b, c, x, y); |
| 106 } | 99 } |
| 107 } | 100 } |
| 108 | 101 |
| 109 check_f6(e, a, b, c, x, y) { | 102 check_f6(e, a, b, c, x, y) { |
| 110 if (e != 42) throw "ERROR"; | 103 if (e != 42) throw "ERROR"; |
| 111 if (a != null) throw "ERROR"; | 104 if (a != null) throw "ERROR"; |
| 112 if (b != 1) throw "ERROR"; | 105 if (b != 1) throw "ERROR"; |
| 113 if (c != 123) throw "ERROR"; | 106 if (c != 123) throw "ERROR"; |
| 114 if (x != null) throw "ERROR"; | 107 if (x != null) throw "ERROR"; |
| 115 if (y != 1) throw "ERROR"; | 108 if (y != 1) throw "ERROR"; |
| 116 } | 109 } |
| 117 | 110 |
| 118 | |
| 119 bool f7(String str) { | 111 bool f7(String str) { |
| 120 double d = double.parse(str); | 112 double d = double.parse(str); |
| 121 var t = d; | 113 var t = d; |
| 122 try { | 114 try { |
| 123 var a = d.toInt(); | 115 var a = d.toInt(); |
| 124 return false; | 116 return false; |
| 125 } on UnsupportedError catch (e) { | 117 } on UnsupportedError catch (e) { |
| 126 Expect.equals(true, identical(t, d)); | 118 Expect.equals(true, identical(t, d)); |
| 127 return true; | 119 return true; |
| 128 } | 120 } |
| 129 } | 121 } |
| 130 | 122 |
| 131 | |
| 132 f8(x, [a = 3, b = 4]) { | 123 f8(x, [a = 3, b = 4]) { |
| 133 var c = 123; | 124 var c = 123; |
| 134 var y = a; | 125 var y = a; |
| 135 try { | 126 try { |
| 136 maythrow(x); | 127 maythrow(x); |
| 137 } catch(e, s) { | 128 } catch (e, s) { |
| 138 check_f8(e, s, a, b, c, x, y); | 129 check_f8(e, s, a, b, c, x, y); |
| 139 } | 130 } |
| 140 } | 131 } |
| 141 | 132 |
| 142 check_f8(e, s, a, b, c, x, y) { | 133 check_f8(e, s, a, b, c, x, y) { |
| 143 if (e != 42) throw "ERROR"; | 134 if (e != 42) throw "ERROR"; |
| 144 if (s is! StackTrace) throw "ERROR"; | 135 if (s is! StackTrace) throw "ERROR"; |
| 145 if (a != 3) { print(a); throw "ERROR"; } | 136 if (a != 3) { |
| 137 print(a); |
| 138 throw "ERROR"; |
| 139 } |
| 146 if (b != 4) throw "ERROR"; | 140 if (b != 4) throw "ERROR"; |
| 147 if (c != 123) throw "ERROR"; | 141 if (c != 123) throw "ERROR"; |
| 148 if (x != null) throw "ERROR"; | 142 if (x != null) throw "ERROR"; |
| 149 if (y != a) throw "ERROR"; | 143 if (y != a) throw "ERROR"; |
| 150 } | 144 } |
| 151 | 145 |
| 152 | |
| 153 f9(x, [a = 3, b = 4]) { | 146 f9(x, [a = 3, b = 4]) { |
| 154 var c = 123; | 147 var c = 123; |
| 155 var y = a; | 148 var y = a; |
| 156 try { | 149 try { |
| 157 if (x < a) maythrow(null); | 150 if (x < a) maythrow(null); |
| 158 maythrow(x); | 151 maythrow(x); |
| 159 } catch(e, s) { | 152 } catch (e, s) { |
| 160 check_f9(e, s, a, b, c, x, y); | 153 check_f9(e, s, a, b, c, x, y); |
| 161 } | 154 } |
| 162 } | 155 } |
| 163 | 156 |
| 164 | |
| 165 check_f9(e, s, a, b, c, x, y) { | 157 check_f9(e, s, a, b, c, x, y) { |
| 166 if (e != 42) throw "ERROR"; | 158 if (e != 42) throw "ERROR"; |
| 167 if (s is! StackTrace) throw "ERROR"; | 159 if (s is! StackTrace) throw "ERROR"; |
| 168 if (a != 3) { print(a); throw "ERROR"; } | 160 if (a != 3) { |
| 161 print(a); |
| 162 throw "ERROR"; |
| 163 } |
| 169 if (b != 4) throw "ERROR"; | 164 if (b != 4) throw "ERROR"; |
| 170 if (c != 123) throw "ERROR"; | 165 if (c != 123) throw "ERROR"; |
| 171 if (x != null) throw "ERROR"; | 166 if (x != null) throw "ERROR"; |
| 172 if (y != a) throw "ERROR"; | 167 if (y != a) throw "ERROR"; |
| 173 } | 168 } |
| 174 | 169 |
| 175 | |
| 176 f10(x, y) { | 170 f10(x, y) { |
| 177 var result = 123; | 171 var result = 123; |
| 178 try { | 172 try { |
| 179 result = maythrow(x); | 173 result = maythrow(x); |
| 180 } catch(e) { | 174 } catch (e) { |
| 181 Expect.equals(123, result); | 175 Expect.equals(123, result); |
| 182 Expect.equals(0.5, y / 2.0); | 176 Expect.equals(0.5, y / 2.0); |
| 183 result = 0; | 177 result = 0; |
| 184 } | 178 } |
| 185 return result; | 179 return result; |
| 186 } | 180 } |
| 187 | 181 |
| 188 | |
| 189 f11(x) { | 182 f11(x) { |
| 190 var result = 123; | 183 var result = 123; |
| 191 var tmp = x; | 184 var tmp = x; |
| 192 try { | 185 try { |
| 193 result = maythrow(x); | 186 result = maythrow(x); |
| 194 if (result > 100) throw 42; | 187 if (result > 100) throw 42; |
| 195 } catch(e, s) { | 188 } catch (e, s) { |
| 196 Expect.equals(123, result); | 189 Expect.equals(123, result); |
| 197 Expect.equals(true, identical(tmp, x)); | 190 Expect.equals(true, identical(tmp, x)); |
| 198 Expect.equals(true, s is StackTrace); | 191 Expect.equals(true, s is StackTrace); |
| 199 result = 0; | 192 result = 0; |
| 200 } | 193 } |
| 201 return result; | 194 return result; |
| 202 } | 195 } |
| 203 | 196 |
| 204 | |
| 205 f12([x = null]) { | 197 f12([x = null]) { |
| 206 try { | 198 try { |
| 207 maythrow(x); | 199 maythrow(x); |
| 208 } catch(e) { | 200 } catch (e) { |
| 209 check_f12(e, x); | 201 check_f12(e, x); |
| 210 } | 202 } |
| 211 } | 203 } |
| 212 | 204 |
| 213 check_f12(e, x) { | 205 check_f12(e, x) { |
| 214 if (e != 42) throw "ERROR"; | 206 if (e != 42) throw "ERROR"; |
| 215 if (x != null) throw "ERROR"; | 207 if (x != null) throw "ERROR"; |
| 216 } | 208 } |
| 217 | 209 |
| 218 | |
| 219 f13(x) { | 210 f13(x) { |
| 220 var result = 123; | 211 var result = 123; |
| 221 try { | 212 try { |
| 222 try { | 213 try { |
| 223 result = maythrow(x); | 214 result = maythrow(x); |
| 224 if (result > 100) throw 42; | 215 if (result > 100) throw 42; |
| 225 } catch(e) { | 216 } catch (e) { |
| 226 Expect.equals(123, result); | 217 Expect.equals(123, result); |
| 227 result = 0; | 218 result = 0; |
| 228 } | 219 } |
| 229 maythrow(x); | 220 maythrow(x); |
| 230 } catch(e) { | 221 } catch (e) { |
| 231 result++; | 222 result++; |
| 232 } | 223 } |
| 233 return result; | 224 return result; |
| 234 } | 225 } |
| 235 | 226 |
| 236 | |
| 237 main() { | 227 main() { |
| 238 for (var i = 0; i < 20; i++) f1("abc"); | 228 for (var i = 0; i < 20; i++) f1("abc"); |
| 239 Expect.equals(99, f1("abc")); | 229 Expect.equals(99, f1("abc")); |
| 240 Expect.equals(0, f1(null)); | 230 Expect.equals(0, f1(null)); |
| 241 | 231 |
| 242 for (var i = 0; i < 20; i++) f2("abc"); | 232 for (var i = 0; i < 20; i++) f2("abc"); |
| 243 Expect.equals(99, f2("abc")); | 233 Expect.equals(99, f2("abc")); |
| 244 Expect.equals(null, f2(null)); | 234 Expect.equals(null, f2(null)); |
| 245 | 235 |
| 246 f3("123", 0); | 236 f3("123", 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 260 for (var i = 0; i < 20; i++) f6(123, 1); | 250 for (var i = 0; i < 20; i++) f6(123, 1); |
| 261 f6(null, 1); | 251 f6(null, 1); |
| 262 | 252 |
| 263 f7("1.2"); | 253 f7("1.2"); |
| 264 f7("Infinity"); | 254 f7("Infinity"); |
| 265 f7("-Infinity"); | 255 f7("-Infinity"); |
| 266 for (var i = 0; i < 20; i++) f7("1.2"); | 256 for (var i = 0; i < 20; i++) f7("1.2"); |
| 267 Expect.equals(false, f7("1.2")); | 257 Expect.equals(false, f7("1.2")); |
| 268 Expect.equals(true, f7("Infinity")); | 258 Expect.equals(true, f7("Infinity")); |
| 269 Expect.equals(true, f7("-Infinity")); | 259 Expect.equals(true, f7("-Infinity")); |
| 270 Expect.equals(false, f7("123456789012345")); // Deopt. | 260 Expect.equals(false, f7("123456789012345")); // Deopt. |
| 271 for (var i = 0; i < 20; i++) f7("123456789012345"); | 261 for (var i = 0; i < 20; i++) f7("123456789012345"); |
| 272 Expect.equals(true, f7("Infinity")); | 262 Expect.equals(true, f7("Infinity")); |
| 273 Expect.equals(true, f7("-Infinity")); | 263 Expect.equals(true, f7("-Infinity")); |
| 274 | 264 |
| 275 for (var i = 0; i < 20; i++) f8(null); | 265 for (var i = 0; i < 20; i++) f8(null); |
| 276 f8(null); | 266 f8(null); |
| 277 | 267 |
| 278 f9(5); | 268 f9(5); |
| 279 f9(5.0); | 269 f9(5.0); |
| 280 for (var i = 0; i < 20; i++) f9(3); | 270 for (var i = 0; i < 20; i++) f9(3); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 291 Expect.equals(0, f11(null)); | 281 Expect.equals(0, f11(null)); |
| 292 | 282 |
| 293 for (var i = 0; i < 20; i++) f12(null); | 283 for (var i = 0; i < 20; i++) f12(null); |
| 294 f12(null); | 284 f12(null); |
| 295 | 285 |
| 296 f13(null); | 286 f13(null); |
| 297 for (var i = 0; i < 20; i++) f13("abc"); | 287 for (var i = 0; i < 20; i++) f13("abc"); |
| 298 Expect.equals(99, f13("abc")); | 288 Expect.equals(99, f13("abc")); |
| 299 Expect.equals(1, f13(null)); | 289 Expect.equals(1, f13(null)); |
| 300 } | 290 } |
| OLD | NEW |