summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/object-expression-numeric-property.js
blob: 575e658390e764faa19aa766cd2c5c0e8f6d045d (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
test("numeric properties", () => {
    const i32Max = 2 ** 31 - 1;
    const u32Max = 2 ** 32 - 1;
    const o = {
        [-1]: "foo",
        0: "foo",
        1: "foo",
        [i32Max - 1]: "foo",
        [i32Max]: "foo",
        [i32Max + 1]: "foo",
        [u32Max - 1]: "foo",
        [u32Max]: "foo",
        [u32Max + 1]: "foo",
    };
    // Numeric properties come first in Object.getOwnPropertyNames()'s output,
    // which means we can test what each is treated as internally.
    expect(Object.getOwnPropertyNames(o)).toEqual([
        // Numeric properties
        "0",
        "1",
        "2147483646",
        "2147483647",
        "2147483648",
        "4294967294",
        // Non-numeric properties
        "-1",
        "4294967295", // >= 2^32 - 1
        "4294967296", // >= 2^32 - 1
    ]);
});