]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/modify-set-during-iteration.js
a7398473912a70a193fcdc85304a9978addb8f81
2 function testValue(value
, expected
) {
3 if (value
!== expected
)
4 throw new Error("bad value: expected:(" + expected
+ "),actual:(" + value
+").");
7 var set = new Set([0]);
10 testValue(elm
, counter
);
17 testValue(counter
, 10002);
19 var set = new Set([0, 1, 2, 3]);
21 for (var elm
of set) {
22 testValue(elm
, counter
);
26 testValue(counter
, 1);
28 var set = new Set([0, 1, 2, 3]);
31 for (var elm
of set) {
32 testValue(elm
, exp
[counter
]);
33 set.delete(counter
+ 1);
36 testValue(counter
, 3);
38 var set = new Set([0, 1, 2, 3]);
39 var iter
= set[Symbol
.iterator
]();
40 var iter2
= set[Symbol
.iterator
]();
41 testValue(iter2
.next().value
, 0);
43 // Consume all output of iter.
44 for (var elm
of iter
);
46 testValue(iter
.next().done
, true);
47 testValue(iter
.next().value
, undefined);
50 set.add(1).add(2).add(3);
52 testValue(iter
.next().done
, true);
53 testValue(iter
.next().value
, undefined);
54 testValue(iter2
.next().value
, 1);
55 testValue(iter2
.next().value
, 2);
56 testValue(iter2
.next().value
, 3);
61 set.forEach(function (i
) {
62 throw new Error("unreeachable.");
66 var iter
= set[Symbol
.iterator
]();
69 for (var elm
of iter
) {
70 throw new Error("unreeachable.");
73 var set = new Set([0, 1, 2, 3, 4]);
74 var iter
= set[Symbol
.iterator
]();
75 testValue(set.size
, 5);
76 testValue(iter
.next().value
, 0);
77 testValue(iter
.next().value
, 1);
78 testValue(iter
.next().value
, 2);
79 testValue(iter
.next().value
, 3);
84 // It will cause MapData packing.
85 for (var i
= 5; i
< 1000; ++i
)
88 for (var i
= 4; i
< 1000; ++i
)
89 testValue(iter
.next().value
, i
);
90 testValue(iter
.next().value
, undefined);