mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
LibJS: Convert to_positive_integer() to ThrowCompletionOr
This commit is contained in:
parent
2f56fd48ca
commit
9ac426c906
3 changed files with 7 additions and 10 deletions
|
@ -1020,18 +1020,17 @@ ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObje
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.46 ToPositiveInteger ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-topositiveinteger
|
// 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();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
// 1. Let integer be ? ToIntegerThrowOnInfinity(argument).
|
// 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
|
// 2. If integer ≤ 0, then
|
||||||
if (integer <= 0) {
|
if (integer <= 0) {
|
||||||
// a. Throw a RangeError exception.
|
// a. Throw a RangeError exception.
|
||||||
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalPropertyMustBePositiveInteger);
|
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalPropertyMustBePositiveInteger);
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Return integer.
|
// 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")) {
|
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)));
|
value = Value(TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite)));
|
||||||
} else if (property.is_one_of("month", "day")) {
|
} else if (property.is_one_of("month", "day")) {
|
||||||
value = Value(to_positive_integer(global_object, value));
|
value = Value(TRY_OR_DISCARD(to_positive_integer(global_object, value)));
|
||||||
if (vm.exception())
|
|
||||||
return {};
|
|
||||||
} else if (property.is_one_of("monthCode", "offset", "era")) {
|
} else if (property.is_one_of("monthCode", "offset", "era")) {
|
||||||
value = value.to_primitive_string(global_object);
|
value = value.to_primitive_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
|
|
|
@ -112,7 +112,7 @@ ThrowCompletionOr<TemporalDuration> parse_temporal_duration_string(GlobalObject&
|
||||||
ThrowCompletionOr<TemporalTime> parse_temporal_time_string(GlobalObject&, String const& iso_string);
|
ThrowCompletionOr<TemporalTime> parse_temporal_time_string(GlobalObject&, String const& iso_string);
|
||||||
ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_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);
|
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);
|
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
|
// 13.46 ToIntegerThrowOnInfinity ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerthrowoninfinity
|
||||||
|
|
|
@ -157,7 +157,7 @@ double calendar_month(GlobalObject& global_object, Object& calendar, Object& dat
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Return ? ToPositiveInteger(result).
|
// 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
|
// 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).
|
// 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
|
// 12.1.13 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek
|
||||||
|
|
Loading…
Add table
Reference in a new issue