Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: test/mjsunit/harmony/sloppy-restrictive-block-function.js

Issue 1757543003: Restrict FunctionDeclarations in Statement position (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: ignition failure expectation Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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: --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 assertThrows(`
17 function() {
18 'use strict';
19 if (true) function foo() {}
20 }
21 `, SyntaxError);
22
23 // In the spec-compliant mode, legacy features of allowing function
24 // declarations as the body of various constructs is disallowed.
25 assertThrows(`
26 for (;false;) function f() { };
27 `, SyntaxError);
28
29 assertThrows(`
30 for (var x in {}) function f() { };
31 `, SyntaxError);
32
33 assertThrows(`
34 for (x in {}) function f() { };
35 `, SyntaxError);
36
37 assertThrows(`
38 for (var i = 0; i < 1; i++) function f() { };
39 `, SyntaxError);
40
41 assertThrows(`
42 for (var x in {a: 1}) function f() { };
43 `, SyntaxError);
44
45 assertThrows(`
46 for (x in {a: 1}) function f() { };
47 `, SyntaxError);
48
49 assertThrows(`
50 with ({}) function f() { };
51 `, SyntaxError);
52
53 assertThrows(`
54 do function foo() {} while (0);
55 `, SyntaxError);
56
57 assertThrows(`
58 function() {
59 'use strict';
60 for (;false;) function foo() {}
61 }
62 `, SyntaxError);
63
64 assertThrows(`
65 function() {
66 'use strict';
67 for (var x in {}) function foo() {}
68 }
69 `, SyntaxError);
70
71 assertThrows(`
72 function() {
73 'use strict';
74 var x;
75 for (x in {}) function foo() {}
76 }
77 `, SyntaxError);
78
79 assertThrows(`
80 function() {
81 'use strict';
82 do function foo() {} while (0);
83 }
84 `, SyntaxError);
85
86 // Some contexts always throw for function declarations, even in sloppy mode
87
88 assertThrows(`
89 function() {
90 try function foo() {} catch (e) {}
91 }
92 `, SyntaxError);
93
94 assertThrows(`
95 function() {
96 'use strict';
97 try function foo() {} catch (e) {}
98 }
99 `, SyntaxError);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698