diff options
author | Linus Groh <mail@linusgroh.de> | 2021-09-15 23:03:38 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-16 22:34:24 +0100 |
commit | 683e31e1ff6bab4743171312acc0919d968931bd (patch) | |
tree | 461ca65e3565f07d46e03b17449691bc8d959ae7 /Userland/Libraries/LibJS/Runtime/Temporal | |
parent | fea27143e9db0812ed433372255214449d3cb8ab (diff) | |
download | serenity-683e31e1ff6bab4743171312acc0919d968931bd.zip |
LibJS: Convert to_integer_throw_on_infinity() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal')
10 files changed, 46 insertions, 125 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 57830621b0..bba238bc0d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -1087,9 +1087,7 @@ double to_positive_integer(GlobalObject& global_object, Value argument) auto& vm = global_object.vm(); // 1. Let integer be ? ToIntegerThrowOnInfinity(argument). - auto integer = to_integer_throw_on_infinity(global_object, argument, ErrorType::TemporalPropertyMustBePositiveInteger); - if (vm.exception()) - return {}; + auto integer = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, argument, ErrorType::TemporalPropertyMustBePositiveInteger)); // 2. If integer ≤ 0, then if (integer <= 0) { @@ -1141,9 +1139,7 @@ Object* prepare_temporal_fields(GlobalObject& global_object, Object const& field // 1. Let Conversion represent the abstract operation named by the Conversion value of the same row. // 2. Set value to ? Conversion(value). if (property.is_one_of("year", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", "eraYear")) { - value = Value(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite)); - if (vm.exception()) - return {}; + value = Value(TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite))); } else if (property.is_one_of("month", "day")) { value = Value(to_positive_integer(global_object, value)); if (vm.exception()) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index 19b962a867..3e65418028 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -11,6 +11,7 @@ #include <AK/String.h> #include <AK/Variant.h> #include <LibJS/Forward.h> +#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/GlobalObject.h> namespace JS::Temporal { @@ -116,20 +117,19 @@ Object* prepare_temporal_fields(GlobalObject&, Object const& fields, Vector<Stri // 13.46 ToIntegerThrowOnInfinity ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerthrowoninfinity template<typename... Args> -double to_integer_throw_on_infinity(GlobalObject& global_object, Value argument, ErrorType error_type, Args... args) +ThrowCompletionOr<double> to_integer_throw_on_infinity(GlobalObject& global_object, Value argument, ErrorType error_type, Args... args) { auto& vm = global_object.vm(); // 1. Let integer be ? ToIntegerOrInfinity(argument). auto integer = argument.to_integer_or_infinity(global_object); - if (vm.exception()) - return {}; + if (auto* exception = vm.exception()) + return throw_completion(exception->value()); // 2. If integer is −∞ or +∞ , then if (Value(integer).is_infinity()) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, error_type, args...); - return {}; + return vm.template throw_completion<RangeError>(global_object, error_type, args...); } // 3. Return integer. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index 725a3767b4..b0ff02bac3 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -138,7 +138,7 @@ double calendar_year(GlobalObject& global_object, Object& calendar, Object& date } // 4. Return ? ToIntegerThrowOnInfinity(result). - return to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.Infinity.as_string()); + return TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.Infinity.as_string())); } // 12.1.10 CalendarMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonth @@ -321,11 +321,8 @@ Value calendar_era_year(GlobalObject& global_object, Object& calendar, Object& d return {}; // 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result). - if (!result.is_undefined()) { - result = Value(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)); - if (vm.exception()) - return {}; - } + if (!result.is_undefined()) + result = Value(TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv))); // 4. Return result. return result; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp index ae09029d66..83cf7a9364 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp @@ -51,54 +51,34 @@ Value DurationConstructor::construct(FunctionObject& new_target) auto& global_object = this->global_object(); // 2. Let y be ? ToIntegerThrowOnInfinity(years). - auto y = to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto y = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidDuration)); // 3. Let mo be ? ToIntegerThrowOnInfinity(months). - auto mo = to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto mo = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidDuration)); // 4. Let w be ? ToIntegerThrowOnInfinity(weeks). - auto w = to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto w = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidDuration)); // 5. Let d be ? ToIntegerThrowOnInfinity(days). - auto d = to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto d = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidDuration)); // 6. Let h be ? ToIntegerThrowOnInfinity(hours). - auto h = to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto h = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidDuration)); // 7. Let m be ? ToIntegerThrowOnInfinity(minutes). - auto m = to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto m = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidDuration)); // 8. Let s be ? ToIntegerThrowOnInfinity(seconds). - auto s = to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto s = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidDuration)); // 9. Let ms be ? ToIntegerThrowOnInfinity(milliseconds). - auto ms = to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto ms = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidDuration)); // 10. Let mis be ? ToIntegerThrowOnInfinity(microseconds). - auto mis = to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto mis = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidDuration)); // 11. Let ns be ? ToIntegerThrowOnInfinity(nanoseconds). - auto ns = to_integer_throw_on_infinity(global_object, vm.argument(9), ErrorType::TemporalInvalidDuration); - if (vm.exception()) - return {}; + auto ns = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(9), ErrorType::TemporalInvalidDuration)); // 12. Return ? CreateTemporalDuration(y, mo, w, d, h, m, s, ms, mis, ns, NewTarget). return create_temporal_duration(global_object, y, mo, w, d, h, m, s, ms, mis, ns, &new_target); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp index 3d4032288c..c7268df52c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp @@ -53,19 +53,13 @@ Value PlainDateConstructor::construct(FunctionObject& new_target) auto& global_object = this->global_object(); // 2. Let y be ? ToIntegerThrowOnInfinity(isoYear). - auto y = to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDate); - if (vm.exception()) - return {}; + auto y = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDate)); // 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth). - auto m = to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDate); - if (vm.exception()) - return {}; + auto m = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDate)); // 4. Let d be ? ToIntegerThrowOnInfinity(isoDay). - auto d = to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDate); - if (vm.exception()) - return {}; + auto d = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDate)); // 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). auto* calendar = to_temporal_calendar_with_iso_default(global_object, vm.argument(3)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp index 59a37dd6f4..9cc2a6c281 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp @@ -53,49 +53,31 @@ Value PlainDateTimeConstructor::construct(FunctionObject& new_target) auto& global_object = this->global_object(); // 2. Let isoYear be ? ToIntegerThrowOnInfinity(isoYear). - auto iso_year = to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto iso_year = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDateTime)); // 3. Let isoMonth be ? ToIntegerThrowOnInfinity(isoMonth). - auto iso_month = to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto iso_month = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDateTime)); // 4. Let isoDay be ? ToIntegerThrowOnInfinity(isoDay). - auto iso_day = to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto iso_day = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDateTime)); // 5. Let hour be ? ToIntegerThrowOnInfinity(hour). - auto hour = to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto hour = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainDateTime)); // 6. Let minute be ? ToIntegerThrowOnInfinity(minute). - auto minute = to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto minute = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainDateTime)); // 7. Let second be ? ToIntegerThrowOnInfinity(second). - auto second = to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto second = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainDateTime)); // 8. Let millisecond be ? ToIntegerThrowOnInfinity(millisecond). - auto millisecond = to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto millisecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidPlainDateTime)); // 9. Let microsecond be ? ToIntegerThrowOnInfinity(microsecond). - auto microsecond = to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto microsecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidPlainDateTime)); // 10. Let nanosecond be ? ToIntegerThrowOnInfinity(nanosecond). - auto nanosecond = to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidPlainDateTime); - if (vm.exception()) - return {}; + auto nanosecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidPlainDateTime)); // 11. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). auto* calendar = to_temporal_calendar_with_iso_default(global_object, vm.argument(9)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp index 61023460c7..0e50d60c7a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp @@ -62,14 +62,10 @@ Value PlainMonthDayConstructor::construct(FunctionObject& new_target) } // 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth). - auto m = to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainMonthDay); - if (vm.exception()) - return {}; + auto m = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainMonthDay)); // 4. Let d be ? ToIntegerThrowOnInfinity(isoDay). - auto d = to_integer_throw_on_infinity(global_object, iso_day, ErrorType::TemporalInvalidPlainMonthDay); - if (vm.exception()) - return {}; + auto d = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, iso_day, ErrorType::TemporalInvalidPlainMonthDay)); // 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). auto* calendar = to_temporal_calendar_with_iso_default(global_object, calendar_like); @@ -77,9 +73,7 @@ Value PlainMonthDayConstructor::construct(FunctionObject& new_target) return {}; // 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISOYear). - auto ref = to_integer_throw_on_infinity(global_object, reference_iso_year, ErrorType::TemporalInvalidPlainMonthDay); - if (vm.exception()) - return {}; + auto ref = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, 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/PlainTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp index 26481f7777..9fbc90bd53 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp @@ -154,9 +154,7 @@ ThrowCompletionOr<PartialUnregulatedTemporalTime> to_partial_time(GlobalObject& any = true; // ii. Set value to ? ToIntegerThrowOnInfinity(value). - auto value_number = to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto value_number = TRY(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite)); // iii. Set result's internal slot whose name is the Internal Slot value of the current row to value. result.*internal_slot = value_number; @@ -384,9 +382,7 @@ ThrowCompletionOr<UnregulatedTemporalTime> to_temporal_time_record(GlobalObject& } // d. Set value to ? ToIntegerThrowOnInfinity(value). - auto value_number = to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto value_number = TRY(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite)); // e. Set result's internal slot whose name is the Internal Slot value of the current row to value. result.*internal_slot = value_number; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp index 4381322484..d6cf430838 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp @@ -51,34 +51,22 @@ Value PlainTimeConstructor::construct(FunctionObject& new_target) auto& global_object = this->global_object(); // 2. Let hour be ? ToIntegerThrowOnInfinity(hour). - auto hour = to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainTime); - if (vm.exception()) - return {}; + auto hour = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainTime)); // 3. Let minute be ? ToIntegerThrowOnInfinity(hour). - auto minute = to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainTime); - if (vm.exception()) - return {}; + auto minute = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainTime)); // 4. Let second be ? ToIntegerThrowOnInfinity(hour). - auto second = to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainTime); - if (vm.exception()) - return {}; + auto second = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainTime)); // 5. Let millisecond be ? ToIntegerThrowOnInfinity(hour). - auto millisecond = to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainTime); - if (vm.exception()) - return {}; + auto millisecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainTime)); // 6. Let microsecond be ? ToIntegerThrowOnInfinity(hour). - auto microsecond = to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainTime); - if (vm.exception()) - return {}; + auto microsecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainTime)); // 7. Let nanosecond be ? ToIntegerThrowOnInfinity(hour). - auto nanosecond = to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainTime); - if (vm.exception()) - return {}; + auto nanosecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, 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 45d8e52976..b3e3b0cc9a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp @@ -64,14 +64,10 @@ Value PlainYearMonthConstructor::construct(FunctionObject& new_target) } // 3. Let y be ? ToIntegerThrowOnInfinity(isoYear). - auto y = to_integer_throw_on_infinity(global_object, iso_year, ErrorType::TemporalInvalidPlainYearMonth); - if (vm.exception()) - return {}; + auto y = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, iso_year, ErrorType::TemporalInvalidPlainYearMonth)); // 4. Let m be ? ToIntegerThrowOnInfinity(isoMonth). - auto m = to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainYearMonth); - if (vm.exception()) - return {}; + auto m = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainYearMonth)); // 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). auto* calendar = to_temporal_calendar_with_iso_default(global_object, calendar_like); @@ -79,9 +75,7 @@ Value PlainYearMonthConstructor::construct(FunctionObject& new_target) return {}; // 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISODay). - auto ref = to_integer_throw_on_infinity(global_object, reference_iso_day, ErrorType::TemporalInvalidPlainYearMonth); - if (vm.exception()) - return {}; + auto ref = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, 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 |