summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/Symbol.keyFor.js
blob: 56e3ed9d815277c9b0d860dcf7a42d3c2432d1c3 (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
load("test-common.js")

try {
    const localSym = Symbol("foo");
    const globalSym = Symbol.for("foo");

    assert(Symbol.keyFor(localSym) === undefined);
    assert(Symbol.keyFor(globalSym) === "foo");

    const testThrows = (value, str) => {
        assertThrowsError(() => {
            Symbol.keyFor(value);
        }, {
            error: TypeError,
            message: str + " is not a symbol",
        });
    };

    testThrows(1, "1");
    testThrows(null, "null");
    testThrows(undefined, "undefined");
    testThrows([], "[object Array]");
    testThrows({}, "[object Object]");
    testThrows(true, "true");
    testThrows("foobar", "foobar");
    testThrows(function(){}, "[object ScriptFunction]"); // FIXME: Better function stringification

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