diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index af56b1e760..df93af001d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -1725,8 +1725,8 @@ ThrowCompletionOr parse_temporal_year_month_string(VM& vm, De // 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)); + // 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 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)) { diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index dff5bee65b..90eedf0062 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -184,21 +184,24 @@ ThrowCompletionOr get_option(VM& vm, Object const& options, PropertyKey c return get_option(vm, options, property, type, Span { 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 -ThrowCompletionOr to_integer_throw_on_infinity(VM& vm, Value argument, ErrorType error_type, Args... args) +ThrowCompletionOr 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(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 diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index 5e60c59692..3929a4e04d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -209,8 +209,8 @@ ThrowCompletionOr calendar_year(VM& vm, Object& calendar, Object& date_l if (result.is_undefined()) return vm.throw_completion(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 calendar_year_of_week(VM& vm, Object& calendar, Object return vm.throw_completion(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 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; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp index 64515508f6..3a3c017ae9 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp @@ -50,14 +50,14 @@ ThrowCompletionOr> 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))); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp index 58eabd06a1..5c5225f3bb 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp @@ -50,32 +50,32 @@ ThrowCompletionOr> 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))); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp index 161d5eec9a..f2f9a35111 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp @@ -59,17 +59,17 @@ ThrowCompletionOr> 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 diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp index a99ae83b10..a45acaf43a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp @@ -48,23 +48,23 @@ ThrowCompletionOr> 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 diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp index f89a7433c3..1e65ade25d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp @@ -61,17 +61,17 @@ ThrowCompletionOr> 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