]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/modify-set-during-iteration.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / modify-set-during-iteration.js
CommitLineData
ed1e77d3
A
1
2function testValue(value, expected) {
3 if (value !== expected)
4 throw new Error("bad value: expected:(" + expected + "),actual:(" + value +").");
5}
6
7var set = new Set([0]);
8var counter = 0;
9for (var elm of set) {
10 testValue(elm, counter);
11 set.add(elm + 1);
12 if (elm > 10000) {
13 set.clear();
14 }
15 ++counter;
16}
17testValue(counter, 10002);
18
19var set = new Set([0, 1, 2, 3]);
20var counter = 0;
21for (var elm of set) {
22 testValue(elm, counter);
23 set.clear();
24 ++counter;
25}
26testValue(counter, 1);
27
28var set = new Set([0, 1, 2, 3]);
29var exp = [0, 2, 3];
30var counter = 0;
31for (var elm of set) {
32 testValue(elm, exp[counter]);
33 set.delete(counter + 1);
34 ++counter;
35}
36testValue(counter, 3);
37
38var set = new Set([0, 1, 2, 3]);
39var iter = set[Symbol.iterator]();
40var iter2 = set[Symbol.iterator]();
41testValue(iter2.next().value, 0);
42
43// Consume all output of iter.
44for (var elm of iter);
45
46testValue(iter.next().done, true);
47testValue(iter.next().value, undefined);
48
49set.clear();
50set.add(1).add(2).add(3);
51
52testValue(iter.next().done, true);
53testValue(iter.next().value, undefined);
54testValue(iter2.next().value, 1);
55testValue(iter2.next().value, 2);
56testValue(iter2.next().value, 3);
57
58var set = new Set();
59set.add(1);
60set.delete(1);
61set.forEach(function (i) {
62 throw new Error("unreeachable.");
63});
64
65var set = new Set();
66var iter = set[Symbol.iterator]();
67set.add(1);
68set.delete(1);
69for (var elm of iter) {
70 throw new Error("unreeachable.");
71}
72
73var set = new Set([0, 1, 2, 3, 4]);
74var iter = set[Symbol.iterator]();
75testValue(set.size, 5);
76testValue(iter.next().value, 0);
77testValue(iter.next().value, 1);
78testValue(iter.next().value, 2);
79testValue(iter.next().value, 3);
80set.delete(0);
81set.delete(1);
82set.delete(2);
83set.delete(3);
84// It will cause MapData packing.
85for (var i = 5; i < 1000; ++i)
86 set.add(i);
87gc();
88for (var i = 4; i < 1000; ++i)
89 testValue(iter.next().value, i);
90testValue(iter.next().value, undefined);
91