summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/generators/iterator-next-non-object.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/generators/iterator-next-non-object.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/generators/iterator-next-non-object.js')
-rw-r--r--js/src/tests/non262/generators/iterator-next-non-object.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/js/src/tests/non262/generators/iterator-next-non-object.js b/js/src/tests/non262/generators/iterator-next-non-object.js
new file mode 100644
index 0000000000..453f4cd876
--- /dev/null
+++ b/js/src/tests/non262/generators/iterator-next-non-object.js
@@ -0,0 +1,64 @@
+var BUGNUMBER = 1016936;
+var summary = "IteratorNext should throw if the value returned by iterator.next() is not an object.";
+
+print(BUGNUMBER + ": " + summary);
+
+var nonobjs = [
+ null,
+ undefined,
+ 1,
+ true,
+ "a",
+ Symbol.iterator,
+];
+
+function createIterable(v) {
+ var iterable = {};
+ iterable[Symbol.iterator] = function () {
+ return {
+ next: function () {
+ return v;
+ }
+ };
+ };
+ return iterable;
+}
+
+function f() {
+}
+
+for (var nonobj of nonobjs) {
+ var iterable = createIterable(nonobj);
+
+ assertThrowsInstanceOf(() => [...iterable], TypeError);
+ assertThrowsInstanceOf(() => f(...iterable), TypeError);
+
+ assertThrowsInstanceOf(() => { for (var x of iterable) {} }, TypeError);
+
+ assertThrowsInstanceOf(() => {
+ var [a] = iterable;
+ }, TypeError);
+ assertThrowsInstanceOf(() => {
+ var [...a] = iterable;
+ }, TypeError);
+
+ assertThrowsInstanceOf(() => Array.from(iterable), TypeError);
+ assertThrowsInstanceOf(() => new Map(iterable), TypeError);
+ assertThrowsInstanceOf(() => new Set(iterable), TypeError);
+ assertThrowsInstanceOf(() => new WeakMap(iterable), TypeError);
+ assertThrowsInstanceOf(() => new WeakSet(iterable), TypeError);
+ // FIXME: bug 1232266
+ // assertThrowsInstanceOf(() => new Int8Array(iterable), TypeError);
+ assertThrowsInstanceOf(() => Int8Array.from(iterable), TypeError);
+
+ assertThrowsInstanceOf(() => {
+ var g = function*() {
+ yield* iterable;
+ };
+ var v = g();
+ v.next();
+ }, TypeError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);