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