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.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.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/iterator.js b/js/src/tests/non262/TypedArray/iterator.js new file mode 100644 index 0000000000..3f943aa70d --- /dev/null +++ b/js/src/tests/non262/TypedArray/iterator.js @@ -0,0 +1,42 @@ +// Ensure that we're using [[ArrayLength]] to determine the number of +// values to produce instead of the length property. + +function testIterationCount(iterator, expectedLength) { + for (let i = 0; i < expectedLength; i++) + assertEq(iterator.next().done, false); + assertEq(iterator.next().done, true); +} + +let i8Array = new Int8Array(4); +Object.defineProperty(i8Array, "length", {value: 0}); +let i8Iterator = i8Array[Symbol.iterator](); +testIterationCount(i8Iterator, 4); + +// Veryify that the length property isn't even touched +i8Array = new Int8Array(); +Object.defineProperty(i8Array, "length", { + get() { + throw TypeError; + } +}); +i8Iterator = i8Array[Symbol.iterator](); +testIterationCount(i8Iterator, 0); + +// Verify that it works for set as well +i8Array = new Uint8Array(1); +// Try setting a high length which would trigger failure +Object.defineProperty(i8Array, "length", {value: 15}); +// Works if the fake length is ignored +(new Uint8Array(4)).set(i8Array, 3); + +// Ensure that it works across globals +let g2 = newGlobal(); + +i8Array = new Int8Array(8); +Object.defineProperty(i8Array, "length", {value: 0}); +let iterator = i8Array[Symbol.iterator](); +iterator.next = g2.Array.prototype[Symbol.iterator]().next; +testIterationCount(iterator, 8); + +if (typeof reportCompare === "function") + reportCompare(true, true); |