summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js
blob: 430b0fde562ed09064820678bb8cc5f7549fb597 (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
describe("[[IsExtensible]] trap normal behavior", () => {
    test("forwarding when not defined in handler", () => {
        expect(Object.isExtensible(new Proxy({}, { isExtensible: null }))).toBeTrue();
        expect(Object.isExtensible(new Proxy({}, { isExtensible: undefined }))).toBeTrue();
        expect(Object.isExtensible(new Proxy({}, {}))).toBeTrue();
    });

    test("correct arguments supplied to trap", () => {
        let o = {};
        let p = new Proxy(o, {
            isExtensible(target) {
                expect(target).toBe(o);
                return true;
            },
        });

        expect(Object.isExtensible(p)).toBeTrue();
    });
});

describe("[[Call]] invariants", () => {
    test("return value must match the target's extensibility", () => {
        let o = {};
        Object.preventExtensions(o);

        let p = new Proxy(o, {
            isExtensible() {
                return true;
            },
        });

        expect(() => {
            Object.isExtensible(p);
        }).toThrowWithMessage(
            TypeError,
            "Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility"
        );
    });
});