diff options
Diffstat (limited to 'js/src/tests/non262/AsyncIterator/prototype/async-iterator-helpers-from-other-global.js')
-rw-r--r-- | js/src/tests/non262/AsyncIterator/prototype/async-iterator-helpers-from-other-global.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/js/src/tests/non262/AsyncIterator/prototype/async-iterator-helpers-from-other-global.js b/js/src/tests/non262/AsyncIterator/prototype/async-iterator-helpers-from-other-global.js new file mode 100644 index 0000000000..f8b8d719cd --- /dev/null +++ b/js/src/tests/non262/AsyncIterator/prototype/async-iterator-helpers-from-other-global.js @@ -0,0 +1,65 @@ +// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator')) + +class TestError extends Error {} + +class TestIterator extends AsyncIterator { + async next() { + return {done: false, value: 'value'}; + } + + closed = false; + async 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", async function*(x) { yield x; }], +]; + +const {next: otherNext, return: otherReturn, throw: otherThrow} = + Object.getPrototypeOf(otherGlobal.eval("(async function*() {})().map(x => x)")); + +(async () => { + for (const [method, arg] of methods) { + const iterator = new TestIterator(); + const helper = iterator[method](arg); + checkIterResult(await otherNext.call(helper), false, 'value'); + } + + for (const [method, arg] of methods) { + const iterator = new TestIterator(); + const helper = iterator[method](arg); + assertEq(iterator.closed, false); + checkIterResult(await otherReturn.call(helper), true, undefined); + assertEq(iterator.closed, true); + } + + for (const [method, arg] of methods) { + const iterator = new TestIterator(); + const helper = iterator[method](arg); + try { + await otherThrow.call(helper, new TestError()); + assertEq(true, false, 'Expected exception'); + } catch (exc) { + assertEq(exc instanceof TestError, true); + } + checkIterResult(await helper.next(), true, undefined); + } +})(); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); |