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-destructuring | 5 // Flags: --harmony-destructuring --harmony-computed-property-names |
6 | 6 |
7 (function TestObjectLiteralPattern() { | 7 (function TestObjectLiteralPattern() { |
8 var { x : x, y : y } = { x : 1, y : 2 }; | 8 var { x : x, y : y } = { x : 1, y : 2 }; |
9 assertEquals(1, x); | 9 assertEquals(1, x); |
10 assertEquals(2, y); | 10 assertEquals(2, y); |
11 | 11 |
12 var {z} = { z : 3 }; | 12 var {z} = { z : 3 }; |
13 assertEquals(3, z); | 13 assertEquals(3, z); |
14 | 14 |
15 | 15 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 }, ReferenceError); | 276 }, ReferenceError); |
277 | 277 |
278 (function() { | 278 (function() { |
279 'use strict'; | 279 'use strict'; |
280 let {x = (function() { x = 2; }())} = {x:1}; | 280 let {x = (function() { x = 2; }())} = {x:1}; |
281 assertSame(1, x); | 281 assertSame(1, x); |
282 }()); | 282 }()); |
283 }()); | 283 }()); |
284 | 284 |
285 | 285 |
286 (function TestComputedNames() { | |
rossberg
2015/05/19 11:50:34
Add tests with computed accessor and method names.
Dmitry Lomov (no reviews)
2015/05/19 14:07:28
Uhm, accessors and method names are not allowed in
| |
287 var x = 1; | |
288 var {[x]:y} = {1:2}; | |
289 assertSame(2, y); | |
290 | |
291 (function(){ | |
292 'use strict'; | |
293 let {[x]:y} = {1:2}; | |
294 assertSame(2, y); | |
295 }()); | |
296 | |
297 var callCount = 0; | |
298 function foo(v) { callCount++; return v; } | |
299 | |
300 (function() { | |
301 callCount = 0; | |
302 var {[foo("abc")]:x} = {abc:42}; | |
303 assertSame(42, x); | |
304 assertEquals(1, callCount); | |
305 }()); | |
306 | |
307 (function() { | |
308 'use strict'; | |
309 callCount = 0; | |
310 let {[foo("abc")]:x} = {abc:42}; | |
311 assertSame(42, x); | |
312 assertEquals(1, callCount); | |
313 }()); | |
314 | |
315 (function() { | |
316 callCount = 0; | |
317 var {[foo("abc")]:x} = {}; | |
318 assertSame(undefined, x); | |
319 assertEquals(1, callCount); | |
320 }()); | |
321 | |
322 (function() { | |
323 'use strict'; | |
324 callCount = 0; | |
325 let {[foo("abc")]:x} = {}; | |
326 assertSame(undefined, x); | |
327 assertEquals(1, callCount); | |
328 }()); | |
329 | |
330 for (val of [null, undefined]) { | |
331 callCount = 0; | |
332 assertThrows(function() { | |
333 var {[foo()]:x} = val; | |
334 }, TypeError); | |
335 assertEquals(0, callCount); | |
336 | |
337 callCount = 0; | |
338 assertThrows(function() { | |
339 'use strict'; | |
340 let {[foo()]:x} = val; | |
341 }, TypeError); | |
342 assertEquals(0, callCount); | |
343 } | |
344 }()); | |
arv (Not doing code reviews)
2015/05/19 14:19:56
Can haz order tests?
var log = [];
var obj = {
Dmitry Lomov (no reviews)
2015/05/19 14:52:00
Done.
| |
345 | |
346 | |
286 (function TestExceptions() { | 347 (function TestExceptions() { |
287 for (var val of [null, undefined]) { | 348 for (var val of [null, undefined]) { |
288 assertThrows(function() { var {} = val; }, TypeError); | 349 assertThrows(function() { var {} = val; }, TypeError); |
289 assertThrows(function() { var {x} = val; }, TypeError); | 350 assertThrows(function() { var {x} = val; }, TypeError); |
290 assertThrows(function() { var { x : {} } = { x : val }; }, TypeError); | 351 assertThrows(function() { var { x : {} } = { x : val }; }, TypeError); |
291 assertThrows(function() { 'use strict'; let {} = val; }, TypeError); | 352 assertThrows(function() { 'use strict'; let {} = val; }, TypeError); |
292 assertThrows(function() { 'use strict'; let {x} = val; }, TypeError); | 353 assertThrows(function() { 'use strict'; let {x} = val; }, TypeError); |
293 assertThrows(function() { 'use strict'; let { x : {} } = { x : val }; }, | 354 assertThrows(function() { 'use strict'; let { x : {} } = { x : val }; }, |
294 TypeError); | 355 TypeError); |
295 } | 356 } |
296 }()); | 357 }()); |
OLD | NEW |