blob: 2c31cd95e60e19c54989070f51d15f47812c97d1 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005
6// In sloppy mode we allow function redeclarations within blocks for webcompat.
7(function() {
8 assertEquals(undefined, f); // Annex B
9 if (true) {
10 assertEquals(2, f());
11 function f() { return 1 }
12 assertEquals(2, f());
13 function f() { return 2 }
14 assertEquals(2, f());
15 }
16 assertEquals(2, f()); // Annex B
17})();
18
19// Should still fail in strict mode
20assertThrows(`
21 (function() {
22 "use strict";
23 if (true) {
24 function f() { return 1 }
25 function f() { return 2 }
26 }
27 })();
28`, SyntaxError);
Ben Murdoch097c5b22016-05-18 11:27:45 +010029
30// Conflicts between let and function still throw
31assertThrows(`
32 (function() {
33 if (true) {
34 let f;
35 function f() { return 2 }
36 }
37 })();
38`, SyntaxError);
39
40assertThrows(`
41 (function() {
42 if (true) {
43 function f() { return 2 }
44 let f;
45 }
46 })();
47`, SyntaxError);
48
49// Conflicts between const and function still throw
50assertThrows(`
51 (function() {
52 if (true) {
53 const f;
54 function f() { return 2 }
55 }
56 })();
57`, SyntaxError);
58
59assertThrows(`
60 (function() {
61 if (true) {
62 function f() { return 2 }
63 const f;
64 }
65 })();
66`, SyntaxError);
67
68// Annex B redefinition semantics still apply with more blocks
69(function() {
70 assertEquals(undefined, f); // Annex B
71 if (true) {
72 assertEquals(undefined, f);
73 { function f() { return 1 } }
74 assertEquals(1, f());
75 { function f() { return 2 } }
76 assertEquals(2, f());
77 }
78 assertEquals(2, f()); // Annex B
79})();