summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/AsyncIterator/prototype/lazy-methods-throw-eagerly-on-non-iterator.js
blob: 1a61f5001aa39ad488d782fcb7453bea35d14725 (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
// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))

//
//
/*---
esid: pending
description: Lazy %AsyncIterator.prototype% methods throw eagerly when called on non-iterators.
info: >
  AsyncIterator Helpers proposal 1.1.1
features: [iterator-helpers]
---*/

async function* gen(x) { yield x; }

const methods = [
  iter => AsyncIterator.prototype.map.bind(iter, x => x),
  iter => AsyncIterator.prototype.filter.bind(iter, x => x),
  iter => AsyncIterator.prototype.take.bind(iter, 1),
  iter => AsyncIterator.prototype.drop.bind(iter, 0),
  iter => AsyncIterator.prototype.asIndexedPairs.bind(iter),
  iter => AsyncIterator.prototype.flatMap.bind(iter, gen),
];

for (const method of methods) {
  for (const value of [undefined, null, 0, false, '', Symbol(''), {}, []]) {
    assertThrowsInstanceOf(method(value), TypeError);
  }
}

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