diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Iterator/prototype/iterator-helpers-from-other-global.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/Iterator/prototype/iterator-helpers-from-other-global.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/js/src/tests/non262/Iterator/prototype/iterator-helpers-from-other-global.js b/js/src/tests/non262/Iterator/prototype/iterator-helpers-from-other-global.js new file mode 100644 index 0000000000..d18bd8f00f --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/iterator-helpers-from-other-global.js @@ -0,0 +1,64 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) + +class TestError extends Error {} + +class TestIterator extends Iterator { + next() { + return {done: false, value: 'value'}; + } + + closed = false; + return(value) { + this.closed = true; + return {done: true, value}; + } +} + +function checkIterResult({done, value}, expectedDone, expectedValue) { + assertEq(done, expectedDone); + assertEq(Array.isArray(value) ? value[1] : value, expectedValue); +} + +const otherGlobal = newGlobal({newCompartment: true}); + +const methods = [ + ["map", x => x], + ["filter", x => true], + ["take", Infinity], + ["drop", 0], + ["asIndexedPairs", undefined], + ["flatMap", x => [x]], +]; + +for (const [method, arg] of methods) { + const {next: otherNext} = Object.getPrototypeOf( + new otherGlobal.Array().values()[method](arg) + ); + const iterator = new TestIterator(); + const helper = iterator[method](arg); + checkIterResult(otherNext.call(helper), false, 'value'); +} + +for (const [method, arg] of methods) { + const {return: otherReturn} = Object.getPrototypeOf( + new otherGlobal.Array().values()[method](arg) + ); + const iterator = new TestIterator(); + const helper = iterator[method](arg); + assertEq(iterator.closed, false); + checkIterResult(otherReturn.call(helper), true, undefined); + assertEq(iterator.closed, true); +} + +for (const [method, arg] of methods) { + const {throw: otherThrow} = Object.getPrototypeOf( + new otherGlobal.Array().values()[method](arg) + ); + const iterator = new TestIterator(); + const helper = iterator[method](arg); + assertThrowsInstanceOf(otherThrow.bind(helper, new TestError()), TestError); + checkIterResult(helper.next(), true, undefined); +} + +if (typeof reportCompare === 'function') + reportCompare(0, 0); |