mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibJS: Migrate ToIntegerIfIntegral to ECMA-262
This is an editorial change in the Temporal proposal. See:
5f76109
This commit is contained in:
parent
a8d6e5c3db
commit
aa737bb654
Notes:
github-actions[bot]
2025-03-01 13:50:37 +00:00
Author: https://github.com/trflynn89
Commit: aa737bb654
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3734
3 changed files with 16 additions and 16 deletions
|
@ -325,6 +325,21 @@ struct YearWeek {
|
|||
Optional<i32> year;
|
||||
};
|
||||
|
||||
// 14.5.1.1 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral
|
||||
template<typename... Args>
|
||||
ThrowCompletionOr<double> to_integer_if_integral(VM& vm, Value argument, ErrorType error_type, Args&&... args)
|
||||
{
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
auto number = TRY(argument.to_number(vm));
|
||||
|
||||
// 2. If number is not an integral Number, throw a RangeError exception.
|
||||
if (!number.is_integral_number())
|
||||
return vm.throw_completion<RangeError>(error_type, forward<Args>(args)...);
|
||||
|
||||
// 3. Return ℝ(number).
|
||||
return number.as_double();
|
||||
}
|
||||
|
||||
enum class OptionType {
|
||||
Boolean,
|
||||
String,
|
||||
|
|
|
@ -209,7 +209,7 @@ ThrowCompletionOr<DurationRecord> to_duration_record(VM& vm, Value input)
|
|||
auto value = TRY(input_object.get(name));
|
||||
|
||||
if (!value.is_undefined()) {
|
||||
value_slot = TRY(Temporal::to_integer_if_integral(vm, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, name, value));
|
||||
value_slot = TRY(to_integer_if_integral(vm, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, name, value));
|
||||
any_defined = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -243,19 +243,4 @@ ThrowCompletionOr<double> to_positive_integer_with_truncation(VM& vm, Value argu
|
|||
return integer;
|
||||
}
|
||||
|
||||
// 13.39 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral
|
||||
template<typename... Args>
|
||||
ThrowCompletionOr<double> to_integer_if_integral(VM& vm, Value argument, ErrorType error_type, Args&&... args)
|
||||
{
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
auto number = TRY(argument.to_number(vm));
|
||||
|
||||
// 2. If number is not an integral Number, throw a RangeError exception.
|
||||
if (!number.is_integral_number())
|
||||
return vm.throw_completion<RangeError>(error_type, forward<Args>(args)...);
|
||||
|
||||
// 3. Return ℝ(number).
|
||||
return number.as_double();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue