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

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: git rebase to fix merge conflict 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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/runtime-gen/mapiteratorclose.js » ('j') | 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 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 })();
902
903
904 (function TestMapForEachNestedNonTrivialTransition() {
905 var map = new Map;
906 map.set(0, 0);
907 map.set(1, 1);
908 map.set(2, 2);
909 map.set(3, 3);
910 map.delete(0);
911
912 var i = 0;
913 var buffer = [];
914 map.forEach(function(v) {
915 if (++i > 10) return;
916
917 buffer.push(v);
918
919 if (v == 3) {
920 map.delete(1);
921 for (var j = 4; j < 10; j++) {
922 map.set(j, j);
923 }
924 for (var j = 4; j < 10; j += 2) {
925 map.delete(j);
926 }
927 map.delete(2);
928
929 for (var j = 10; j < 20; j++) {
930 map.set(j, j);
931 }
932 for (var j = 10; j < 20; j += 2) {
933 map.delete(j);
934 }
935
936 map.delete(3);
937 }
938 });
939
940 assertArrayEquals([1, 2, 3, 5, 7, 9, 11, 13, 15, 17], buffer);
941 })();
942
943
944 (function TestMapForEachAllRemovedTransitionNoClear() {
945 var map = new Map;
946 map.set(0, 0);
947
948 var buffer = [];
949 map.forEach(function(v) {
950 buffer.push(v);
951 if (v === 0) {
952 for (var i = 1; i < 8; i++) {
953 map.set(i, i);
954 }
955 }
956
957 if (v === 4) {
958 for (var i = 0; i < 8; i++) {
959 map.delete(i);
960 }
961 }
962 });
963
964 assertArrayEquals([0, 1, 2, 3, 4], buffer);
965 })();
966
967
968 (function TestMapForEachNoMoreElementsAfterTransition() {
969 var map = new Map;
970 map.set(0, 0);
971
972 var buffer = [];
973 map.forEach(function(v) {
974 buffer.push(v);
975 if (v === 0) {
976 for (var i = 1; i < 16; i++) {
977 map.set(i, i);
978 }
979 }
980
981 if (v === 4) {
982 for (var i = 5; i < 16; i++) {
983 map.delete(i);
984 }
985 }
986 });
987
988 assertArrayEquals([0, 1, 2, 3, 4], buffer);
989 })();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/runtime-gen/mapiteratorclose.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698