summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/bug1273858-1.js
blob: 89769ffe583f4f84069f8b9e550b3f068d0212d4 (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
// |jit-test| --no-threads

function t1() {
    let x = [];

    for (let k = 0; k < 100; ++k)
        x[k] = () => k; // Lexical capture

    try {
        eval("k");
        throw false;
    }
    catch (e) {
        if (!(e instanceof ReferenceError))
            throw "Loop index escaped block";
    }

    for (var i = 0; i < 100; ++i)
        if (x[i]() != i)
            throw "Bad let capture";
}
t1();
t1();
t1();
t1();

function t2() {
    let x = [];
    let y = {};

    for (var i = 0; i < 100; ++i)
        x[i] = i;

    for (const k of x)
        y[k] = () => k; // Lexical capture

    try {
        eval("k");
        throw false;
    }
    catch (e) {
        if (!(e instanceof ReferenceError))
            throw "Loop index escaped block";
    }

    for (var i = 0; i < 100; ++i)
        if (y[i]() != i)
            throw "Bad const capture";
}
t2();
t2();
t2();
t2();