summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/to-number-exception.js
blob: 0deec450d5be4da13b25d2561171cfeb1a6abe77 (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
load("test-common.js");

try {
    const message = "oops, Value::to_number() failed";
    const o = { toString() { throw new Error(message); } };

    assertThrowsError(() => {
        +o;
    }, {
        error: Error,
        message
    });

    assertThrowsError(() => {
        o - 1;
    }, {
        error: Error,
        message
    });

    assertThrowsError(() => {
        "foo".charAt(o);
    }, {
        error: Error,
        message
    });

    assertThrowsError(() => {
        "bar".repeat(o);
    }, {
        error: Error,
        message
    });

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