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

LibJS: Convert to_integer_throw_on_infinity() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-09-15 23:03:38 +01:00
parent fea27143e9
commit 683e31e1ff
10 changed files with 46 additions and 125 deletions

View file

@ -1087,9 +1087,7 @@ 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 = to_integer_throw_on_infinity(global_object, argument, ErrorType::TemporalPropertyMustBePositiveInteger); auto integer = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, argument, ErrorType::TemporalPropertyMustBePositiveInteger));
if (vm.exception())
return {};
// 2. If integer ≤ 0, then // 2. If integer ≤ 0, then
if (integer <= 0) { 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. // 1. Let Conversion represent the abstract operation named by the Conversion value of the same row.
// 2. Set value to ? Conversion(value). // 2. Set value to ? Conversion(value).
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(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)));
if (vm.exception())
return {};
} 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(to_positive_integer(global_object, value));
if (vm.exception()) if (vm.exception())

View file

@ -11,6 +11,7 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/Variant.h> #include <AK/Variant.h>
#include <LibJS/Forward.h> #include <LibJS/Forward.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
namespace JS::Temporal { 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 // 13.46 ToIntegerThrowOnInfinity ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerthrowoninfinity
template<typename... Args> 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(); auto& vm = global_object.vm();
// 1. Let integer be ? ToIntegerOrInfinity(argument). // 1. Let integer be ? ToIntegerOrInfinity(argument).
auto integer = argument.to_integer_or_infinity(global_object); auto integer = argument.to_integer_or_infinity(global_object);
if (vm.exception()) if (auto* exception = vm.exception())
return {}; return throw_completion(exception->value());
// 2. If integer is −∞ or +∞ , then // 2. If integer is −∞ or +∞ , then
if (Value(integer).is_infinity()) { if (Value(integer).is_infinity()) {
// a. Throw a RangeError exception. // a. Throw a RangeError exception.
vm.throw_exception<RangeError>(global_object, error_type, args...); return vm.template throw_completion<RangeError>(global_object, error_type, args...);
return {};
} }
// 3. Return integer. // 3. Return integer.

View file

@ -138,7 +138,7 @@ double calendar_year(GlobalObject& global_object, Object& calendar, Object& date
} }
// 4. Return ? ToIntegerThrowOnInfinity(result). // 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 // 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 {}; return {};
// 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result). // 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result).
if (!result.is_undefined()) { if (!result.is_undefined())
result = Value(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)); result = Value(TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)));
if (vm.exception())
return {};
}
// 4. Return result. // 4. Return result.
return result; return result;

View file

@ -51,54 +51,34 @@ Value DurationConstructor::construct(FunctionObject& new_target)
auto& global_object = this->global_object(); auto& global_object = this->global_object();
// 2. Let y be ? ToIntegerThrowOnInfinity(years). // 2. Let y be ? ToIntegerThrowOnInfinity(years).
auto y = to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidDuration); auto y = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 3. Let mo be ? ToIntegerThrowOnInfinity(months). // 3. Let mo be ? ToIntegerThrowOnInfinity(months).
auto mo = to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidDuration); auto mo = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 4. Let w be ? ToIntegerThrowOnInfinity(weeks). // 4. Let w be ? ToIntegerThrowOnInfinity(weeks).
auto w = to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidDuration); auto w = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 5. Let d be ? ToIntegerThrowOnInfinity(days). // 5. Let d be ? ToIntegerThrowOnInfinity(days).
auto d = to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidDuration); auto d = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 6. Let h be ? ToIntegerThrowOnInfinity(hours). // 6. Let h be ? ToIntegerThrowOnInfinity(hours).
auto h = to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidDuration); auto h = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 7. Let m be ? ToIntegerThrowOnInfinity(minutes). // 7. Let m be ? ToIntegerThrowOnInfinity(minutes).
auto m = to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidDuration); auto m = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 8. Let s be ? ToIntegerThrowOnInfinity(seconds). // 8. Let s be ? ToIntegerThrowOnInfinity(seconds).
auto s = to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidDuration); auto s = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 9. Let ms be ? ToIntegerThrowOnInfinity(milliseconds). // 9. Let ms be ? ToIntegerThrowOnInfinity(milliseconds).
auto ms = to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidDuration); auto ms = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 10. Let mis be ? ToIntegerThrowOnInfinity(microseconds). // 10. Let mis be ? ToIntegerThrowOnInfinity(microseconds).
auto mis = to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidDuration); auto mis = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 11. Let ns be ? ToIntegerThrowOnInfinity(nanoseconds). // 11. Let ns be ? ToIntegerThrowOnInfinity(nanoseconds).
auto ns = to_integer_throw_on_infinity(global_object, vm.argument(9), ErrorType::TemporalInvalidDuration); auto ns = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(9), ErrorType::TemporalInvalidDuration));
if (vm.exception())
return {};
// 12. Return ? CreateTemporalDuration(y, mo, w, d, h, m, s, ms, mis, ns, NewTarget). // 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); return create_temporal_duration(global_object, y, mo, w, d, h, m, s, ms, mis, ns, &new_target);

