diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 3eb4227987..13d51ae253 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -202,12 +202,12 @@ ThrowCompletionOr> get_string_or_number_option(Globa } // 13.6 ToTemporalOverflow ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaloverflow -Optional to_temporal_overflow(GlobalObject& global_object, Object const& normalized_options) +ThrowCompletionOr to_temporal_overflow(GlobalObject& global_object, Object const& normalized_options) { auto& vm = global_object.vm(); // 1. Return ? GetOption(normalizedOptions, "overflow", « String », « "constrain", "reject" », "constrain"). - auto option = TRY_OR_DISCARD(get_option(global_object, normalized_options, vm.names.overflow, { OptionType::String }, { "constrain"sv, "reject"sv }, js_string(vm, "constrain"))); + auto option = TRY(get_option(global_object, normalized_options, vm.names.overflow, { OptionType::String }, { "constrain"sv, "reject"sv }, js_string(vm, "constrain"))); VERIFY(option.is_string()); return option.as_string().string(); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index 2a4c30b22b..305e3c5dc2 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -89,7 +89,7 @@ ThrowCompletionOr get_options_object(GlobalObject&, Value options); ThrowCompletionOr get_option(GlobalObject&, Object const& options, PropertyName const& property, Vector const& types, Vector const& values, Value fallback); template ThrowCompletionOr> get_string_or_number_option(GlobalObject&, Object const& options, PropertyName const& property, Vector const& string_values, NumberType minimum, NumberType maximum, Value fallback); -Optional to_temporal_overflow(GlobalObject&, Object const& normalized_options); +ThrowCompletionOr to_temporal_overflow(GlobalObject&, Object const& normalized_options); Optional to_temporal_rounding_mode(GlobalObject&, Object const& normalized_options, String const& fallback); Optional to_show_calendar_option(GlobalObject&, Object const& normalized_options); u64 to_temporal_rounding_increment(GlobalObject&, Object const& normalized_options, Optional dividend, bool inclusive); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index 1a343543c9..1fb91ebd4b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -791,9 +791,7 @@ Optional iso_date_from_fields(GlobalObject& global_object, Object const // 1. Assert: Type(fields) is Object. // 2. Let overflow be ? ToTemporalOverflow(options). - auto overflow = to_temporal_overflow(global_object, options); - if (vm.exception()) - return {}; + auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, options)); // 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », «»). auto* prepared_fields = prepare_temporal_fields(global_object, fields, { "day", "month", "monthCode", "year" }, {}); @@ -828,7 +826,7 @@ Optional iso_date_from_fields(GlobalObject& global_object, Object const } // 9. Return ? RegulateISODate(year, month, day, overflow). - return regulate_iso_date(global_object, year.as_double(), month, day.as_double(), *overflow); + return regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow); } // 12.1.39 ISOYearMonthFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthfromfields @@ -839,9 +837,7 @@ Optional iso_year_month_from_fields(GlobalObject& global_object, O // 1. Assert: Type(fields) is Object. // 2. Let overflow be ? ToTemporalOverflow(options). - auto overflow = to_temporal_overflow(global_object, options); - if (vm.exception()) - return {}; + auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, options)); // 3. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », «»). auto* prepared_fields = prepare_temporal_fields(global_object, fields, { "month"sv, "monthCode"sv, "year"sv }, {}); @@ -865,7 +861,7 @@ Optional iso_year_month_from_fields(GlobalObject& global_object, O return {}; // 7. Let result be ? RegulateISOYearMonth(year, month, overflow). - auto result = TRY_OR_DISCARD(regulate_iso_year_month(global_object, year.as_double(), month, *overflow)); + auto result = TRY_OR_DISCARD(regulate_iso_year_month(global_object, year.as_double(), month, overflow)); // 8. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[ReferenceISODay]]: 1 }. return ISOYearMonth { .year = result.year, .month = result.month, .reference_iso_day = 1 }; @@ -879,9 +875,7 @@ Optional iso_month_day_from_fields(GlobalObject& global_object, Obj // 1. Assert: Type(fields) is Object. // 2. Let overflow be ? ToTemporalOverflow(options). - auto overflow = to_temporal_overflow(global_object, options); - if (vm.exception()) - return {}; + auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, options)); // 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », «»). auto* prepared_fields = prepare_temporal_fields(global_object, fields, { "day"sv, "month"sv, "monthCode"sv, "year"sv }, {}); @@ -934,12 +928,12 @@ Optional iso_month_day_from_fields(GlobalObject& global_object, Obj // 12. If monthCode is undefined, then if (month_code.is_undefined()) { // a. Let result be ? RegulateISODate(year, month, day, overflow). - result = regulate_iso_date(global_object, year.as_double(), month, day.as_double(), *overflow); + result = regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow); } // 13. Else, else { // a. Let result be ? RegulateISODate(referenceISOYear, month, day, overflow). - result = regulate_iso_date(global_object, reference_iso_year, month, day.as_double(), *overflow); + result = regulate_iso_date(global_object, reference_iso_year, month, day.as_double(), overflow); } if (vm.exception()) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index 83292c3635..f02ba8cf7a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -194,9 +194,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_add) auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(2))); // 7. Let overflow be ? ToTemporalOverflow(options). - auto overflow = to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); // FIXME: Narrowing conversion from 'double' to 'i64' auto* nanoseconds = js_bigint(vm, Crypto::SignedBigInteger::create_from(duration->nanoseconds())); @@ -205,7 +203,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_add) auto balance_result = balance_duration(global_object, duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), *nanoseconds, "day"sv); // 9. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], balanceResult.[[Days]], overflow). - auto result = add_iso_date(global_object, date->iso_year(), date->iso_month(), date->iso_day(), duration->years(), duration->months(), duration->weeks(), balance_result->days, *overflow); + auto result = add_iso_date(global_object, date->iso_year(), date->iso_month(), date->iso_day(), duration->years(), duration->months(), duration->weeks(), balance_result->days, overflow); if (vm.exception()) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp index b9365fd39a..c4d71eeb2c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp @@ -131,9 +131,7 @@ PlainDate* to_temporal_date(GlobalObject& global_object, Value item, Object* opt } // 4. Perform ? ToTemporalOverflow(options). - (void)to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + (void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); // 5. Let string be ? ToString(item). auto string = item.to_string(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp index 7d7517d752..463e7d4f07 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp @@ -89,9 +89,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateConstructor::from) if (item.is_object() && is(item.as_object())) { auto& plain_date_item = static_cast(item.as_object()); // a. Perform ? ToTemporalOverflow(options). - (void)to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + (void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); + // b. Return ? CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[Calendar]]). return create_temporal_date(global_object, plain_date_item.iso_year(), plain_date_item.iso_month(), plain_date_item.iso_day(), plain_date_item.calendar()); } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp index 8ebb4853d8..7e9555651c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp @@ -112,12 +112,10 @@ Optional interpret_temporal_date_time_fields(GlobalObject& global_o return {}; // 3. Let overflow be ? ToTemporalOverflow(options). - auto overflow = to_temporal_overflow(global_object, options); - if (vm.exception()) - return {}; + auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, options)); // 4. Let timeResult be ? RegulateTime(timeResult.[[Hour]], timeResult.[[Minute]], timeResult.[[Second]], timeResult.[[Millisecond]], timeResult.[[Microsecond]], timeResult.[[Nanosecond]], overflow). - auto time_result = TRY_OR_DISCARD(regulate_time(global_object, unregulated_time_result.hour, unregulated_time_result.minute, unregulated_time_result.second, unregulated_time_result.millisecond, unregulated_time_result.microsecond, unregulated_time_result.nanosecond, *overflow)); + auto time_result = TRY_OR_DISCARD(regulate_time(global_object, unregulated_time_result.hour, unregulated_time_result.minute, unregulated_time_result.second, unregulated_time_result.millisecond, unregulated_time_result.microsecond, unregulated_time_result.nanosecond, overflow)); // 5. Return the Record { [[Year]]: temporalDate.[[ISOYear]], [[Month]]: temporalDate.[[ISOMonth]], [[Day]]: temporalDate.[[ISODay]], [[Hour]]: timeResult.[[Hour]], [[Minute]]: timeResult.[[Minute]], [[Second]]: timeResult.[[Second]], [[Millisecond]]: timeResult.[[Millisecond]], [[Microsecond]]: timeResult.[[Microsecond]], [[Nanosecond]]: timeResult.[[Nanosecond]] }. return ISODateTime { @@ -198,9 +196,7 @@ PlainDateTime* to_temporal_date_time(GlobalObject& global_object, Value item, Ob // 3. Else, else { // a. Perform ? ToTemporalOverflow(options). - (void)to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + (void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); // b. Let string be ? ToString(item). auto string = item.to_string(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp index 2572501f66..76cde1ef7e 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp @@ -110,9 +110,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimeConstructor::from) auto& plain_date_time = static_cast(item.as_object()); // a. Perform ? ToTemporalOverflow(options). - (void)to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + (void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); // b. Return ? CreateTemporalDateTime(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[ISOHour]], item.[[ISOMinute]], item.[[ISOSecond]], item.[[ISOMillisecond]], item.[[ISOMicrosecond]], item.[[ISONanosecond]], item.[[Calendar]]). return create_temporal_date_time(global_object, plain_date_time.iso_year(), plain_date_time.iso_month(), plain_date_time.iso_day(), plain_date_time.iso_hour(), plain_date_time.iso_minute(), plain_date_time.iso_second(), plain_date_time.iso_millisecond(), plain_date_time.iso_microsecond(), plain_date_time.iso_nanosecond(), plain_date_time.calendar()); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp index 9fce7ce72c..39abf86afd 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp @@ -98,9 +98,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayConstructor::from) // 2. If Type(item) is Object and item has an [[InitializedTemporalMonthDay]] internal slot, then if (item.is_object() && is(item.as_object())) { // a. Perform ? ToTemporalOverflow(options). - (void)to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + (void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); auto& plain_month_day_object = static_cast(item.as_object()); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp index 8dd7e3c17c..7a7f0006ba 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp @@ -88,9 +88,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimeConstructor::from) auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); // 2. Let overflow be ? ToTemporalOverflow(options). - auto overflow = to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); auto item = vm.argument(0); @@ -102,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimeConstructor::from) } // 4. Return ? ToTemporalTime(item, overflow). - return TRY_OR_DISCARD(to_temporal_time(global_object, item, *overflow)); + return TRY_OR_DISCARD(to_temporal_time(global_object, item, overflow)); } // 4.2.3 Temporal.PlainTime.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.compare diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp index 63200920d6..0ae03eb29f 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp @@ -195,9 +195,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with) auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); // 11. Let overflow be ? ToTemporalOverflow(options). - auto overflow = to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); // 12. If partialTime.[[Hour]] is not undefined, then // a. Let hour be partialTime.[[Hour]]. @@ -236,7 +234,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with) auto nanosecond = partial_time.nanosecond.value_or(temporal_time->iso_nanosecond()); // 24. Let result be ? RegulateTime(hour, minute, second, millisecond, microsecond, nanosecond, overflow). - auto result = TRY_OR_DISCARD(regulate_time(global_object, hour, minute, second, millisecond, microsecond, nanosecond, *overflow)); + auto result = TRY_OR_DISCARD(regulate_time(global_object, hour, minute, second, millisecond, microsecond, nanosecond, overflow)); // 25. Return ? CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]). return TRY_OR_DISCARD(create_temporal_time(global_object, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp index fd1385dc16..d7c59afe23 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp @@ -71,9 +71,7 @@ ThrowCompletionOr to_temporal_year_month(GlobalObject& global_o } // 4. Perform ? ToTemporalOverflow(options). - (void)to_temporal_overflow(global_object, *options); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + (void)TRY(to_temporal_overflow(global_object, *options)); // 5. Let string be ? ToString(item). auto string = item.to_string(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp index ffa4f1f3e5..da7d20d7e9 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp @@ -100,9 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthConstructor::from) // 2. If Type(item) is Object and item has an [[InitializedTemporalYearMonth]] internal slot, then if (item.is_object() && is(item.as_object())) { // a. Perform ? ToTemporalOverflow(options). - (void)to_temporal_overflow(global_object, *options); - if (vm.exception()) - return {}; + (void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); auto& plain_year_month_object = static_cast(item.as_object());