diff options
Diffstat (limited to 'js/src/tests/non262/Iterator/prototype/lazy-methods-iterator-not-closed-on-value-throws.js')
-rw-r--r-- | js/src/tests/non262/Iterator/prototype/lazy-methods-iterator-not-closed-on-value-throws.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/js/src/tests/non262/Iterator/prototype/lazy-methods-iterator-not-closed-on-value-throws.js b/js/src/tests/non262/Iterator/prototype/lazy-methods-iterator-not-closed-on-value-throws.js new file mode 100644 index 0000000000..1ca88ca9b5 --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/lazy-methods-iterator-not-closed-on-value-throws.js @@ -0,0 +1,48 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) + +// +// +/*--- +esid: pending +description: Lazy %Iterator.prototype% methods don't close the iterator if `value` throws. +info: > + Iterator Helpers proposal 2.1.5 +features: [iterator-helpers] +---*/ + +class TestError extends Error {} +class TestIterator extends Iterator { + next() { + return { + get value() { + throw new TestError(); + } + }; + } + + closed = false; + return() { + this.closed = true; + return {done: true}; + } +} + +const iterator = new TestIterator(); + +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 => [x]), +]; + +for (const method of methods) { + assertEq(iterator.closed, false); + assertThrowsInstanceOf(() => method(iterator).next(), TestError); + assertEq(iterator.closed, false); +} + +if (typeof reportCompare == 'function') + reportCompare(0, 0); |