summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/var-scoping.js
blob: 4d3cfd3a2e76e2103546c76cd19ae4f6cbcf32c8 (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
test("basic functionality", () => {
    function foo() {
        i = 3;
        expect(i).toBe(3);
        var i;
    }

    foo();

    var caught_exception;
    try {
        j = i;
    } catch (e) {
        caught_exception = e;
    }
    expect(caught_exception).not.toBeUndefined();
});

test("Issue #8198 arrow function escapes function scope", () => {
    const b = 3;

    function f() {
        expect(b).toBe(3);
        (() => {
            expect(b).toBe(3);
            var a = "wat";
            eval("var b=a;");
            expect(b).toBe("wat");
        })();
        expect(b).toBe(3);
    }

    f();
    expect(b).toBe(3);
});