Chromium Code Reviews| 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: --no-harmony-restrictive-declarations | |
| 6 | |
| 7 // ES#sec-functiondeclarations-in-ifstatement-statement-clauses | |
| 8 // Annex B 3.4 FunctionDeclarations in IfStatement Statement Clauses | |
| 9 // In sloppy mode, function declarations in if statements act like | |
| 10 // they have a block around them. Prohibited in strict mode. | |
| 11 (function() { | |
|
adamk
2016/03/02 00:33:45
Maybe add assertEquals(undefined, f) before the if
Dan Ehrenberg
2016/03/02 00:49:54
Done
| |
| 12 if (false) function f() { }; | |
|
adamk
2016/03/02 00:33:45
What about if (true)? I assume that results in the
Dan Ehrenberg
2016/03/02 00:49:54
Good point, added tests for this, and for the 'els
| |
| 13 assertEquals(undefined, f); | |
| 14 })(); | |
| 15 | |
| 16 assertThrows(` | |
| 17 function() { | |
| 18 'use strict'; | |
| 19 if (true) function foo() {} | |
| 20 } | |
| 21 `, SyntaxError); | |
|
adamk
2016/03/02 00:51:10
All these parsing tests will better-exercise the p
Dan Ehrenberg
2016/03/03 02:32:57
Oops, not sure how I completely forgot about the p
| |
| 22 | |
| 23 // For legacy reasons, we also support these types of semantics as | |
| 24 // the body of a for or with statement. | |
| 25 (function() { | |
| 26 for (;false;) function f() { }; | |
| 27 assertEquals(undefined, f); | |
| 28 })(); | |
| 29 | |
| 30 (function() { | |
| 31 for (var x in {}) function f() { }; | |
| 32 assertEquals(undefined, f); | |
| 33 })(); | |
| 34 | |
| 35 (function() { | |
| 36 var x; | |
| 37 for (x in {}) function f() { }; | |
| 38 assertEquals(undefined, f); | |
| 39 })(); | |
| 40 | |
| 41 (function() { | |
| 42 for (var i = 0; i < 1; i++) function f() { }; | |
| 43 assertEquals('function', typeof f); | |
| 44 })(); | |
| 45 | |
| 46 (function() { | |
| 47 for (var x in {a: 1}) function f() { }; | |
| 48 assertEquals('function', typeof f); | |
| 49 })(); | |
| 50 | |
| 51 (function() { | |
| 52 var x; | |
| 53 for (x in {a: 1}) function f() { }; | |
| 54 assertEquals('function', typeof f); | |
| 55 })(); | |
| 56 | |
| 57 (function() { | |
| 58 with ({}) function f() { }; | |
| 59 assertEquals('function', typeof f); | |
| 60 })(); | |
| 61 | |
| 62 (function() { | |
| 63 do function f() {} while (0); | |
| 64 assertEquals('function', typeof f); | |
| 65 })(); | |
| 66 | |
| 67 assertThrows(` | |
| 68 function() { | |
| 69 'use strict'; | |
| 70 for (;false;) function foo() {} | |
| 71 } | |
| 72 `, SyntaxError); | |
| 73 | |
| 74 assertThrows(` | |
| 75 function() { | |
| 76 'use strict'; | |
| 77 for (var x in {}) function foo() {} | |
| 78 } | |
| 79 `, SyntaxError); | |
| 80 | |
| 81 assertThrows(` | |
| 82 function() { | |
| 83 'use strict'; | |
| 84 var x; | |
| 85 for (x in {}) function foo() {} | |
| 86 } | |
| 87 `, SyntaxError); | |
| 88 | |
| 89 assertThrows(` | |
| 90 function() { | |
| 91 'use strict'; | |
| 92 do function foo() {} while (0); | |
| 93 } | |
| 94 `, SyntaxError); | |
| 95 | |
| 96 // Some contexts always throw for function declarations, even in sloppy mode | |
| 97 | |
| 98 assertThrows(` | |
| 99 function() { | |
| 100 try function foo() {} catch (e) {} | |
| 101 } | |
| 102 `, SyntaxError); | |
| 103 | |
| 104 assertThrows(` | |
| 105 function() { | |
| 106 'use strict'; | |
| 107 try function foo() {} catch (e) {} | |
| 108 } | |
| 109 `, SyntaxError); | |
| OLD | NEW |