mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibJS: Throw RangeError for non-integral values in ToPartialDuration
This is a normative change in the Temporal spec.
See: 895c8e5
This commit is contained in:
parent
7acd174c85
commit
0e6d503317
2 changed files with 19 additions and 7 deletions
|
@ -214,13 +214,20 @@ PartialDuration to_partial_duration(GlobalObject& global_object, Value temporal_
|
||||||
// i. Set any to true.
|
// i. Set any to true.
|
||||||
any = true;
|
any = true;
|
||||||
|
|
||||||
// ii. Set value to ? ToIntegerOrInfinity(value).
|
// ii. Set value to ? ToNumber(value).
|
||||||
auto value_number = value.to_integer_or_infinity(global_object);
|
value = value.to_number(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// iii. Set result's internal slot whose name is the Internal Slot value of the current row to value.
|
// iii. If ! IsIntegralNumber(value) is false, then
|
||||||
result.*internal_slot = value_number;
|
if (!value.is_integral_number()) {
|
||||||
|
// 1. Throw a RangeError exception.
|
||||||
|
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, property.as_string(), value.to_string_without_side_effects());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// iv. Set result's internal slot whose name is the Internal Slot value of the current row to value.
|
||||||
|
result.*internal_slot = value.as_double();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,14 @@ describe("errors", () => {
|
||||||
|
|
||||||
test("invalid duration value", () => {
|
test("invalid duration value", () => {
|
||||||
for (const property of DURATION_PROPERTIES) {
|
for (const property of DURATION_PROPERTIES) {
|
||||||
|
for (const value of [1.23, NaN, Infinity]) {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new Temporal.Duration().with({ [property]: Infinity });
|
new Temporal.Duration().with({ [property]: value });
|
||||||
}).toThrowWithMessage(RangeError, "Invalid duration");
|
}).toThrowWithMessage(
|
||||||
|
RangeError,
|
||||||
|
`Invalid value for duration property '${property}': must be an integer, got ${value}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue