]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | |
2 | function testValue(value, expected) { | |
3 | if (value !== expected) | |
4 | throw new Error("bad value: expected:(" + expected + "),actual:(" + value +")."); | |
5 | } | |
6 | ||
7 | var set = new Set([0]); | |
8 | var counter = 0; | |
9 | for (var elm of set) { | |
10 | testValue(elm, counter); | |
11 | set.add(elm + 1); | |
12 | if (elm > 10000) { | |
13 | set.clear(); | |
14 | } | |
15 | ++counter; | |
16 | } | |
17 | testValue(counter, 10002); | |
18 | ||
19 | var set = new Set([0, 1, 2, 3]); | |
20 | var counter = 0; | |
21 | for (var elm of set) { | |
22 | testValue(elm, counter); | |
23 | set.clear(); | |
24 | ++counter; | |
25 | } | |
26 | testValue(counter, 1); | |
27 | ||
28 | var set = new Set([0, 1, 2, 3]); | |
29 | var exp = [0, 2, 3]; | |
30 | var counter = 0; | |
31 | for (var elm of set) { | |
32 | testValue(elm, exp[counter]); | |
33 | set.delete(counter + 1); | |
34 | ++counter; | |
35 | } | |
36 | testValue(counter, 3); | |
37 | ||
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); | |
42 | ||
43 | // Consume all output of iter. | |
44 | for (var elm of iter); | |
45 | ||
46 | testValue(iter.next().done, true); | |
47 | testValue(iter.next().value, undefined); | |
48 | ||
49 | set.clear(); | |
50 | set.add(1).add(2).add(3); | |
51 | ||
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); | |
57 | ||
58 | var set = new Set(); | |
59 | set.add(1); | |
60 | set.delete(1); | |
61 | set.forEach(function (i) { | |
62 | throw new Error("unreeachable."); | |
63 | }); | |
64 | ||
65 | var set = new Set(); | |
66 | var iter = set[Symbol.iterator](); | |
67 | set.add(1); | |
68 | set.delete(1); | |
69 | for (var elm of iter) { | |
70 | throw new Error("unreeachable."); | |
71 | } | |
72 | ||
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); | |
80 | set.delete(0); | |
81 | set.delete(1); | |
82 | set.delete(2); | |
83 | set.delete(3); | |
84 | // It will cause MapData packing. | |
85 | for (var i = 5; i < 1000; ++i) | |
86 | set.add(i); | |
87 | gc(); | |
88 | for (var i = 4; i < 1000; ++i) | |
89 | testValue(iter.next().value, i); | |
90 | testValue(iter.next().value, undefined); | |
91 |