summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/for-of/value-done-access.js
blob: 49028a7746eb64459fff891d23dbf046c18167e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Test that each yield* loop just checks "done", and "value" is only
// fetched once at the end.

load(libdir + 'iteration.js');

var log = "";

function Iter(val, count) {
    function next() {
        return {
            get done() { log += "d"; return count-- == 0; },
            get value() { log += "v"; return val; }
        }
    }

    this[Symbol.iterator] = function() { return this; };
    this.next = next;
}

for (var x of new Iter(42, 5))
    assertEq(x, 42);

assertEq(log, "dvdvdvdvdvd");