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

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

Issue 236143002: ES6: Add support for Map.prototype.forEach and Set.prototype.forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« src/runtime.cc ('K') | « test/cctest/test-ordered-hash-table.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 (function TestMinusZeroMap() { 500 (function TestMinusZeroMap() {
501 var m = new Map(); 501 var m = new Map();
502 m.set(0, 'plus'); 502 m.set(0, 'plus');
503 m.set(-0, 'minus'); 503 m.set(-0, 'minus');
504 assertEquals(1, m.size); 504 assertEquals(1, m.size);
505 assertTrue(m.has(0)); 505 assertTrue(m.has(0));
506 assertTrue(m.has(-0)); 506 assertTrue(m.has(-0));
507 assertEquals('minus', m.get(0)); 507 assertEquals('minus', m.get(0));
508 assertEquals('minus', m.get(-0)); 508 assertEquals('minus', m.get(-0));
509 })(); 509 })();
510
511
512 (function TestSetForEach() {
513 var set = new Set();
514 set.add('a');
515 set.add('b');
516 set.add('c');
517
518 var buffer = '';
519 var receiver = {};
520 set.forEach(function(v, k, s) {
521 assertSame(v, k);
522 assertSame(set, s);
523 assertSame(this, receiver);
524 buffer += v;
525 if (v === 'a') {
526 set.delete('b');
527 set.add('d');
528 set.add('e');
529 set.add('f');
530 } else if (v === 'c') {
531 set.add('b');
532 set.delete('e');
533 }
534 }, receiver);
535
536 assertEquals('acdfb', buffer);
537 })();
538
539
540 (function TestSetForEachClear() {
541 var set = new Set();
542 set.add('a');
543 set.add('b');
544 set.add('c');
545
546 var buffer = '';
547 var receiver = {};
548 set.forEach(function(v, k, s) {
549 assertSame(v, k);
550 assertSame(set, s);
551 assertSame(this, receiver);
552 buffer += v;
553 if (v === 'a') {
554 set.clear();
555 set.add('d');
556 set.add('e');
557 }
558 }, receiver);
559
560 assertEquals('ade', buffer);
561 })();
562
563
564 (function TestSetForEachNested() {
565 var set = new Set();
566 set.add('a');
567 set.add('b');
568 set.add('c');
569
570 var buffer = '';
571 var receiver = {};
572 set.forEach(function(v) {
573 buffer += v;
574 set.forEach(function(v) {
575 buffer += v;
576 if (v === 'a') {
577 set.delete('b');
578 }
579 });
580 });
581
582 assertEquals('aaccac', buffer);
583 })();
584
585
586 (function TestMapForEach() {
587 var map = new Map();
588 map.set(0, 'a');
589 map.set(1, 'b');
590 map.set(2, 'c');
591
592 var buffer = [];
593 var receiver = {};
594 map.forEach(function(v, k, m) {
595 assertEquals(map, m);
596 assertEquals(this, receiver);
597 buffer.push(k, v);
598 if (k === 0) {
599 map.delete(1);
600 map.set(3, 'd');
601 map.set(4, 'e');
602 map.set(5, 'f');
603 } else if (k === 2) {
604 map.set(1, 'B');
605 map.delete(4);
606 }
607 }, receiver);
608
609 assertArrayEquals([0, 'a', 2, 'c', 3, 'd', 5, 'f', 1, 'B'], buffer);
610 })();
611
612
613 (function TestMapForEachClear() {
614 var map = new Map();
615 map.set(0, 'a');
616 map.set(1, 'b');
617 map.set(2, 'c');
618
619 var buffer = [];
620 var receiver = {};
621 map.forEach(function(v, k) {
622 buffer.push(k, v);
623 if (k === 0) {
624 map.clear();
625 map.set(3, 'd');
626 map.set(4, 'e');
627 }
628 }, receiver);
629
630 assertArrayEquals([0, 'a', 3, 'd', 4, 'e'], buffer);
631 })();
632
633
634 (function TestMapForEachNested() {
635 var map = new Map();
636 map.set(0, 'a');
637 map.set(1, 'b');
638 map.set(2, 'c');
639
640 var buffer = [];
641 var receiver = {};
642 map.forEach(function(v, k) {
643 buffer.push(k, v);
644 map.forEach(function(v, k) {
645 buffer.push(k, v);
646 if (k === 0) {
647 map.delete(1);
648 }
649 });
650 });
651
652 assertArrayEquals([0, 'a', 0, 'a', 2, 'c', 2, 'c', 0, 'a', 2, 'c'], buffer);
653 })();
OLDNEW
« src/runtime.cc ('K') | « test/cctest/test-ordered-hash-table.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698