1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

LibJS: Disallow Temporal.Duration input values to be non-integers

This is a normative change in the Temporal spec.

See: 8c85450
This commit is contained in:
Linus Groh 2021-11-17 22:20:59 +00:00
parent 92708746c8
commit ec1e1f4f12
6 changed files with 60 additions and 48 deletions

View file

@ -39,6 +39,13 @@ describe("correct behavior", () => {
expectDurationOneToTen(duration);
});
test("NaN value becomes zero", () => {
// NOTE: NaN does *not* throw a RangeError anymore - which is questionable, IMO - as of:
// https://github.com/tc39/proposal-temporal/commit/8c854507a52efbc6e9eb2642f0f928df38e5c021
const duration = Temporal.Duration.from({ years: "foo" });
expect(duration.years).toBe(0);
});
// Un-skip once ParseTemporalDurationString is implemented
test.skip("Duration string argument", () => {
const duration = Temporal.Duration.from("TODO");
@ -60,11 +67,5 @@ describe("errors", () => {
RangeError,
"Invalid value for duration property 'years': must be an integer, got 1.2" // ...29999999999999 - let's not include that in the test :^)
);
expect(() => {
Temporal.Duration.from({ years: "foo" });
}).toThrowWithMessage(
RangeError,
"Invalid value for duration property 'years': must be an integer, got NaN"
);
});
});