]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - tests/stress/map-iterators-next.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / map-iterators-next.js
... / ...
CommitLineData
1// This test checks the behavior of the iterator.next methods on Map objects
2
3var testArray = [1,2,3,4,5,6]
4var testMap = new Map();
5for (var [key, value] of testArray.entries()) {
6 testMap.set(key, value);
7}
8var keys = testMap.keys();
9var i = 0;
10while (true) {
11 var {done, value: key} = keys.next();
12 if (done)
13 break;
14 if (key >= testArray.length)
15 throw "Error: bad value: " + key;
16 i++;
17}
18
19if (testMap.size !== i)
20 throw "Error: bad value: " + i;
21
22var value = keys.next().value;
23if (value !== undefined)
24 throw "Error: bad value: " + value;
25
26var values = testMap.values();
27var i = 0;
28while (true) {
29 var {done, value} = values.next();
30 if (done)
31 break;
32 i++;
33 if (testArray.indexOf(value) === -1)
34 throw "Error: bad value: " + value;
35}
36
37if (testMap.size !== i)
38 throw "Error: bad value: " + i;
39
40var value = values.next().value;
41if (value !== undefined)
42 throw "Error: bad value: " + value;
43
44var entries = testMap.entries();
45var i = 0;
46do {
47 var {done, value: entry} = entries.next();
48 if (done)
49 break;
50 var [key, value] = entry;
51 if (value !== testMap.get(key))
52 throw "Error: bad value: " + value + " " + testMap.get(key);
53 if (key >= testArray.length)
54 throw "Error: bad value: " + key;
55 i++;
56 if (testArray.indexOf(value) === -1)
57 throw "Error: bad value: " + value + " " + i;
58} while (!done);
59
60if (testMap.size !== i)
61 throw "Error: bad value: " + i;
62
63var value = entries.next().value;
64if (value !== undefined)
65 throw "Error: bad value: " + value;
66
67var entries = testMap.entries();
68var i = 0;
69do {
70 var {done, value: entry} = entries.next();
71 if (done)
72 break;
73 var [key, value] = entry;
74 if (value !== testMap.get(key))
75 throw "Error: bad value: " + value + " " + testMap.get(key);
76 i++;
77 if (i % 4 === 0)
78 testMap.set(100000 + i, i);
79} while (!done);
80
81if (testMap.size !== i)
82 throw "Error: bad value: " + i;
83
84var value = entries.next().value;
85if (value !== undefined)
86 throw "Error: bad value: " + value;
87
88function otherKey(key) {
89 return (key + 1) % testArray.length;
90}
91
92var entries = testMap.entries();
93var i = 0;
94do {
95 var {done, value: entry} = entries.next();
96 if (done)
97 break;
98 var [key, value] = entry;
99 if (value !== testMap.get(key))
100 throw "Error: bad value: " + value + " " + testMap.get(key);
101 i++;
102 if (i % 4 === 0)
103 testMap.delete(otherKey(key));
104} while (!done);
105
106if (testMap.size !== i)
107 throw "Error: bad value: " + i;
108
109var value = entries.next().value;
110if (value !== undefined)
111 throw "Error: bad value: " + value;