1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:57:45 +00:00

LibJS: Add and use newly introduced ToIntegerThrowOnInfinity Temporal AO

See: 2ed58f4
This commit is contained in:
Linus Groh 2021-08-17 20:17:12 +01:00
parent 4073fe497a
commit d46c531023
7 changed files with 84 additions and 199 deletions

View file

@ -5,6 +5,7 @@
*/
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
#include <LibJS/Runtime/Temporal/Calendar.h>
#include <LibJS/Runtime/Temporal/PlainYearMonth.h>
#include <LibJS/Runtime/Temporal/PlainYearMonthConstructor.h>
@ -56,44 +57,26 @@ Value PlainYearMonthConstructor::construct(FunctionObject& new_target)
reference_iso_day = Value(1);
}
// 3. Let y be ? ToIntegerOrInfinity(isoYear).
auto y = iso_year.to_integer_or_infinity(global_object);
// 3. Let y be ? ToIntegerThrowOnInfinity(isoYear).
auto y = to_integer_throw_on_infinity(global_object, iso_year, ErrorType::TemporalInvalidPlainYearMonth);
if (vm.exception())
return {};
// 4. If y is +∞ or -∞, throw a RangeError exception.
if (Value(y).is_infinity()) {
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidPlainYearMonth);
return {};
}
// 5. Let m be ? ToIntegerOrInfinity(isoMonth).
auto m = iso_month.to_integer_or_infinity(global_object);
// 4. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainYearMonth);
if (vm.exception())
return {};
// 6. If m is +∞ or -∞, throw a RangeError exception.
if (Value(m).is_infinity()) {
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidPlainYearMonth);
return {};
}
// 7. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = to_temporal_calendar_with_iso_default(global_object, calendar_like);
if (vm.exception())
return {};
// 8. Let ref be ? ToIntegerOrInfinity(referenceISODay).
auto ref = reference_iso_day.to_integer_or_infinity(global_object);
// 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISODay).
auto ref = to_integer_throw_on_infinity(global_object, reference_iso_day, ErrorType::TemporalInvalidPlainYearMonth);
if (vm.exception())
return {};
// 9. If ref is +∞ or -∞, throw a RangeError exception.
if (Value(ref).is_infinity()) {
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidPlainYearMonth);
return {};
}
// 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 behaviour as the call to CreateTemporalYearMonth will immediately check that these values are valid
// ISO values (for years: -273975 - 273975, for months: 1 - 12, for days: 1 - 31) all of which are subsets of this check.
@ -102,7 +85,7 @@ Value PlainYearMonthConstructor::construct(FunctionObject& new_target)
return {};
}
// 10. Return ? CreateTemporalYearMonth(y, m, calendar, ref, NewTarget).
// 7. Return ? CreateTemporalYearMonth(y, m, calendar, ref, NewTarget).
return create_temporal_year_month(global_object, y, m, *calendar, ref, &new_target);
}