OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode. | 5 // Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode. |
6 // http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-decl
arations-web-legacy-compatibility-semantics | 6 // http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-decl
arations-web-legacy-compatibility-semantics |
7 | 7 |
8 (function overridingLocalFunction() { | 8 (function overridingLocalFunction() { |
9 var x = []; | 9 var x = []; |
10 assertEquals('function', typeof f); | 10 assertEquals('function', typeof f); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 })(1); | 184 })(1); |
185 | 185 |
186 assertThrows(function notInDefaultScope(x = y) { | 186 assertThrows(function notInDefaultScope(x = y) { |
187 { | 187 { |
188 function y() {} | 188 function y() {} |
189 } | 189 } |
190 assertEquals('function', typeof y); | 190 assertEquals('function', typeof y); |
191 assertEquals(x, undefined); | 191 assertEquals(x, undefined); |
192 }, ReferenceError); | 192 }, ReferenceError); |
193 | 193 |
| 194 // B.3.5 interacts with B.3.3 to allow this. |
| 195 (function hoistingThroughSimpleCatch() { |
| 196 assertEquals(undefined, f); |
| 197 |
| 198 try { |
| 199 throw 0; |
| 200 } catch(f) { |
| 201 { |
| 202 assertEquals(4, f()); |
| 203 |
| 204 function f() { |
| 205 return 4; |
| 206 } |
| 207 |
| 208 assertEquals(4, f()); |
| 209 } |
| 210 } |
| 211 |
| 212 assertEquals(4, f()); |
| 213 })(); |
| 214 |
| 215 (function noHoistingThroughComplexCatch() { |
| 216 try { |
| 217 throw 0; |
| 218 } catch({f}) { |
| 219 { |
| 220 assertEquals(4, f()); |
| 221 |
| 222 function f() { |
| 223 return 4; |
| 224 } |
| 225 |
| 226 assertEquals(4, f()); |
| 227 } |
| 228 } |
| 229 |
| 230 assertThrows(()=>f, ReferenceError); |
| 231 })(); |
| 232 |
194 // Test that hoisting from blocks does happen in global scope | 233 // Test that hoisting from blocks does happen in global scope |
195 function globalHoisted() { return 0; } | 234 function globalHoisted() { return 0; } |
196 { | 235 { |
197 function globalHoisted() { return 1; } | 236 function globalHoisted() { return 1; } |
198 } | 237 } |
199 assertEquals(1, globalHoisted()); | 238 assertEquals(1, globalHoisted()); |
200 | 239 |
201 // Also happens when not previously defined | 240 // Also happens when not previously defined |
202 assertEquals(undefined, globalUndefinedHoisted); | 241 assertEquals(undefined, globalUndefinedHoisted); |
203 { | 242 { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 throws = false; | 328 throws = false; |
290 try { | 329 try { |
291 eval('{ function hoistWhenFrozen() {} }'); | 330 eval('{ function hoistWhenFrozen() {} }'); |
292 } catch (e) { | 331 } catch (e) { |
293 throws = true; | 332 throws = true; |
294 } | 333 } |
295 assertFalse(this.hasOwnProperty("hoistWhenFrozen")); | 334 assertFalse(this.hasOwnProperty("hoistWhenFrozen")); |
296 assertThrows(() => hoistWhenFrozen, ReferenceError); | 335 assertThrows(() => hoistWhenFrozen, ReferenceError); |
297 // Should be assertFalse BUG(v8:4452) | 336 // Should be assertFalse BUG(v8:4452) |
298 assertTrue(throws); | 337 assertTrue(throws); |
OLD | NEW |