LibJS: Rename ToIntegerThrowOnInfinity to ToIntegerWithTruncation

This commit ticks away two of the boxes in #15525
Temporal commits: tc39/proposal-temporal@f274678 and
tc39/proposal-temporal@a63a0fb
This commit is contained in:
BodilessSleeper 2023-01-06 03:31:29 +01:00 committed by Linus Groh
parent 18122c0368
commit 90b43712e6
Notes: sideshowbarker 2024-07-17 02:07:21 +09:00
8 changed files with 70 additions and 68 deletions

View file

@ -1725,8 +1725,8 @@ ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(VM& vm, De
// 13.40 ToPositiveIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-topositiveintegerwithtruncation
ThrowCompletionOr<double> to_positive_integer_with_truncation(VM& vm, Value argument)
{
// 1. Let integer be ? ToIntegerThrowOnInfinity(argument).
auto integer = TRY(to_integer_throw_on_infinity(vm, argument, ErrorType::TemporalPropertyMustBePositiveInteger));
// 1. Let integer be ? ToIntegerWithTruncation(argument).
auto integer = TRY(to_integer_with_truncation(vm, argument, ErrorType::TemporalPropertyMustBePositiveInteger));
// 2. If integer ≤ 0, throw a RangeError exception.
if (integer <= 0) {
@ -1761,11 +1761,11 @@ ThrowCompletionOr<Object*> prepare_temporal_fields(VM& vm, Object const& fields,
// ii. If property is in the Property column of Table 15 and there is a Conversion value in the same row, then
// 1. Let Conversion be the Conversion value of the same row.
// 2. If Conversion is ToIntegerThrowOnInfinity, then
// 2. If Conversion is ToIntegerWithTruncation, then
if (property.is_one_of("year"sv, "hour"sv, "minute"sv, "second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv, "eraYear"sv)) {
// a. Set value to ? ToIntegerThrowOnInfinity(value).
// a. Set value to ? ToIntegerWithTruncation(value).
// b. Set value to 𝔽(value).
value = Value(TRY(to_integer_throw_on_infinity(vm, value, ErrorType::TemporalPropertyMustBeFinite)));
value = Value(TRY(to_integer_with_truncation(vm, value, ErrorType::TemporalPropertyMustBeFinite)));
}
// 3. Else if Conversion is ToPositiveIntegerWithTruncation, then
else if (property.is_one_of("month"sv, "day"sv)) {

View file

@ -184,21 +184,24 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
return get_option(vm, options, property, type, Span<StringView const> { values }, default_);
}
// 13.40 ToIntegerThrowOnInfinity ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerthrowoninfinity
// 13.40 ToIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerwithtruncation
template<typename... Args>
ThrowCompletionOr<double> to_integer_throw_on_infinity(VM& vm, Value argument, ErrorType error_type, Args... args)
ThrowCompletionOr<double> to_integer_with_truncation(VM& vm, Value argument, ErrorType error_type, Args... args)
{
// 1. Let integer be ? ToIntegerOrInfinity(argument).
auto integer = TRY(argument.to_integer_or_infinity(vm));
// 1. Let number be ? ToIntegerOrInfinity(argument).
auto number = TRY(argument.to_number(vm));
// 2. If integer is -∞ or +∞ , then
if (Value(integer).is_infinity()) {
// a. Throw a RangeError exception.
// 2. If number is NaN, return 0.
if (number.is_nan())
return 0;
// 3. If number is +∞𝔽 or -∞𝔽, throw a RangeError exception.
if (Value(number).is_infinity()) {
return vm.template throw_completion<RangeError>(error_type, args...);
}
// 3. Return integer.
return integer;
// 4. Return truncate((number)).
return trunc(number.as_double());
}
// 13.41 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral

View file

@ -209,8 +209,8 @@ ThrowCompletionOr<double> calendar_year(VM& vm, Object& calendar, Object& date_l
if (result.is_undefined())
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.undefined.as_string());
// 3. Return ? ToIntegerThrowOnInfinity(result).
return TRY(to_integer_throw_on_infinity(vm, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.Infinity.as_string()));
// 3. Return ? ToIntegerWithTruncation(result).
return TRY(to_integer_with_truncation(vm, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.Infinity.as_string()));
}
// 12.2.9 CalendarMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonth
@ -308,8 +308,7 @@ ThrowCompletionOr<double> calendar_year_of_week(VM& vm, Object& calendar, Object
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.yearOfWeek.as_string(), vm.names.undefined.as_string());
// 3. Return ? ToIntegerWithTruncation(result).
// FIXME: ToIntegerThrowOnInfinity was renamed to ToIntegerWithTruncation in https://github.com/tc39/proposal-temporal/commit/f2746783e808c0144f2ce669e004a8c6286f9fc7
return TRY(to_integer_throw_on_infinity(vm, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.yearOfWeek.as_string(), vm.names.Infinity.to_string()));
return TRY(to_integer_with_truncation(vm, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.yearOfWeek.as_string(), vm.names.Infinity.to_string()));
}
// 12.2.16 CalendarDaysInWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinweek
@ -402,9 +401,9 @@ ThrowCompletionOr<Value> calendar_era_year(VM& vm, Object& calendar, Object& dat
// 2. Let result be ? Invoke(calendar, "eraYear", « dateLike »).
auto result = TRY(Value(&calendar).invoke(vm, vm.names.eraYear, &date_like));
// 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result).
// 3. If result is not undefined, set result to ? ToIntegerWithTruncation(result).
if (!result.is_undefined())
result = Value(TRY(to_integer_throw_on_infinity(vm, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)));
result = Value(TRY(to_integer_with_truncation(vm, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)));
// 4. Return result.
return result;

View file

@ -50,14 +50,14 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PlainDateConstructor::construct(Function
{
auto& vm = this->vm();
// 2. Let y be ? ToIntegerThrowOnInfinity(isoYear).
auto y = TRY(to_integer_throw_on_infinity(vm, vm.argument(0), ErrorType::TemporalInvalidPlainDate));
// 2. Let y be ? ToIntegerWithTruncation(isoYear).
auto y = TRY(to_integer_with_truncation(vm, vm.argument(0), ErrorType::TemporalInvalidPlainDate));
// 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = TRY(to_integer_throw_on_infinity(vm, vm.argument(1), ErrorType::TemporalInvalidPlainDate));
// 3. Let m be ? ToIntegerWithTruncation(isoMonth).
auto m = TRY(to_integer_with_truncation(vm, vm.argument(1), ErrorType::TemporalInvalidPlainDate));
// 4. Let d be ? ToIntegerThrowOnInfinity(isoDay).
auto d = TRY(to_integer_throw_on_infinity(vm, vm.argument(2), ErrorType::TemporalInvalidPlainDate));
// 4. Let d be ? ToIntegerWithTruncation(isoDay).
auto d = TRY(to_integer_with_truncation(vm, vm.argument(2), ErrorType::TemporalInvalidPlainDate));
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, vm.argument(3)));

View file

@ -50,32 +50,32 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PlainDateTimeConstructor::construct(Func
{
auto& vm = this->vm();
// 2. Let isoYear be ? ToIntegerThrowOnInfinity(isoYear).
auto iso_year = TRY(to_integer_throw_on_infinity(vm, vm.argument(0), ErrorType::TemporalInvalidPlainDateTime));
// 2. Let isoYear be ? ToIntegerWithTruncation(isoYear).
auto iso_year = TRY(to_integer_with_truncation(vm, vm.argument(0), ErrorType::TemporalInvalidPlainDateTime));
// 3. Let isoMonth be ? ToIntegerThrowOnInfinity(isoMonth).
auto iso_month = TRY(to_integer_throw_on_infinity(vm, vm.argument(1), ErrorType::TemporalInvalidPlainDateTime));
// 3. Let isoMonth be ? ToIntegerWithTruncation(isoMonth).
auto iso_month = TRY(to_integer_with_truncation(vm, vm.argument(1), ErrorType::TemporalInvalidPlainDateTime));
// 4. Let isoDay be ? ToIntegerThrowOnInfinity(isoDay).
auto iso_day = TRY(to_integer_throw_on_infinity(vm, vm.argument(2), ErrorType::TemporalInvalidPlainDateTime));
// 4. Let isoDay be ? ToIntegerWithTruncation(isoDay).
auto iso_day = TRY(to_integer_with_truncation(vm, vm.argument(2), ErrorType::TemporalInvalidPlainDateTime));
// 5. Let hour be ? ToIntegerThrowOnInfinity(hour).
auto hour = TRY(to_integer_throw_on_infinity(vm, vm.argument(3), ErrorType::TemporalInvalidPlainDateTime));
// 5. Let hour be ? ToIntegerWithTruncation(hour).
auto hour = TRY(to_integer_with_truncation(vm, vm.argument(3), ErrorType::TemporalInvalidPlainDateTime));
// 6. Let minute be ? ToIntegerThrowOnInfinity(minute).
auto minute = TRY(to_integer_throw_on_infinity(vm, vm.argument(4), ErrorType::TemporalInvalidPlainDateTime));
// 6. Let minute be ? ToIntegerWithTruncation(minute).
auto minute = TRY(to_integer_with_truncation(vm, vm.argument(4), ErrorType::TemporalInvalidPlainDateTime));
// 7. Let second be ? ToIntegerThrowOnInfinity(second).
auto second = TRY(to_integer_throw_on_infinity(vm, vm.argument(5), ErrorType::TemporalInvalidPlainDateTime));
// 7. Let second be ? ToIntegerWithTruncation(second).
auto second = TRY(to_integer_with_truncation(vm, vm.argument(5), ErrorType::TemporalInvalidPlainDateTime));
// 8. Let millisecond be ? ToIntegerThrowOnInfinity(millisecond).
auto millisecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(6), ErrorType::TemporalInvalidPlainDateTime));
// 8. Let millisecond be ? ToIntegerWithTruncation(millisecond).
auto millisecond = TRY(to_integer_with_truncation(vm, vm.argument(6), ErrorType::TemporalInvalidPlainDateTime));
// 9. Let microsecond be ? ToIntegerThrowOnInfinity(microsecond).
auto microsecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(7), ErrorType::TemporalInvalidPlainDateTime));
// 9. Let microsecond be ? ToIntegerWithTruncation(microsecond).
auto microsecond = TRY(to_integer_with_truncation(vm, vm.argument(7), ErrorType::TemporalInvalidPlainDateTime));
// 10. Let nanosecond be ? ToIntegerThrowOnInfinity(nanosecond).
auto nanosecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(8), ErrorType::TemporalInvalidPlainDateTime));
// 10. Let nanosecond be ? ToIntegerWithTruncation(nanosecond).
auto nanosecond = TRY(to_integer_with_truncation(vm, vm.argument(8), ErrorType::TemporalInvalidPlainDateTime));
// 11. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, vm.argument(9)));

View file

@ -59,17 +59,17 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PlainMonthDayConstructor::construct(Func
reference_iso_year = Value(1972);
}
// 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = TRY(to_integer_throw_on_infinity(vm, iso_month, ErrorType::TemporalInvalidPlainMonthDay));
// 3. Let m be ? ToIntegerWithTruncation(isoMonth).
auto m = TRY(to_integer_with_truncation(vm, iso_month, ErrorType::TemporalInvalidPlainMonthDay));
// 4. Let d be ? ToIntegerThrowOnInfinity(isoDay).
auto d = TRY(to_integer_throw_on_infinity(vm, iso_day, ErrorType::TemporalInvalidPlainMonthDay));
// 4. Let d be ? ToIntegerWithTruncation(isoDay).
auto d = TRY(to_integer_with_truncation(vm, iso_day, ErrorType::TemporalInvalidPlainMonthDay));
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, calendar_like));
// 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISOYear).
auto ref = TRY(to_integer_throw_on_infinity(vm, reference_iso_year, ErrorType::TemporalInvalidPlainMonthDay));
// 6. Let ref be ? ToIntegerWithTruncation(referenceISOYear).
auto ref = TRY(to_integer_with_truncation(vm, reference_iso_year, ErrorType::TemporalInvalidPlainMonthDay));
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
// This does not change the exposed behavior as the call to CreateTemporalMonthDay will immediately check that these values are valid

View file

@ -48,23 +48,23 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PlainTimeConstructor::construct(Function
{
auto& vm = this->vm();
// 2. Let hour be ? ToIntegerThrowOnInfinity(hour).
auto hour = TRY(to_integer_throw_on_infinity(vm, vm.argument(0), ErrorType::TemporalInvalidPlainTime));
// 2. Let hour be ? ToIntegerWithTruncation(hour).
auto hour = TRY(to_integer_with_truncation(vm, vm.argument(0), ErrorType::TemporalInvalidPlainTime));
// 3. Let minute be ? ToIntegerThrowOnInfinity(hour).
auto minute = TRY(to_integer_throw_on_infinity(vm, vm.argument(1), ErrorType::TemporalInvalidPlainTime));
// 3. Let minute be ? ToIntegerWithTruncation(hour).
auto minute = TRY(to_integer_with_truncation(vm, vm.argument(1), ErrorType::TemporalInvalidPlainTime));
// 4. Let second be ? ToIntegerThrowOnInfinity(hour).
auto second = TRY(to_integer_throw_on_infinity(vm, vm.argument(2), ErrorType::TemporalInvalidPlainTime));
// 4. Let second be ? ToIntegerWithTruncation(hour).
auto second = TRY(to_integer_with_truncation(vm, vm.argument(2), ErrorType::TemporalInvalidPlainTime));
// 5. Let millisecond be ? ToIntegerThrowOnInfinity(hour).
auto millisecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(3), ErrorType::TemporalInvalidPlainTime));
// 5. Let millisecond be ? ToIntegerWithTruncation(hour).
auto millisecond = TRY(to_integer_with_truncation(vm, vm.argument(3), ErrorType::TemporalInvalidPlainTime));
// 6. Let microsecond be ? ToIntegerThrowOnInfinity(hour).
auto microsecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(4), ErrorType::TemporalInvalidPlainTime));
// 6. Let microsecond be ? ToIntegerWithTruncation(hour).
auto microsecond = TRY(to_integer_with_truncation(vm, vm.argument(4), ErrorType::TemporalInvalidPlainTime));
// 7. Let nanosecond be ? ToIntegerThrowOnInfinity(hour).
auto nanosecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(5), ErrorType::TemporalInvalidPlainTime));
// 7. Let nanosecond be ? ToIntegerWithTruncation(hour).
auto nanosecond = TRY(to_integer_with_truncation(vm, vm.argument(5), ErrorType::TemporalInvalidPlainTime));
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
// This does not change the exposed behavior as the call to CreateTemporalTime will immediately check that these values are valid

View file

@ -61,17 +61,17 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PlainYearMonthConstructor::construct(Fun
reference_iso_day = Value(1);
}
// 3. Let y be ? ToIntegerThrowOnInfinity(isoYear).
auto y = TRY(to_integer_throw_on_infinity(vm, iso_year, ErrorType::TemporalInvalidPlainYearMonth));
// 3. Let y be ? ToIntegerWithTruncation(isoYear).
auto y = TRY(to_integer_with_truncation(vm, iso_year, ErrorType::TemporalInvalidPlainYearMonth));
// 4. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = TRY(to_integer_throw_on_infinity(vm, iso_month, ErrorType::TemporalInvalidPlainYearMonth));
// 4. Let m be ? ToIntegerWithTruncation(isoMonth).
auto m = TRY(to_integer_with_truncation(vm, iso_month, ErrorType::TemporalInvalidPlainYearMonth));
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, calendar_like));
// 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISODay).
auto ref = TRY(to_integer_throw_on_infinity(vm, reference_iso_day, ErrorType::TemporalInvalidPlainYearMonth));
// 6. Let ref be ? ToIntegerWithTruncation(referenceISODay).
auto ref = TRY(to_integer_with_truncation(vm, reference_iso_day, ErrorType::TemporalInvalidPlainYearMonth));
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
// This does not change the exposed behavior as the call to CreateTemporalYearMonth will immediately check that these values are valid