summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Array/iterator_edge_cases.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Array/iterator_edge_cases.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Array/iterator_edge_cases.js')
-rw-r--r--js/src/tests/non262/Array/iterator_edge_cases.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/js/src/tests/non262/Array/iterator_edge_cases.js b/js/src/tests/non262/Array/iterator_edge_cases.js
new file mode 100644
index 0000000000..156aaba5f1
--- /dev/null
+++ b/js/src/tests/non262/Array/iterator_edge_cases.js
@@ -0,0 +1,50 @@
+// Test that we can't confuse %ArrayIteratorPrototype% for an
+// ArrayIterator object.
+function TestArrayIteratorPrototypeConfusion() {
+ var iter = [][Symbol.iterator]();
+ try {
+ iter.next.call(Object.getPrototypeOf(iter))
+ throw new Error("Call did not throw");
+ } catch (e) {
+ assertEq(e instanceof TypeError, true);
+ assertEq(e.message, "next method called on incompatible Array Iterator");
+ }
+}
+TestArrayIteratorPrototypeConfusion();
+
+// Tests that we can use %ArrayIteratorPrototype%.next on a
+// cross-compartment iterator.
+function TestArrayIteratorWrappers() {
+ var iter = [][Symbol.iterator]();
+ assertDeepEq(iter.next.call(newGlobal().eval('[5][Symbol.iterator]()')),
+ { value: 5, done: false })
+}
+if (typeof newGlobal === "function") {
+ TestArrayIteratorWrappers();
+}
+
+// Tests that calling |next| on an array iterator after iteration has finished
+// doesn't get the array's |length| property.
+function TestIteratorNextGetLength() {
+ var lengthCalledTimes = 0;
+ var array = {
+ __proto__: Array.prototype,
+ get length() {
+ lengthCalledTimes += 1;
+ return {
+ valueOf() {
+ return 0;
+ }
+ };
+ }
+ };
+ var it = array[Symbol.iterator]();
+ it.next();
+ it.next();
+ assertEq(1, lengthCalledTimes);
+}
+TestIteratorNextGetLength();
+
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);