summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/program-non-strict.js
blob: c66e298d731c4a7b8ece3e4444fb83f15bbde8fd (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
54
55
56
57
58
59
60
61
"do not use strict";
"no really";
// /\ Valid directives which should not trigger strict mode

test("basic functionality", () => {
    expect(isStrictMode()).toBeFalse();

    (function () {
        expect(isStrictMode()).toBeFalse();
    })();

    (() => {
        expect(isStrictMode()).toBeFalse();
    })();

    (() => {
        expect(isStrictMode()).toBeFalse();
    })();

    function a() {
        expect(isStrictMode()).toBeFalse();
    }

    a();

    eval("expect(isStrictMode()).toBeFalse()");
});

test("functions with strict mode", () => {
    expect(isStrictMode()).toBeFalse();

    function a() {
        "this is allowed trust me";
        "use strict";
        expect(isStrictMode()).toBeTrue();
    }

    a();

    expect(isStrictMode()).toBeFalse();

    (() => {
        "use strict";
        expect(isStrictMode()).toBeTrue();
    })();

    function b() {
        eval("expect(isStrictMode()).toBeFalse()");

        function nested() {
            "use strict";
            eval("expect(isStrictMode()).toBeTrue()");
        }

        nested();

        eval("expect(isStrictMode()).toBeFalse()");
    }

    b();
});