summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/functions/function-strict-mode.js
blob: 99ec10b9a73ed03116ee7c962493d5a75a9f40c9 (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
test("non strict-mode by default", () => {
    expect(isStrictMode()).toBeFalse();
});

test("use strict with double quotes", () => {
    "use strict";
    expect(isStrictMode()).toBeTrue();
});

// prettier-ignore
test("use strict with single quotes", () => {
    'use strict';
    expect(isStrictMode()).toBeTrue();
});

// prettier-ignore
test("use strict with backticks does not yield strict mode", () => {
    `use strict`;
    expect(isStrictMode()).toBeFalse();
});

// prettier-ignore
test("use strict with single quotes after statement does not yield strict mode code", () => {
    ;'use strict';
    expect(isStrictMode()).toBeFalse();
});

// prettier-ignore
test("use strict with double quotes after statement does not yield strict mode code", () => {
    ;"use strict";
    expect(isStrictMode()).toBeFalse();
});

test("use strict interrupted by a line continuation does not yield strict mode code", () => {
    "use \
strict";
    expect(isStrictMode()).toBeFalse();
});

test("strict mode propagates down the scope chain", () => {
    "use strict";
    expect(isStrictMode()).toBeTrue();
    (function () {
        expect(isStrictMode()).toBeTrue();
    })();
});

test("strict mode does not propagate up the scope chain", () => {
    expect(isStrictMode()).toBeFalse();
    (function () {
        "use strict";
        expect(isStrictMode()).toBeTrue();
    })();
    expect(isStrictMode()).toBeFalse();
});

test('only the string "use strict" yields strict mode code', () => {
    "use stric";
    expect(isStrictMode()).toBeFalse();
});