1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
//
//
/*---
esid: pending
description: Lazy %AsyncIterator.prototype% method calls can be interleaved.
info: >
Iterator Helpers proposal 2.1.6
features: [iterator-helpers]
---*/
class TestIterator extends AsyncIterator {
value = 0;
async next() {
return {done: false, value: this.value++};
}
}
function unwrapResult(value) {
// Unwrap the asIndexedPair return values.
while (Array.isArray(value)) {
value = value[1];
}
return value;
}
function check({done, value}, expectedDone, expectedValue) {
assertEq(done, expectedDone);
assertEq(unwrapResult(value), expectedValue);
}
const methods = [
['map', x => x],
['filter', x => true],
['take', Infinity],
['drop', 0],
['asIndexedPairs', undefined],
['flatMap', async function*(x) { yield x; }],
];
(async () => {
for (const [firstMethod, firstArg] of methods) {
for (const [secondMethod, secondArg] of methods) {
const iterator = new TestIterator();
const firstHelper = iterator[firstMethod](firstArg);
const secondHelper = iterator[secondMethod](secondArg);
check(await firstHelper.next(), false, 0);
check(await secondHelper.next(), false, 1);
check(await firstHelper.next(), false, 2);
check(await secondHelper.next(), false, 3);
}
}
})();
if (typeof reportCompare == 'function')
reportCompare(0, 0);
|