1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +00:00

LibJS: Normalize NaN values in Sets and Maps

This ensures that different NaN types (e.g. 0/0, 0 * Infinity, etc) are
mapped to the same Set/Map entry.
This commit is contained in:
Idan Horowitz 2022-04-02 15:10:53 +03:00 committed by Linus Groh
parent cc08f82ddb
commit 59080f441e
3 changed files with 26 additions and 0 deletions

View file

@ -9,3 +9,12 @@ test("basic functionality", () => {
expect(map.get("a")).toBe(0);
expect(map.get("d")).toBe(undefined);
});
test("NaN differentiation", () => {
const map = new Map();
map.set(NaN, "a");
expect(map.get(0 / 0)).toBe("a");
expect(map.get(0 * Infinity)).toBe("a");
expect(map.get(Infinity - Infinity)).toBe("a");
});