summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/for-of/next-shenanigans.js
blob: f57b04e12ef689db56e00c35d8ebcea10b131d66 (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
// Test for-of with iter.next and monkeypatching.

function* g(n) { for (var i=0; i<n; i++) yield i; }
var GeneratorObjectPrototype = Object.getPrototypeOf(g).prototype;
var GeneratorObjectPrototype_next = GeneratorObjectPrototype.next;

// Monkeypatch next on an iterator.
var inner = g(20);
var n = 0;
for (let x of inner) {
    assertEq(x, n++);
    if (n == 1) {
        inner.next = function() { throw 'not reached'; };
    }
}
assertEq(n, 20);

// Monkeypatch next on the prototype.
var inner = g(20);
var n = 0;
for (let x of inner) {
    assertEq(x, n++);
    if (n == 1) {
        GeneratorObjectPrototype.next = function() { throw 'not reached'; };
    }
}
assertEq(n, 20);