From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- ...y-methods-multiple-throw-close-iterator-once.js | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 js/src/tests/non262/AsyncIterator/prototype/lazy-methods-multiple-throw-close-iterator-once.js (limited to 'js/src/tests/non262/AsyncIterator/prototype/lazy-methods-multiple-throw-close-iterator-once.js') diff --git a/js/src/tests/non262/AsyncIterator/prototype/lazy-methods-multiple-throw-close-iterator-once.js b/js/src/tests/non262/AsyncIterator/prototype/lazy-methods-multiple-throw-close-iterator-once.js new file mode 100644 index 0000000000..45e88be26a --- /dev/null +++ b/js/src/tests/non262/AsyncIterator/prototype/lazy-methods-multiple-throw-close-iterator-once.js @@ -0,0 +1,90 @@ +// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator')) + +// +// +/*--- +esid: pending +description: Calling `throw` on a lazy %AsyncIterator.prototype% method multiple times closes the source iterator once. +info: > + Iterator Helpers proposal 2.1.6 +features: [iterator-helpers] +---*/ + +class TestError extends Error {} + +class TestIterator extends AsyncIterator { + async next() { + return {done: false, value: 1}; + } + + closeCount = 0; + async return(value) { + this.closeCount++; + return {done: true, value}; + } +} + +async function* gen(x) { yield x; } + +const methods = [ + iter => iter.map(x => x), + iter => iter.filter(x => true), + iter => iter.take(Infinity), + iter => iter.drop(0), + iter => iter.asIndexedPairs(), + iter => iter.flatMap(gen), +]; + +(async () => { + // Call `throw` after stepping the iterator once: + for (const method of methods) { + const iter = new TestIterator(); + const iterHelper = method(iter); + + await iterHelper.next() + assertEq(iter.closeCount, 0); + + try { + await iterHelper.throw(new TestError()); + assertEq(true, false, 'Expected reject'); + } catch (exc) { + assertEq(exc instanceof TestError, true); + } + assertEq(iter.closeCount, 1); + + try { + await iterHelper.throw(new TestError()); + assertEq(true, false, 'Expected reject'); + } catch (exc) { + assertEq(exc instanceof TestError, true); + } + assertEq(iter.closeCount, 1); + } + + // Call `throw` before stepping the iterator: + for (const method of methods) { + const iter = new TestIterator(); + const iterHelper = method(iter); + + assertEq(iter.closeCount, 0); + + try { + await iterHelper.throw(new TestError()); + assertEq(true, false, 'Expected reject'); + } catch (exc) { + assertEq(exc instanceof TestError, true); + } + assertEq(iter.closeCount, 1); + + try { + await iterHelper.throw(new TestError()); + assertEq(true, false, 'Expected reject'); + } catch (exc) { + assertEq(exc instanceof TestError, true); + } + assertEq(iter.closeCount, 1); + } +})(); + +if (typeof reportCompare == 'function') + reportCompare(0, 0); -- cgit v1.2.3