diff options
author | Linus Groh <mail@linusgroh.de> | 2021-09-16 18:02:55 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-16 22:34:24 +0100 |
commit | 9ac426c906a75fa80f1dea612fcff44f4481cb56 (patch) | |
tree | 2204399fe253f05928175822de36ce451023a151 | |
parent | 2f56fd48cab2ba11dfd317c3b3a05f33f747c353 (diff) | |
download | serenity-9ac426c906a75fa80f1dea612fcff44f4481cb56.zip |
LibJS: Convert to_positive_integer() to ThrowCompletionOr
3 files changed, 7 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index e0800b6684..2b4f3c32a4 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -1020,18 +1020,17 @@ ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObje } // 13.46 ToPositiveInteger ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-topositiveinteger -double to_positive_integer(GlobalObject& global_object, Value argument) +ThrowCompletionOr<double> to_positive_integer(GlobalObject& global_object, Value argument) { auto& vm = global_object.vm(); // 1. Let integer be ? ToIntegerThrowOnInfinity(argument). - auto integer = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, argument, ErrorType::TemporalPropertyMustBePositiveInteger)); + auto integer = TRY(to_integer_throw_on_infinity(global_object, argument, ErrorType::TemporalPropertyMustBePositiveInteger)); // 2. If integer ≤ 0, then if (integer <= 0) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalPropertyMustBePositiveInteger); - return {}; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalPropertyMustBePositiveInteger); } // 3. Return integer. @@ -1079,9 +1078,7 @@ Object* prepare_temporal_fields(GlobalObject& global_object, Object const& field if (property.is_one_of("year", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", "eraYear")) { 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()) - return {}; + value = Value(TRY_OR_DISCARD(to_positive_integer(global_object, value))); } else if (property.is_one_of("monthCode", "offset", "era")) { value = value.to_primitive_string(global_object); if (vm.exception()) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index dfe8c5ffd5..130c6c1ad9 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -112,7 +112,7 @@ ThrowCompletionOr<TemporalDuration> parse_temporal_duration_string(GlobalObject& ThrowCompletionOr<TemporalTime> parse_temporal_time_string(GlobalObject&, String const& iso_string); ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject&, String const& iso_string); ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject&, String const& iso_string); -double to_positive_integer(GlobalObject&, Value argument); +ThrowCompletionOr<double> to_positive_integer(GlobalObject&, Value argument); Object* prepare_temporal_fields(GlobalObject&, Object const& fields, Vector<String> const& field_names, Vector<StringView> const& required_fields); // 13.46 ToIntegerThrowOnInfinity ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerthrowoninfinity diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index debcd22cd8..e225e41dfd 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -157,7 +157,7 @@ double calendar_month(GlobalObject& global_object, Object& calendar, Object& dat } // 4. Return ? ToPositiveInteger(result). - return to_positive_integer(global_object, result); + return TRY_OR_DISCARD(to_positive_integer(global_object, result)); } // 12.1.11 CalendarMonthCode ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthcode @@ -199,7 +199,7 @@ double calendar_day(GlobalObject& global_object, Object& calendar, Object& date_ } // 4. Return ? ToPositiveInteger(result). - return to_positive_integer(global_object, result); + return TRY_OR_DISCARD(to_positive_integer(global_object, result)); } // 12.1.13 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek |