diff --git a/Libraries/LibJS/Runtime/AbstractOperations.h b/Libraries/LibJS/Runtime/AbstractOperations.h index e4f0740eebb..2bb1a0ef3ef 100644 --- a/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Libraries/LibJS/Runtime/AbstractOperations.h @@ -325,6 +325,21 @@ struct YearWeek { Optional year; }; +// 14.5.1.1 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral +template +ThrowCompletionOr 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(error_type, forward(args)...); + + // 3. Return ℝ(number). + return number.as_double(); +} + enum class OptionType { Boolean, String, diff --git a/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index abbe230158d..39705c1deb6 100644 --- a/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -209,7 +209,7 @@ ThrowCompletionOr 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; } diff --git a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index 0979b606715..ae3d038490b 100644 --- a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -243,19 +243,4 @@ ThrowCompletionOr to_positive_integer_with_truncation(VM& vm, Value argu return integer; } -// 13.39 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral -template -ThrowCompletionOr 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(error_type, forward(args)...); - - // 3. Return ℝ(number). - return number.as_double(); -} - }