summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/AsyncIterator/prototype/generator-methods-throw-on-iterator-helpers.js
blob: 0e5b6ac0b59f1a5e583fe53378f0fba5e0f4f08e (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
// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))

const asyncGeneratorProto = Object.getPrototypeOf(
  Object.getPrototypeOf(
    (async function *() {})()
  )
);

const methods = [
  iter => iter.map(x => x),
  iter => iter.filter(x => x),
  iter => iter.take(1),
  iter => iter.drop(0),
  iter => iter.asIndexedPairs(),
  iter => iter.flatMap(x => (async function*() {})()),
];

for (const method of methods) {
  const iteratorHelper = method((async function*() {})());
  asyncGeneratorProto.next.call(iteratorHelper).then(
    _ => assertEq(true, false, 'Expected reject'),
    err => assertEq(err instanceof TypeError, true),
  );
  asyncGeneratorProto.return.call(iteratorHelper).then(
    _ => assertEq(true, false, 'Expected reject'),
    err => assertEq(err instanceof TypeError, true),
  );
  asyncGeneratorProto.throw.call(iteratorHelper).then(
    _ => assertEq(true, false, 'Expected reject'),
    err => assertEq(err instanceof TypeError, true),
  );
}

if (typeof reportCompare == 'function')
  reportCompare(0, 0);