1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +00:00

LibJS: Allow BigInts as destructuring property names

These are simply treated as their numerical value which means that above
2^32 - 1 they are strings.
This commit is contained in:
davidot 2022-08-20 00:24:30 +02:00 committed by Linus Groh
parent e663504df1
commit fce2b33758
3 changed files with 37 additions and 1 deletions

View file

@ -28,3 +28,26 @@ test("numeric properties", () => {
"4294967296", // >= 2^32 - 1
]);
});
test("big int properties", () => {
const o = {
[-1n]: "foo",
0n: "foo",
1n: "foo",
[12345678901n]: "foo",
[4294967294n]: "foo",
[4294967295n]: "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",
"4294967294",
// Non-numeric properties
"-1",
"12345678901", // >= 2^32 - 1
"4294967295", // >= 2^32 - 1
]);
});