View file

@ -53,19 +53,13 @@ Value PlainDateConstructor::construct(FunctionObject& new_target)
auto& global_object = this->global_object(); auto& global_object = this->global_object();
// 2. Let y be ? ToIntegerThrowOnInfinity(isoYear). // 2. Let y be ? ToIntegerThrowOnInfinity(isoYear).
auto y = to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDate); auto y = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDate));
if (vm.exception())
return {};
// 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth). // 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDate); auto m = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDate));
if (vm.exception())
return {};
// 4. Let d be ? ToIntegerThrowOnInfinity(isoDay). // 4. Let d be ? ToIntegerThrowOnInfinity(isoDay).
auto d = to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDate); auto d = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDate));
if (vm.exception())
return {};
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). // 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = to_temporal_calendar_with_iso_default(global_object, vm.argument(3)); auto* calendar = to_temporal_calendar_with_iso_default(global_object, vm.argument(3));

View file

@ -53,49 +53,31 @@ Value PlainDateTimeConstructor::construct(FunctionObject& new_target)
auto& global_object = this->global_object(); auto& global_object = this->global_object();
// 2. Let isoYear be ? ToIntegerThrowOnInfinity(isoYear). // 2. Let isoYear be ? ToIntegerThrowOnInfinity(isoYear).
auto iso_year = to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDateTime); auto iso_year = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 3. Let isoMonth be ? ToIntegerThrowOnInfinity(isoMonth). // 3. Let isoMonth be ? ToIntegerThrowOnInfinity(isoMonth).
auto iso_month = to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDateTime); auto iso_month = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 4. Let isoDay be ? ToIntegerThrowOnInfinity(isoDay). // 4. Let isoDay be ? ToIntegerThrowOnInfinity(isoDay).
auto iso_day = to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDateTime); auto iso_day = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 5. Let hour be ? ToIntegerThrowOnInfinity(hour). // 5. Let hour be ? ToIntegerThrowOnInfinity(hour).
auto hour = to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainDateTime); auto hour = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 6. Let minute be ? ToIntegerThrowOnInfinity(minute). // 6. Let minute be ? ToIntegerThrowOnInfinity(minute).
auto minute = to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainDateTime); auto minute = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 7. Let second be ? ToIntegerThrowOnInfinity(second). // 7. Let second be ? ToIntegerThrowOnInfinity(second).
auto second = to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainDateTime); auto second = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 8. Let millisecond be ? ToIntegerThrowOnInfinity(millisecond). // 8. Let millisecond be ? ToIntegerThrowOnInfinity(millisecond).
auto millisecond = to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidPlainDateTime); auto millisecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 9. Let microsecond be ? ToIntegerThrowOnInfinity(microsecond). // 9. Let microsecond be ? ToIntegerThrowOnInfinity(microsecond).
auto microsecond = to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidPlainDateTime); auto microsecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 10. Let nanosecond be ? ToIntegerThrowOnInfinity(nanosecond). // 10. Let nanosecond be ? ToIntegerThrowOnInfinity(nanosecond).
auto nanosecond = to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidPlainDateTime); auto nanosecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidPlainDateTime));
if (vm.exception())
return {};
// 11. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). // 11. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = to_temporal_calendar_with_iso_default(global_object, vm.argument(9)); auto* calendar = to_temporal_calendar_with_iso_default(global_object, vm.argument(9));

View file

@ -62,14 +62,10 @@ Value PlainMonthDayConstructor::construct(FunctionObject& new_target)
} }
// 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth). // 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainMonthDay); auto m = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainMonthDay));
if (vm.exception())
return {};
// 4. Let d be ? ToIntegerThrowOnInfinity(isoDay). // 4. Let d be ? ToIntegerThrowOnInfinity(isoDay).
auto d = to_integer_throw_on_infinity(global_object, iso_day, ErrorType::TemporalInvalidPlainMonthDay); auto d = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, iso_day, ErrorType::TemporalInvalidPlainMonthDay));
if (vm.exception())
return {};
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). // 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = to_temporal_calendar_with_iso_default(global_object, calendar_like); auto* calendar = to_temporal_calendar_with_iso_default(global_object, calendar_like);
@ -77,9 +73,7 @@ Value PlainMonthDayConstructor::construct(FunctionObject& new_target)
return {}; return {};
// 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISOYear). // 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISOYear).
auto ref = to_integer_throw_on_infinity(global_object, reference_iso_year, ErrorType::TemporalInvalidPlainMonthDay); auto ref = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, reference_iso_year, ErrorType::TemporalInvalidPlainMonthDay));
if (vm.exception())
return {};
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards. // 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 // This does not change the exposed behavior as the call to CreateTemporalMonthDay will immediately check that these values are valid

