OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax |
| 6 |
| 7 (function DeoptimizeFinallyFallThrough() { |
| 8 var global = 0; |
| 9 function f() { |
| 10 var a = 1; |
| 11 try { |
| 12 global = 1; |
| 13 } finally { |
| 14 global = 42; |
| 15 %DeoptimizeNow(); |
| 16 } |
| 17 return global + a; |
| 18 } |
| 19 |
| 20 f(); |
| 21 f(); |
| 22 %OptimizeFunctionOnNextCall(f); |
| 23 assertEquals(43, f()); |
| 24 assertEquals(42, global); |
| 25 })(); |
| 26 |
| 27 (function DeoptimizeFinallyReturn() { |
| 28 var global = 0; |
| 29 function f() { |
| 30 try { |
| 31 return 10; |
| 32 } finally { |
| 33 global = 42; |
| 34 %DeoptimizeNow(); |
| 35 } |
| 36 return 1; |
| 37 } |
| 38 |
| 39 f(); |
| 40 f(); |
| 41 %OptimizeFunctionOnNextCall(f); |
| 42 assertEquals(10, f()); |
| 43 assertEquals(42, global); |
| 44 })(); |
| 45 |
| 46 (function DeoptimizeFinallyReturnDoublyNested() { |
| 47 var global = 0; |
| 48 function f() { |
| 49 try { |
| 50 try { |
| 51 return 10; |
| 52 } finally { |
| 53 global += 21; |
| 54 %DeoptimizeNow(); |
| 55 } |
| 56 } finally { |
| 57 global += 21; |
| 58 } |
| 59 return 1; |
| 60 } |
| 61 |
| 62 f(); |
| 63 f(); |
| 64 %OptimizeFunctionOnNextCall(f); |
| 65 global = 0; |
| 66 assertEquals(10, f()); |
| 67 assertEquals(42, global); |
| 68 })(); |
| 69 |
| 70 (function DeoptimizeOuterFinallyReturnDoublyNested() { |
| 71 var global = 0; |
| 72 function f() { |
| 73 try { |
| 74 try { |
| 75 return 10; |
| 76 } finally { |
| 77 global += 21; |
| 78 } |
| 79 } finally { |
| 80 global += 21; |
| 81 %DeoptimizeNow(); |
| 82 } |
| 83 return 1; |
| 84 } |
| 85 |
| 86 f(); |
| 87 f(); |
| 88 %OptimizeFunctionOnNextCall(f); |
| 89 global = 0; |
| 90 assertEquals(10, f()); |
| 91 assertEquals(42, global); |
| 92 })(); |
| 93 |
| 94 (function DeoptimizeFinallyThrow() { |
| 95 var global = 0; |
| 96 function f() { |
| 97 try { |
| 98 global = 21; |
| 99 throw 1; |
| 100 global = 2; |
| 101 } finally { |
| 102 global += 21; |
| 103 %DeoptimizeNow(); |
| 104 } |
| 105 global = 3; |
| 106 return 1; |
| 107 } |
| 108 |
| 109 try { f(); } catch(e) {} |
| 110 try { f(); } catch(e) {} |
| 111 %OptimizeFunctionOnNextCall(f); |
| 112 assertThrowsEquals(f, 1); |
| 113 assertEquals(42, global); |
| 114 })(); |
| 115 |
| 116 (function DeoptimizeFinallyThrowNested() { |
| 117 var global = 0; |
| 118 function f() { |
| 119 try { |
| 120 try { |
| 121 global = 10; |
| 122 throw 1; |
| 123 global = 2; |
| 124 } finally { |
| 125 global += 11; |
| 126 %DeoptimizeNow(); |
| 127 } |
| 128 global = 4; |
| 129 } finally { |
| 130 global += 21; |
| 131 } |
| 132 global = 3; |
| 133 return 1; |
| 134 } |
| 135 |
| 136 try { f(); } catch(e) {} |
| 137 try { f(); } catch(e) {} |
| 138 %OptimizeFunctionOnNextCall(f); |
| 139 assertThrowsEquals(f, 1); |
| 140 assertEquals(42, global); |
| 141 })(); |
| 142 |
| 143 (function DeoptimizeFinallyContinue() { |
| 144 var global = 0; |
| 145 function f() { |
| 146 global = 0; |
| 147 for (var i = 0; i < 2; i++) { |
| 148 try { |
| 149 if (i == 0) continue; |
| 150 global += 10; |
| 151 } finally { |
| 152 global += 6; |
| 153 %DeoptimizeNow(); |
| 154 } |
| 155 global += 20; |
| 156 } |
| 157 return 1; |
| 158 } |
| 159 |
| 160 f(); |
| 161 f(); |
| 162 %OptimizeFunctionOnNextCall(f); |
| 163 assertEquals(1, f()); |
| 164 assertEquals(42, global); |
| 165 })(); |
| 166 |
| 167 (function DeoptimizeFinallyContinueNestedTry() { |
| 168 var global = 0; |
| 169 function f() { |
| 170 global = 0; |
| 171 for (var i = 0; i < 2; i++) { |
| 172 try { |
| 173 try { |
| 174 if (i == 0) continue; |
| 175 global += 5; |
| 176 } finally { |
| 177 global += 4; |
| 178 %DeoptimizeNow(); |
| 179 } |
| 180 global += 5; |
| 181 } finally { |
| 182 global += 2; |
| 183 } |
| 184 global += 20; |
| 185 } |
| 186 return 1; |
| 187 } |
| 188 |
| 189 f(); |
| 190 f(); |
| 191 %OptimizeFunctionOnNextCall(f); |
| 192 assertEquals(1, f()); |
| 193 assertEquals(42, global); |
| 194 })(); |
| 195 |
| 196 (function DeoptimizeFinallyBreak() { |
| 197 var global = 0; |
| 198 function f() { |
| 199 global = 0; |
| 200 for (var i = 0; i < 2; i++) { |
| 201 try { |
| 202 global += 20; |
| 203 if (i == 0) break; |
| 204 global += 5; |
| 205 } finally { |
| 206 global += 22; |
| 207 %DeoptimizeNow(); |
| 208 } |
| 209 global += 5; |
| 210 } |
| 211 return 1; |
| 212 } |
| 213 |
| 214 f(); |
| 215 f(); |
| 216 %OptimizeFunctionOnNextCall(f); |
| 217 assertEquals(1, f()); |
| 218 assertEquals(42, global); |
| 219 })(); |
| 220 |
| 221 (function DeoptimizeFinallyBreakNested() { |
| 222 var global = 0; |
| 223 function f() { |
| 224 global = 0; |
| 225 for (var i = 0; i < 2; i++) { |
| 226 try { |
| 227 try { |
| 228 global += 20; |
| 229 if (i == 0) break; |
| 230 global += 5; |
| 231 } finally { |
| 232 global += 12; |
| 233 %DeoptimizeNow(); |
| 234 } |
| 235 global += 8; |
| 236 } finally { |
| 237 global += 10; |
| 238 } |
| 239 global += 5; |
| 240 } |
| 241 return 1; |
| 242 } |
| 243 |
| 244 f(); |
| 245 f(); |
| 246 %OptimizeFunctionOnNextCall(f); |
| 247 assertEquals(1, f()); |
| 248 assertEquals(42, global); |
| 249 })(); |
OLD | NEW |