1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:17:45 +00:00

LibJS: Fix toFixed throwing on undefined, null and NaN fractionDigits

It was checking the original fractionDigits argument was a finite
number instead of the coerced fraction_digits.
This commit is contained in:
Luke Wilde 2021-12-26 14:15:09 +00:00 committed by Linus Groh
parent dfb994f62d
commit 2d26a50d28
2 changed files with 6 additions and 2 deletions

View file

@ -15,6 +15,10 @@ describe("correct behavior", () => {
// Numbers >= 1e+21
[1e21, 5, "1e+21"],
[1e22, 0, "1e+22"],
// undefined, null and NaN are treated as 0 due to toFixed using ToIntegerOrInfinity.
[1.1, undefined, "1"],
[1.1, null, "1"],
[1.1, NaN, "1"],
].forEach(testCase => {
expect(testCase[0].toFixed(testCase[1])).toBe(testCase[2]);
});
@ -37,7 +41,7 @@ describe("errors", () => {
});
test("fixed digits RangeError", () => {
[-Infinity, -5, 105, Infinity, NaN].forEach(value => {
[-Infinity, -5, 105, Infinity].forEach(value => {
expect(() => (0).toFixed(value)).toThrow(RangeError);
});
});