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

Side by Side Diff: test/mjsunit/harmony/destructuring.js

Issue 1139603005: [destructuring] Implement BindingArrayPattern (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
« src/parser.cc ('K') | « src/pattern-rewriter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 --harmony-computed-property-names 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);
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 for (var val of [null, undefined]) { 381 for (var val of [null, undefined]) {
382 assertThrows(function() { var {} = val; }, TypeError); 382 assertThrows(function() { var {} = val; }, TypeError);
383 assertThrows(function() { var {x} = val; }, TypeError); 383 assertThrows(function() { var {x} = val; }, TypeError);
384 assertThrows(function() { var { x : {} } = { x : val }; }, TypeError); 384 assertThrows(function() { var { x : {} } = { x : val }; }, TypeError);
385 assertThrows(function() { 'use strict'; let {} = val; }, TypeError); 385 assertThrows(function() { 'use strict'; let {} = val; }, TypeError);
386 assertThrows(function() { 'use strict'; let {x} = val; }, TypeError); 386 assertThrows(function() { 'use strict'; let {x} = val; }, TypeError);
387 assertThrows(function() { 'use strict'; let { x : {} } = { x : val }; }, 387 assertThrows(function() { 'use strict'; let { x : {} } = { x : val }; },
388 TypeError); 388 TypeError);
389 } 389 }
390 }()); 390 }());
391
392
393 (function TestArrayLiteral() {
394 var [a,b,c] = [1,2,3];
arv (Not doing code reviews) 2015/05/19 17:03:48 ws
Dmitry Lomov (no reviews) 2015/05/20 07:42:42 Done.
395 assertSame(1, a);
396 assertSame(2, b);
397 assertSame(3, c);
398 }());
399
400 (function TestIterators() {
401 var log = [];
402 function* f() {
403 log.push("1");
404 yield 1;
405 log.push("2");
406 yield 2;
407 log.push("3");
408 yield 3;
409 log.push("done");
410 };
411
412 (function() {
413 log = [];
414 var [a,b,c] = f();
415 assertSame(1, a);
416 assertSame(2, b);
417 assertSame(3, c);
418 assertArrayEquals(["1", "2", "3"], log);
419 }());
420
421 (function() {
422 log = [];
423 var [a,b,c,d] = f();
424 assertSame(1, a);
425 assertSame(2, b);
426 assertSame(3, c);
427 assertSame(undefined, d);
428 assertArrayEquals(["1", "2", "3", "done"], log);
429 }());
430
431 (function() {
432 log = [];
433 var [a,,c] = f();
434 assertSame(1, a);
435 assertSame(3, c);
436 assertArrayEquals(["1", "2", "3"], log);
437 }());
438
439 (function() {
440 log = [];
441 var [a,,c,d] = f();
442 assertSame(1, a);
443 assertSame(3, c);
444 assertSame(undefined, d);
445 assertArrayEquals(["1", "2", "3", "done"], log);
446 }());
447
448 (function() {
449 log = [];
450 // last comma is not an elision.
451 var [a,b,] = f();
452 assertSame(1, a);
453 assertSame(2, b);
454 assertArrayEquals(["1", "2"], log);
455 }());
456
457 (function() {
458 log = [];
459 // last comma is not an elision, but the comma before the last is.
460 var [a,b,,] = f();
461 assertSame(1, a);
462 assertSame(2, b);
463 assertArrayEquals(["1", "2", "3"], log);
464 }());
465
466 }());
467
468
469 (function TestIteratorsLexical() {
470 'use strict';
471 var log = [];
472 function* f() {
473 log.push("1");
474 yield 1;
475 log.push("2");
476 yield 2;
477 log.push("3");
478 yield 3;
479 log.push("done");
480 };
481
482 (function() {
483 log = [];
484 let [a,b,c] = f();
485 assertSame(1, a);
486 assertSame(2, b);
487 assertSame(3, c);
488 assertArrayEquals(["1", "2", "3"], log);
489 }());
490
491 (function() {
492 log = [];
493 let [a,b,c,d] = f();
494 assertSame(1, a);
495 assertSame(2, b);
496 assertSame(3, c);
497 assertSame(undefined, d);
498 assertArrayEquals(["1", "2", "3", "done"], log);
499 }());
500
501 (function() {
502 log = [];
503 let [a,,c] = f();
504 assertSame(1, a);
505 assertSame(3, c);
506 assertArrayEquals(["1", "2", "3"], log);
507 }());
508
509 (function() {
510 log = [];
511 let [a,,c,d] = f();
512 assertSame(1, a);
513 assertSame(3, c);
514 assertSame(undefined, d);
515 assertArrayEquals(["1", "2", "3", "done"], log);
516 }());
517
518 (function() {
519 log = [];
520 // last comma is not an elision.
521 let [a,b,] = f();
522 assertSame(1, a);
523 assertSame(2, b);
524 assertArrayEquals(["1", "2"], log);
525 }());
526
527 (function() {
528 log = [];
529 // last comma is not an elision, but the comma before the last is.
530 let [a,b,,] = f();
531 assertSame(1, a);
532 assertSame(2, b);
533 assertArrayEquals(["1", "2", "3"], log);
534 }());
535
arv (Not doing code reviews) 2015/05/19 17:03:48 Can you add some recursive tests too?
Dmitry Lomov (no reviews) 2015/05/20 07:42:42 Done.
536 }());
OLDNEW
« src/parser.cc ('K') | « src/pattern-rewriter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698