blob: 07ce64b9ac0e69961e9acb723a1c23adc2e7f426 [file] [log] [blame]
Ben Murdochda12d292016-06-02 14:46:10 +01001// 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: --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() {
12 if (false) function f() { };
13 assertEquals(undefined, f);
14})();
15
16(function() {
17 assertEquals(undefined, f);
18 if (true) function f() { };
19 assertEquals('function', typeof f);
20})();
21
22(function() {
23 assertEquals(undefined, f);
24 if (true) {} else function f() { };
25 assertEquals(undefined, f);
26})();
27
28(function() {
29 assertEquals(undefined, f);
30 if (false) {} else function f() { };
31 assertEquals('function', typeof f);
32})();
33
34// Labeled function declarations undergo the same hoisting/FiB semantics as if
35// they were unalbeled.
36(function() {
37 function bar() {
38 return f;
39 x: function f() {}
40 }
41 assertEquals('function', typeof bar());
42})();
43
44(function() {
45 function bar() {
46 return f;
47 {
48 x: function f() {}
49 }
50 }
51 assertEquals(undefined, bar());
52})();