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

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: Add comment for Transition 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
908 var i = 0;
909 var buffer = [];
910 map.forEach(function(v) {
911 buffer.push(v);
912
913 if (++i > 16) return;
914
915 if (v % 8 == 0) {
916 for (var j = 1; j <= 8; j++) {
917 map.set(v + j, v + j);
918 }
919 }
920
921 if (v % 2 == 0) {
922 map.delete(v + 1);
rossberg 2014/05/16 16:10:18 If I read this correctly, this only ever deletes t
arv (Not doing code reviews) 2014/05/20 00:29:58 Changed this test. It now has a 4 iteration transi
923 map.delete(v + 3);
924 }
925 });
926
927 for (var i = 0; i <= 16; i++) {
928 assertEquals(buffer[i], i * 2);
929 }
930 })();
931
932
933 (function TestMapForEachAllRemovedTransitionNoClear() {
934 var map = new Map;
935 map.set(0, 0);
936
937 var buffer = [];
938 map.forEach(function(v) {
939 buffer.push(v);
940 if (v === 0) {
941 for (var i = 1; i < 8; i++) {
942 map.set(i, i);
943 }
944 }
945
946 if (v === 4) {
947 for (var i = 0; i < 8; i++) {
948 map.delete(i);
949 }
950 }
951 });
952
953 assertArrayEquals([0, 1, 2, 3, 4], buffer);
954 })();
955
956
957 (function TestMapForEachNoMoreElementsAfterTransition() {
958 var map = new Map;
959 map.set(0, 0);
960
961 var buffer = [];
962 map.forEach(function(v) {
963 buffer.push(v);
964 if (v === 0) {
965 for (var i = 1; i < 16; i++) {
966 map.set(i, i);
967 }
968 }
969
970 if (v === 4) {
971 for (var i = 5; i < 16; i++) {
972 map.delete(i);
973 }
974 }
975 });
976
977 assertArrayEquals([0, 1, 2, 3, 4], buffer);
978 })();
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