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 289503002: ES6 Map/Set iterators/forEach improvements (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Expanded tests and fixed edge case Created 6 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 | Annotate | Revision Log
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 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 845
846 var accumulated = 0; 846 var accumulated = 0;
847 map.forEach(function(v) { 847 map.forEach(function(v) {
848 accumulated += v; 848 accumulated += v;
849 if (v % 10 === 0) { 849 if (v % 10 === 0) {
850 gc(); 850 gc();
851 } 851 }
852 }); 852 });
853 assertEquals(4950, accumulated); 853 assertEquals(4950, accumulated);
854 })(); 854 })();
855
856
857 (function TestMapForEachAllRemovedTransition() {
858 var map = new Map;
859 map.set(0, 0);
860
861 var buffer = [];
862 map.forEach(function(v) {
863 buffer.push(v);
864 if (v === 0) {
865 for (var i = 1; i < 4; i++) {
866 map.set(i, i);
867 }
868 }
869
870 if (v === 3) {
871 for (var i = 0; i < 4; i++) {
872 map.delete(i);
873 }
874 for (var i = 4; i < 8; i++) {
875 map.set(i, i);
876 }
877 }
878 });
879
880 assertArrayEquals([0, 1, 2, 3, 4, 5, 6, 7], buffer);
881 })();
882
883
884 (function TestMapForEachClearTransition() {
885 var map = new Map;
886 map.set(0, 0);
887
888 var i = 0;
889 var buffer = [];
890 map.forEach(function(v) {
891 buffer.push(v);
892 if (++i < 5) {
893 for (var j = 0; j < 5; j++) {
894 map.clear();
895 map.set(i, i);
896 }
897 }
898 });
899
900 assertArrayEquals([0, 1, 2, 3, 4], buffer);
901 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698