Bug 1016936 - Part 4: Add test for IteratorNext with non-object returned by iterator.next(). r=jorendorff
authorTooru Fujisawa <arai_a@mac.com>
Wed, 10 Aug 2016 22:26:08 +0900
changeset 308894 9286619fafa0907c79c0f4ac712ca09d10ddc4b5
parent 308893 494760e727953aa80b28fb948ff1d8fc6196ba4b
child 308895 b706d46a20e55fcea6517f627113519a1d426c51
push id30552
push userkwierso@gmail.com
push dateWed, 10 Aug 2016 23:15:29 +0000
treeherdermozilla-central@65520f4cf4cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1016936
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1016936 - Part 4: Add test for IteratorNext with non-object returned by iterator.next(). r=jorendorff
js/src/tests/ecma_6/Generators/iterator-next-non-object.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/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);