1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +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

@ -102,16 +102,10 @@ ThrowCompletionOr<TemporalDuration> to_temporal_duration_record(GlobalObject& gl
// i. Set any to true.
any = true;
// ii. Let val be ? ToNumber(val).
value = TRY(value.to_number(global_object));
// ii. Let val be 𝔽(? ToIntegerWithoutRounding(val)).
value = Value(TRY(to_integer_without_rounding(global_object, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, property.as_string(), value.to_string_without_side_effects())));
// iii. If ! IsIntegralNumber(val) is false, then
if (!value.is_integral_number()) {
// 1. Throw a RangeError exception.
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, property.as_string(), value.to_string_without_side_effects());
}
// iv. Set result's internal slot whose name is the Internal Slot value of the current row to val.
// iii. Set result's internal slot whose name is the Internal Slot value of the current row to val.
result.*internal_slot = value.as_double();
}
}
@ -198,16 +192,10 @@ ThrowCompletionOr<PartialDuration> to_partial_duration(GlobalObject& global_obje
// i. Set any to true.
any = true;
// ii. Set value to ? ToNumber(value).
value = TRY(value.to_number(global_object));
// ii. Set value to 𝔽(? ToIntegerWithoutRounding(value)).
value = Value(TRY(to_integer_without_rounding(global_object, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, property.as_string(), value.to_string_without_side_effects())));
// iii. If ! IsIntegralNumber(value) is false, then
if (!value.is_integral_number()) {
// 1. Throw a RangeError exception.
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, property.as_string(), value.to_string_without_side_effects());
}
// iv. Set result's internal slot whose name is the Internal Slot value of the current row to value.
// iii. Set result's internal slot whose name is the Internal Slot value of the current row to value.
result.*internal_slot = value.as_double();
}
}