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/TypedArray/iterator-next-with-detached.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/TypedArray/iterator-next-with-detached.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/iterator-next-with-detached.js b/js/src/tests/non262/TypedArray/iterator-next-with-detached.js new file mode 100644 index 0000000000..d6a31160a6 --- /dev/null +++ b/js/src/tests/non262/TypedArray/iterator-next-with-detached.js @@ -0,0 +1,73 @@ +function checkResult(actual, expected) +{ + assertEq(actual.value, expected.value); + assertEq(actual.done, expected.done); +} + +if (typeof detachArrayBuffer === "function" && typeof newGlobal === "function") +{ + var iteratorFunction = Uint8Array.prototype[Symbol.iterator]; + + + var thisGlobal = this; + var otherGlobal = newGlobal(); + + var thisNext = new Uint8Array()[Symbol.iterator]().next + + for (const constructor of typedArrayConstructors) + { + assertEq(new constructor()[Symbol.iterator]().next, thisNext); + + var globals = + [ + [thisGlobal, thisGlobal], + [thisGlobal, otherGlobal], + [otherGlobal, otherGlobal], + [otherGlobal, thisGlobal], + ]; + + for (const [arrayGlobal, bufferGlobal] of globals) + { + var arr, buffer, iterator; + + function arrayBufferIterator() + { + var byteLength = 2 * constructor.BYTES_PER_ELEMENT; + var buf = new bufferGlobal.ArrayBuffer(byteLength); + var tarray = new arrayGlobal[constructor.name](buf); + + tarray[0] = 1; + tarray[1] = 2; + + return [tarray, buf, Reflect.apply(iteratorFunction, tarray, [])]; + } + + [arr, buffer, iterator] = arrayBufferIterator(); + checkResult(thisNext.call(iterator), {value: 1, done: false}); + checkResult(thisNext.call(iterator), {value: 2, done: false}); + checkResult(thisNext.call(iterator), {value: undefined, done: true}); + + // Test an exhausted iterator. + bufferGlobal.detachArrayBuffer(buffer); + checkResult(thisNext.call(iterator), {value: undefined, done: true}); + + // Test an all-but-exhausted iterator. + [arr, buffer, iterator] = arrayBufferIterator(); + checkResult(thisNext.call(iterator), {value: 1, done: false}); + checkResult(thisNext.call(iterator), {value: 2, done: false}); + + bufferGlobal.detachArrayBuffer(buffer); + assertThrowsInstanceOf(() => thisNext.call(iterator), TypeError); + + // Test an unexhausted iterator. + [arr, buffer, iterator] = arrayBufferIterator(); + checkResult(thisNext.call(iterator), {value: 1, done: false}); + + bufferGlobal.detachArrayBuffer(buffer); + assertThrowsInstanceOf(() => thisNext.call(iterator), TypeError); + } + } +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |