From 1f1b2f4d26778ad92cef81843a66bff3f845bc79 Mon Sep 17 00:00:00 2001 From: BodilessSleeper Date: Sat, 31 Dec 2022 03:17:56 +0100 Subject: [PATCH] LibJS: Rename ToPositiveInteger -> ToPositiveIntegerWithTruncation This commit ticks away one of the boxes in #15525 Temporal commit: tc39/proposal-temporal@768b916 --- .../Runtime/Temporal/AbstractOperations.cpp | 13 ++++--- .../Runtime/Temporal/AbstractOperations.h | 2 +- .../LibJS/Runtime/Temporal/Calendar.cpp | 36 +++++++++---------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index a02d3ef495..11cbad9dc8 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -1722,15 +1722,14 @@ ThrowCompletionOr parse_temporal_year_month_string(VM& vm, De return TemporalYearMonth { .year = result.year, .month = result.month, .day = result.day, .calendar = move(result.calendar) }; } -// 13.40 ToPositiveInteger ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-topositiveinteger -ThrowCompletionOr to_positive_integer(VM& vm, Value argument) +// 13.40 ToPositiveIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-topositiveintegerwithtruncation +ThrowCompletionOr 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)); - // 2. If integer ≤ 0, then + // 2. If integer ≤ 0, throw a RangeError exception. if (integer <= 0) { - // a. Throw a RangeError exception. return vm.throw_completion(ErrorType::TemporalPropertyMustBePositiveInteger); } @@ -1768,11 +1767,11 @@ ThrowCompletionOr prepare_temporal_fields(VM& vm, Object const& fields, // b. Set value to 𝔽(value). value = Value(TRY(to_integer_throw_on_infinity(vm, value, ErrorType::TemporalPropertyMustBeFinite))); } - // 3. Else if Conversion is ToPositiveInteger, then + // 3. Else if Conversion is ToPositiveIntegerWithTruncation, then else if (property.is_one_of("month"sv, "day"sv)) { - // a. Set value to ? ToPositiveInteger(value). + // a. Set value to ? ToPositiveIntegerWithTruncation(value). // b. Set value to 𝔽(value). - value = Value(TRY(to_positive_integer(vm, value))); + value = Value(TRY(to_positive_integer_with_truncation(vm, value))); } // 4. Else, else if (property.is_one_of("monthCode"sv, "offset"sv, "era"sv)) { diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index cfe3b36829..dff5bee65b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -174,7 +174,7 @@ ThrowCompletionOr parse_temporal_relative_to_string(VM&, Deprecated ThrowCompletionOr parse_temporal_time_string(VM&, DeprecatedString const& iso_string); ThrowCompletionOr parse_temporal_time_zone_string(VM&, DeprecatedString const& iso_string); ThrowCompletionOr parse_temporal_year_month_string(VM&, DeprecatedString const& iso_string); -ThrowCompletionOr to_positive_integer(VM&, Value argument); +ThrowCompletionOr to_positive_integer_with_truncation(VM&, Value argument); ThrowCompletionOr prepare_temporal_fields(VM&, Object const& fields, Vector const& field_names, Variant> const& required_fields); ThrowCompletionOr get_difference_settings(VM&, DifferenceOperation, Value options_value, UnitGroup unit_group, Vector const& disallowed_units, TemporalUnitDefault const& fallback_smallest_unit, StringView smallest_largest_default_unit); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index 94c7e15206..b9f705f301 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -223,8 +223,8 @@ ThrowCompletionOr calendar_month(VM& vm, Object& calendar, Object& date_ if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.month.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.10 CalendarMonthCode ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthcode @@ -251,8 +251,8 @@ ThrowCompletionOr calendar_day(VM& vm, Object& calendar, Object& date_li if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.day.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.12 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek @@ -265,8 +265,8 @@ ThrowCompletionOr calendar_day_of_week(VM& vm, Object& calendar, Object& if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.dayOfWeek.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.13 CalendarDayOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofyear @@ -279,8 +279,8 @@ ThrowCompletionOr calendar_day_of_year(VM& vm, Object& calendar, Object& if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.dayOfYear.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.14 CalendarWeekOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarweekofyear @@ -293,8 +293,8 @@ ThrowCompletionOr calendar_week_of_year(VM& vm, Object& calendar, Object& if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.weekOfYear.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.15 CalendarYearOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryearofweek @@ -322,8 +322,8 @@ ThrowCompletionOr calendar_days_in_week(VM& vm, Object& calendar, Object& if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.daysInWeek.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.17 CalendarDaysInMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinmonth @@ -336,8 +336,8 @@ ThrowCompletionOr calendar_days_in_month(VM& vm, Object& calendar, Objec if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.daysInMonth.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.18 CalendarDaysInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinyear @@ -350,8 +350,8 @@ ThrowCompletionOr calendar_days_in_year(VM& vm, Object& calendar, Object& if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.daysInYear.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.19 CalendarMonthsInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthsinyear @@ -364,8 +364,8 @@ ThrowCompletionOr calendar_months_in_year(VM& vm, Object& calendar, Objec if (result.is_undefined()) return vm.throw_completion(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.monthsInYear.as_string(), vm.names.undefined.as_string()); - // 2. Return ? ToPositiveInteger(result). - return TRY(to_positive_integer(vm, result)); + // 2. Return ? ToPositiveIntegerWithTruncation(result). + return TRY(to_positive_integer_with_truncation(vm, result)); } // 12.2.20 CalendarInLeapYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarinleapyear