summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/Reflect.apply.js
blob: 15060eea4c609f237f9b244e83432932a9fc718e (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
load("test-common.js");

try {
    assert(Reflect.apply.length === 3);

    [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
        assertThrowsError(() => {
            Reflect.apply(value);
        }, {
            error: TypeError,
            message: "First argument of Reflect.apply() must be a function"
        });

        assertThrowsError(() => {
            Reflect.apply(() => {}, undefined, value);
        }, {
            error: TypeError,
            message: "Arguments list must be an object"
        });
    });

    assert(Reflect.apply(String.prototype.charAt, "foo", [0]) === "f");
    assert(Reflect.apply(Array.prototype.indexOf, ["hello", 123, "foo", "bar"], ["foo"]) === 2);

    function Foo(foo) {
        this.foo = foo;
    }

    var o = {};
    assert(o.foo === undefined);
    assert(Reflect.apply(Foo, o, ["bar"]) === undefined);
    assert(o.foo === "bar");

    console.log("PASS");
} catch (e) {
    console.log("FAIL: " + e);
}