View file

@ -154,9 +154,7 @@ ThrowCompletionOr<PartialUnregulatedTemporalTime> to_partial_time(GlobalObject&
any = true; any = true;
// ii. Set value to ? ToIntegerThrowOnInfinity(value). // ii. Set value to ? ToIntegerThrowOnInfinity(value).
auto value_number = to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite); auto value_number = TRY(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite));
if (auto* exception = vm.exception())
return throw_completion(exception->value());
// iii. Set result's internal slot whose name is the Internal Slot value of the current row to value. // iii. Set result's internal slot whose name is the Internal Slot value of the current row to value.
result.*internal_slot = value_number; result.*internal_slot = value_number;
@ -384,9 +382,7 @@ ThrowCompletionOr<UnregulatedTemporalTime> to_temporal_time_record(GlobalObject&
} }
// d. Set value to ? ToIntegerThrowOnInfinity(value). // d. Set value to ? ToIntegerThrowOnInfinity(value).
auto value_number = to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite); auto value_number = TRY(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite));
if (auto* exception = vm.exception())
return throw_completion(exception->value());
// e. Set result's internal slot whose name is the Internal Slot value of the current row to value. // e. Set result's internal slot whose name is the Internal Slot value of the current row to value.
result.*internal_slot = value_number; result.*internal_slot = value_number;

View file

@ -51,34 +51,22 @@ Value PlainTimeConstructor::construct(FunctionObject& new_target)
auto& global_object = this->global_object(); auto& global_object = this->global_object();
// 2. Let hour be ? ToIntegerThrowOnInfinity(hour). // 2. Let hour be ? ToIntegerThrowOnInfinity(hour).
auto hour = to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainTime); auto hour = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainTime));
if (vm.exception())
return {};
// 3. Let minute be ? ToIntegerThrowOnInfinity(hour). // 3. Let minute be ? ToIntegerThrowOnInfinity(hour).
auto minute = to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainTime); auto minute = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainTime));
if (vm.exception())
return {};
// 4. Let second be ? ToIntegerThrowOnInfinity(hour). // 4. Let second be ? ToIntegerThrowOnInfinity(hour).
auto second = to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainTime); auto second = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainTime));
if (vm.exception())
return {};
// 5. Let millisecond be ? ToIntegerThrowOnInfinity(hour). // 5. Let millisecond be ? ToIntegerThrowOnInfinity(hour).
auto millisecond = to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainTime); auto millisecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainTime));
if (vm.exception())
return {};
// 6. Let microsecond be ? ToIntegerThrowOnInfinity(hour). // 6. Let microsecond be ? ToIntegerThrowOnInfinity(hour).
auto microsecond = to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainTime); auto microsecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainTime));
if (vm.exception())
return {};
// 7. Let nanosecond be ? ToIntegerThrowOnInfinity(hour). // 7. Let nanosecond be ? ToIntegerThrowOnInfinity(hour).
auto nanosecond = to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainTime); auto nanosecond = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainTime));
if (vm.exception())
return {};
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards. // 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 // This does not change the exposed behavior as the call to CreateTemporalTime will immediately check that these values are valid

View file

@ -64,14 +64,10 @@ Value PlainYearMonthConstructor::construct(FunctionObject& new_target)
} }
// 3. Let y be ? ToIntegerThrowOnInfinity(isoYear). // 3. Let y be ? ToIntegerThrowOnInfinity(isoYear).
auto y = to_integer_throw_on_infinity(global_object, iso_year, ErrorType::TemporalInvalidPlainYearMonth); auto y = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, iso_year, ErrorType::TemporalInvalidPlainYearMonth));
if (vm.exception())
return {};
// 4. Let m be ? ToIntegerThrowOnInfinity(isoMonth). // 4. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainYearMonth); auto m = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainYearMonth));
if (vm.exception())
return {};
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). // 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = to_temporal_calendar_with_iso_default(global_object, calendar_like); auto* calendar = to_temporal_calendar_with_iso_default(global_object, calendar_like);
@ -79,9 +75,7 @@ Value PlainYearMonthConstructor::construct(FunctionObject& new_target)
return {}; return {};
// 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISODay). // 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISODay).
auto ref = to_integer_throw_on_infinity(global_object, reference_iso_day, ErrorType::TemporalInvalidPlainYearMonth); auto ref = TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, reference_iso_day, ErrorType::TemporalInvalidPlainYearMonth));
if (vm.exception())
return {};
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards. // 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 // This does not change the exposed behavior as the call to CreateTemporalYearMonth will immediately check that these values are valid