OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-default-parameters --harmony-arrow-functions | 5 // Flags: --harmony-default-parameters --harmony-arrow-functions |
6 // Flags: --harmony-rest-parameters --harmony-destructuring | 6 // Flags: --harmony-rest-parameters --harmony-destructuring |
7 | 7 |
8 | 8 |
9 (function TestDefaults() { | 9 (function TestDefaults() { |
10 function f1(x = 1) { return x } | 10 function f1(x = 1) { return x } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 var x = 1; | 165 var x = 1; |
166 | 166 |
167 function f1(y = eval("var x = 2")) { with ({}) { return x; } } | 167 function f1(y = eval("var x = 2")) { with ({}) { return x; } } |
168 assertEquals(1, f1()); | 168 assertEquals(1, f1()); |
169 function f2(y = eval("var x = 2"), z = x) { return z; } | 169 function f2(y = eval("var x = 2"), z = x) { return z; } |
170 assertEquals(1, f2()); | 170 assertEquals(1, f2()); |
171 assertEquals(1, f2(0)); | 171 assertEquals(1, f2(0)); |
172 function f3(y = eval("var x = 2"), z = eval("x")) { return z; } | 172 function f3(y = eval("var x = 2"), z = eval("x")) { return z; } |
173 assertEquals(1, f3()); | 173 assertEquals(1, f3()); |
174 assertEquals(1, f3(0)); | 174 assertEquals(1, f3(0)); |
175 // TODO(rossberg): eval inside patterns is not recognized yet. | 175 function f41({[eval("var x = 2; 'a'")]: w}, z = x) { return z; } |
176 // function f41({[eval("var x = 2; 'a'")]: w}, z = x)) { return z; } | 176 assertEquals(1, f41({})); |
177 // assertEquals(1, f41({})); | 177 assertEquals(1, f41({a: 0})); |
178 // assertEquals(1, f41({a: 0})); | 178 function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; } |
179 // function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; } | 179 assertEquals(1, f42({})); |
180 // assertEquals(1, f42({})); | 180 assertEquals(1, f42({a: 0})); |
181 // assertEquals(1, f42({a: 0})); | 181 function f43({a: w = eval("var x = 2")}, z = x) { return z; } |
182 // function f43({a: w = eval("var x = 2")}, z = x) { return z; } | 182 assertEquals(1, f43({})); |
183 // assertEquals(1, f43({})); | 183 assertEquals(1, f43({a: 0})); |
184 // assertEquals(1, f43({a: 0})); | 184 function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; } |
185 // function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; } | 185 assertEquals(1, f44({})); |
186 // assertEquals(1, f44({})); | 186 assertEquals(1, f44({a: 0})); |
187 // assertEquals(1, f44({a: 0})); | |
188 | 187 |
189 function f5({a = eval("var x = 2"), b = x}) { return b; } | 188 function f5({a = eval("var x = 2"), b = x}) { return b; } |
190 assertEquals(2, f5({})); | 189 assertEquals(2, f5({})); |
191 assertEquals(1, f5({a: 0})); | 190 assertEquals(1, f5({a: 0})); |
192 function f6({a = eval("var x = 2"), b = eval("x")}) { return b; } | 191 function f6({a = eval("var x = 2"), b = eval("x")}) { return b; } |
193 assertEquals(2, f6({})); | 192 assertEquals(2, f6({})); |
194 assertEquals(1, f6({a: 0})); | 193 assertEquals(1, f6({a: 0})); |
195 function f71({[eval("var x = 2; 'a'")]: w, b = x}) { return b; } | 194 function f71({[eval("var x = 2; 'a'")]: w, b = x}) { return b; } |
196 assertEquals(2, f71({})); | 195 assertEquals(2, f71({})); |
197 assertEquals(2, f71({a: 0})); | 196 assertEquals(2, f71({a: 0})); |
(...skipping 16 matching lines...) Expand all Loading... |
214 assertThrows(f12, ReferenceError); | 213 assertThrows(f12, ReferenceError); |
215 function f13(z = eval("var y = 2"), b = eval("y")) {} | 214 function f13(z = eval("var y = 2"), b = eval("y")) {} |
216 assertThrows(f13, ReferenceError); | 215 assertThrows(f13, ReferenceError); |
217 | 216 |
218 function f21(f = () => x) { eval("var x = 2"); return f() } | 217 function f21(f = () => x) { eval("var x = 2"); return f() } |
219 assertEquals(1, f21()); | 218 assertEquals(1, f21()); |
220 assertEquals(3, f21(() => 3)); | 219 assertEquals(3, f21(() => 3)); |
221 function f22(f = () => eval("x")) { eval("var x = 2"); return f() } | 220 function f22(f = () => eval("x")) { eval("var x = 2"); return f() } |
222 assertEquals(1, f22()); | 221 assertEquals(1, f22()); |
223 assertEquals(3, f22(() => 3)); | 222 assertEquals(3, f22(() => 3)); |
| 223 |
| 224 var g1 = (y = eval("var x = 2")) => { with ({}) { return x; } }; |
| 225 assertEquals(1, g1()); |
| 226 var g2 = (y = eval("var x = 2"), z = x) => { return z; }; |
| 227 assertEquals(1, g2()); |
| 228 assertEquals(1, g2(0)); |
| 229 var g3 = (y = eval("var x = 2"), z = eval("x")) => { return z; }; |
| 230 assertEquals(1, g3()); |
| 231 assertEquals(1, g3(0)); |
| 232 var g41 = ({[eval("var x = 2; 'a'")]: w}, z = x) => { return z; }; |
| 233 assertEquals(1, g41({})); |
| 234 assertEquals(1, g41({a: 0})); |
| 235 var g42 = ({[eval("var x = 2; 'a'")]: w}, z = eval("x")) => { return z; }; |
| 236 assertEquals(1, g42({})); |
| 237 assertEquals(1, g42({a: 0})); |
| 238 var g43 = ({a: w = eval("var x = 2")}, z = x) => { return z; }; |
| 239 assertEquals(1, g43({})); |
| 240 assertEquals(1, g43({a: 0})); |
| 241 var g44 = ({a: w = eval("var x = 2")}, z = eval("x")) => { return z; }; |
| 242 assertEquals(1, g44({})); |
| 243 assertEquals(1, g44({a: 0})); |
| 244 |
| 245 var g5 = ({a = eval("var x = 2"), b = x}) => { return b; }; |
| 246 assertEquals(2, g5({})); |
| 247 assertEquals(1, g5({a: 0})); |
| 248 var g6 = ({a = eval("var x = 2"), b = eval("x")}) => { return b; }; |
| 249 assertEquals(2, g6({})); |
| 250 assertEquals(1, g6({a: 0})); |
| 251 var g71 = ({[eval("var x = 2; 'a'")]: w, b = x}) => { return b; }; |
| 252 assertEquals(2, g71({})); |
| 253 assertEquals(2, g71({a: 0})); |
| 254 var g72 = ({[eval("var x = 2; 'a'")]: w, b = eval("x")}) => { return b; }; |
| 255 assertEquals(2, g72({})); |
| 256 assertEquals(2, g72({a: 0})); |
| 257 var g73 = ({a: w = eval("var x = 2"), b = x}) => { return b; }; |
| 258 assertEquals(2, g73({})); |
| 259 assertEquals(1, g73({a: 0})); |
| 260 var g74 = ({a: w = eval("var x = 2"), b = eval("x")}) => { return b; }; |
| 261 assertEquals(2, g74({})); |
| 262 assertEquals(1, g74({a: 0})); |
| 263 var g8 = (y = (eval("var x = 2"), x)) => { return y; }; |
| 264 assertEquals(2, g8()); |
| 265 assertEquals(0, g8(0)); |
| 266 |
| 267 var g11 = (z = eval("var y = 2")) => { return y; }; |
| 268 assertThrows(g11, ReferenceError); |
| 269 var g12 = (z = eval("var y = 2"), b = y) => {}; |
| 270 assertThrows(g12, ReferenceError); |
| 271 var g13 = (z = eval("var y = 2"), b = eval("y")) => {}; |
| 272 assertThrows(g13, ReferenceError); |
| 273 |
| 274 var g21 = (f = () => x) => { eval("var x = 2"); return f() }; |
| 275 assertEquals(1, g21()); |
| 276 assertEquals(3, g21(() => 3)); |
| 277 var g22 = (f = () => eval("x")) => { eval("var x = 2"); return f() }; |
| 278 assertEquals(1, g22()); |
| 279 assertEquals(3, g22(() => 3)); |
224 })(); | 280 })(); |
225 | 281 |
226 | 282 |
227 (function TestStrictEvalScoping() { | 283 (function TestStrictEvalScoping() { |
228 'use strict'; | 284 'use strict'; |
229 var x = 1; | 285 var x = 1; |
230 | 286 |
231 function f1(y = eval("var x = 2")) { return x; } | 287 function f1(y = eval("var x = 2")) { return x; } |
232 assertEquals(1, f1()); | 288 assertEquals(1, f1()); |
233 function f2(y = eval("var x = 2"), z = x) { return z; } | 289 function f2(y = eval("var x = 2"), z = x) { return z; } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // assertEquals(0, (function(x = 1, ...a) {}).length); | 423 // assertEquals(0, (function(x = 1, ...a) {}).length); |
368 // assertEquals(1, (function(x, y = 1) {}).length); | 424 // assertEquals(1, (function(x, y = 1) {}).length); |
369 // assertEquals(1, (function(x, y = 1, ...a) {}).length); | 425 // assertEquals(1, (function(x, y = 1, ...a) {}).length); |
370 // assertEquals(2, (function(x, y, z = 1) {}).length); | 426 // assertEquals(2, (function(x, y, z = 1) {}).length); |
371 // assertEquals(2, (function(x, y, z = 1, ...a) {}).length); | 427 // assertEquals(2, (function(x, y, z = 1, ...a) {}).length); |
372 // assertEquals(1, (function(x, y = 1, z) {}).length); | 428 // assertEquals(1, (function(x, y = 1, z) {}).length); |
373 // assertEquals(1, (function(x, y = 1, z, ...a) {}).length); | 429 // assertEquals(1, (function(x, y = 1, z, ...a) {}).length); |
374 // assertEquals(1, (function(x, y = 1, z, v = 2) {}).length); | 430 // assertEquals(1, (function(x, y = 1, z, v = 2) {}).length); |
375 // assertEquals(1, (function(x, y = 1, z, v = 2, ...a) {}).length); | 431 // assertEquals(1, (function(x, y = 1, z, v = 2, ...a) {}).length); |
376 })(); | 432 })(); |
OLD | NEW |