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

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

Issue 1234433002: [es6] Sloppy functions in block (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add more tests and discover we do report wrong error Created 5 years, 5 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
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/harmony/block-let-semantics-sloppy.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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-sloppy --no-legacy-const
6
7
8 (function TestHoistingToBlock() {
9 assertEquals(undefined, f);
10 {
11 assertEquals(1, f());
12 function f() { return 1; }
13 assertEquals(1, f());
14 }
15 assertEquals(1, f());
16 })();
17
18
19 (function TestOnlyOneFunction() {
20 var outer, inner;
21 {
22 function f() { return 1; }
23 inner = f;
24 }
25 outer = f;
26 assertEquals(inner, outer);
27 })();
28
29
30 (function TestNoInitIf() {
31 assertEquals(undefined, f);
32 if (false) {
33 function f() { return 1; }
34 }
35 assertEquals(undefined, f);
36 })();
37
38
39 (function TestInitIf() {
40 assertEquals(undefined, f);
41 if (true) {
42 function f() { return 1; }
43 }
44 assertEquals(1, f());
45 })();
46
47
48 (function TestNoInitElse() {
49 assertEquals(undefined, f);
50 if (true) {
51 } else {
52 function f() { return 1; }
53 }
54 assertEquals(undefined, f);
55 })();
56
57
58 (function TestInitElse() {
59 assertEquals(undefined, f);
60 if (false) {
61 } else {
62 function f() { return 1; }
63 }
64 assertEquals(1, f());
65 })();
66
67
68 (function TestNoInitWhile() {
69 assertEquals(undefined, f);
70 while (false) {
71 function f() { return 1; }
72 }
73 assertEquals(undefined, f);
74 })();
75
76
77 (function TestInitWhile() {
78 assertEquals(undefined, f);
79 while (true) {
80 function f() { return 1; }
81 break;
82 }
83 assertEquals(1, f());
84 })();
85
86
87 (function TestNoInitFor() {
88 assertEquals(undefined, f);
89 for (; false; ) {
90 function f() { return 1; }
91 }
92 assertEquals(undefined, f);
93 })();
94
95
96 (function TestInitFor() {
97 assertEquals(undefined, f);
98 for (; true; ) {
99 function f() { return 1; }
100 break
101 }
102 assertEquals(1, f());
103 })();
104
105
106 (function TestNoInitForLet() {
107 assertEquals(undefined, f);
108 for (let x; false; ) {
109 function f() { return 1; }
110 }
111 assertEquals(undefined, f);
112 })();
113
114
115 (function TestInitForLet() {
116 assertEquals(undefined, f);
117 for (let x = 0; x < 1; x++) {
118 function f() { return 1; }
119 }
120 assertEquals(1, f());
121 })();
122
123
124 (function TestNoInitForIn() {
125 assertEquals(undefined, f);
126 for (var k in {}) {
127 function f() { return 1; }
128 }
129 assertEquals(undefined, f);
130 })();
131
132
133 (function TestInitForIn() {
134 assertEquals(undefined, f);
135 for (var k in {a: 1}) {
136 function f() { return 1; }
137 }
138 assertEquals(1, f());
139 })();
140
141
142 (function TestNoInitForInLet() {
143 assertEquals(undefined, f);
144 for (let k in {}) {
145 function f() { return 1; }
146 }
147 assertEquals(undefined, f);
148 })();
149
150
151 (function TestInitForInLet() {
152 assertEquals(undefined, f);
153 for (let k in {a: 1}) {
154 function f() { return 1; }
155 }
156 assertEquals(1, f());
157 })();
158
159
160 (function TestNoInitForOf() {
161 assertEquals(undefined, f);
162 for (var v of []) {
163 function f() { return 1; }
164 }
165 assertEquals(undefined, f);
166 })();
167
168
169 (function TestNoInitForOf() {
170 assertEquals(undefined, f);
171 for (var v of [0]) {
172 function f() { return 1; }
173 }
174 assertEquals(1, f());
175 })();
176
177
178 (function TestNoInitForOfLet() {
179 assertEquals(undefined, f);
180 for (let v of []) {
181 function f() { return 1; }
182 }
183 assertEquals(undefined, f);
184 })();
185
186
187 (function TestInitForOfLet() {
188 assertEquals(undefined, f);
189 for (let v of [0]) {
190 function f() { return 1; }
191 }
192 assertEquals(1, f());
193 })();
194
195
196 (function TestNoVarBindingInCaseOfEarlyError() {
197 let f = 1;
198 assertEquals(1, f);
199 {
200 assertEquals(2, f());
201 function f() { return 2; }
202 assertEquals(2, f());
203 }
204 assertEquals(1, f);
205 })();
206
207
208 (function TestCorrectError() {
209 var ex;
210 try {
211 eval(`
212 function f() {
213 let x = 1;
214 {
215 function x() {}
216 }
217 let y = 2;
218 let y = 3;
219 }
220 f();
221 `);
222 } catch (e) {
223 ex = e;
224 }
225 assertEquals("Identifier 'y' has already been declared", ex.message);
arv (Not doing code reviews) 2015/07/10 16:37:23 We are reporting 'x' here as I suspected. Will hav
226 })();
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/harmony/block-let-semantics-sloppy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698