summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/generators/iterator-next-non-object.js
blob: 453f4cd87663a49e431f5a31dfdedbf462c1b873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);