summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Statements/for-of-iterator-close-throw.js
blob: 1974e416bef88f369464c3fd3ae9c08c454b1f49 (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
function test() {
    var returnCalled = 0;
    var returnCalledExpected = 0;
    var catchEntered = 0;
    var finallyEntered = 0;
    var finallyEnteredExpected = 0;
    var iterable = {};
    iterable[Symbol.iterator] = makeIterator({
        ret: function() {
            returnCalled++;
            throw 42;
        }
    });

    // inner try cannot catch IteratorClose throwing
    assertThrowsValue(function() {
        for (var x of iterable) {
            try {
                return;
            } catch (e) {
                catchEntered++;
            } finally {
                finallyEntered++;
            }
        }
    }, 42);
    assertEq(returnCalled, ++returnCalledExpected);
    assertEq(catchEntered, 0);
    assertEq(finallyEntered, ++finallyEnteredExpected);
}

test();

if (typeof reportCompare === "function")
    reportCompare(0, 0);