Explorar o código

LibJS: Rename ToPositiveInteger -> ToPositiveIntegerWithTruncation

This commit ticks away one of the boxes in #15525
Temporal commit: tc39/proposal-temporal@768b916
BodilessSleeper %!s(int64=2) %!d(string=hai) anos
pai
achega
1f1b2f4d26

+ 6 - 7
Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp

@@ -1722,15 +1722,14 @@ ThrowCompletionOr<TemporalYearMonth> 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<double> to_positive_integer(VM& vm, Value argument)
+// 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));
 
-    // 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<RangeError>(ErrorType::TemporalPropertyMustBePositiveInteger);
     }
 
@@ -1768,11 +1767,11 @@ ThrowCompletionOr<Object*> 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)) {

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h

@@ -174,7 +174,7 @@ ThrowCompletionOr<ISODateTime> parse_temporal_relative_to_string(VM&, Deprecated
 ThrowCompletionOr<TemporalTime> parse_temporal_time_string(VM&, DeprecatedString const& iso_string);
 ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(VM&, DeprecatedString const& iso_string);
 ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(VM&, DeprecatedString const& iso_string);
-ThrowCompletionOr<double> to_positive_integer(VM&, Value argument);
+ThrowCompletionOr<double> to_positive_integer_with_truncation(VM&, Value argument);
 ThrowCompletionOr<Object*> prepare_temporal_fields(VM&, Object const& fields, Vector<DeprecatedString> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields);
 ThrowCompletionOr<DifferenceSettings> get_difference_settings(VM&, DifferenceOperation, Value options_value, UnitGroup unit_group, Vector<StringView> const& disallowed_units, TemporalUnitDefault const& fallback_smallest_unit, StringView smallest_largest_default_unit);
 

+ 18 - 18
Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp

@@ -223,8 +223,8 @@ ThrowCompletionOr<double> calendar_month(VM& vm, Object& calendar, Object& date_
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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<double> calendar_day(VM& vm, Object& calendar, Object& date_li
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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<Value> calendar_day_of_week(VM& vm, Object& calendar, Object&
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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<Value> calendar_day_of_year(VM& vm, Object& calendar, Object&
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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<Value> calendar_week_of_year(VM& vm, Object& calendar, Object&
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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<Value> calendar_days_in_week(VM& vm, Object& calendar, Object&
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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<double> calendar_days_in_month(VM& vm, Object& calendar, Objec
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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<Value> calendar_days_in_year(VM& vm, Object& calendar, Object&
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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<Value> calendar_months_in_year(VM& vm, Object& calendar, Objec
     if (result.is_undefined())
         return vm.throw_completion<RangeError>(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