blob: 1a52d113f9757f52dbb6ee15fe4fc739d46dde0c (
plain)
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
|
// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
//
//
/*---
esid: pending
description: Lazy %AsyncIterator.prototype% methods close the iterator if callback throws.
info: >
AsyncIterator Helpers proposal 2.1.6
features: [iterator-helpers]
---*/
class TestError extends Error {}
class TestAsyncIterator extends AsyncIterator {
async next() {
return {done: false, value: 1};
}
closed = false;
async return() {
this.closed = true;
return {done: true};
}
}
function fn() {
throw new TestError();
}
const methods = [
iter => iter.map(fn),
iter => iter.filter(fn),
iter => iter.flatMap(fn),
];
for (const method of methods) {
const iter = new TestAsyncIterator();
assertEq(iter.closed, false);
method(iter).next().then(
_ => assertEq(true, false, 'Expected reject'),
err => {
assertEq(err instanceof TestError, true);
assertEq(iter.closed, true);
},
);
}
if (typeof reportCompare == 'function')
reportCompare(0, 0);
|