diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp index 5b9d03c913..a4ef855b18 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp @@ -68,9 +68,7 @@ Value DisplayNamesConstructor::construct(FunctionObject& new_target) } // 5. Set options to ? GetOptionsObject(options). - auto* options = Temporal::get_options_object(global_object, options_value); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(Temporal::get_options_object(global_object, options_value)); // 6. Let opt be a new Record. LocaleOptions opt {}; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp index d116e51ad2..390f1399e1 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp @@ -61,9 +61,7 @@ Value ListFormatConstructor::construct(FunctionObject& new_target) return {}; // 4. Set options to ? GetOptionsObject(options). - auto* options = Temporal::get_options_object(global_object, options_value); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(Temporal::get_options_object(global_object, options_value)); // 5. Let opt be a new Record. LocaleOptions opt {}; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 95017e567a..5ea2322441 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -82,7 +82,7 @@ ThrowCompletionOr iterable_to_list_of_type(GlobalObject& global } // 13.2 GetOptionsObject ( options ), https://tc39.es/proposal-temporal/#sec-getoptionsobject -Object* get_options_object(GlobalObject& global_object, Value options) +ThrowCompletionOr get_options_object(GlobalObject& global_object, Value options) { auto& vm = global_object.vm(); @@ -99,8 +99,7 @@ Object* get_options_object(GlobalObject& global_object, Value options) } // 3. Throw a TypeError exception. - vm.throw_exception(global_object, ErrorType::NotAnObject, "Options"); - return {}; + return vm.throw_completion(global_object, ErrorType::NotAnObject, "Options"); } // 13.3 GetOption ( options, property, types, values, fallback ), https://tc39.es/proposal-temporal/#sec-getoption diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index 62fb5880a6..a311eca993 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -85,7 +85,7 @@ struct SecondsStringPrecision { }; ThrowCompletionOr iterable_to_list_of_type(GlobalObject&, Value items, Vector const& element_types); -Object* get_options_object(GlobalObject&, Value options); +ThrowCompletionOr get_options_object(GlobalObject&, Value options); Value get_option(GlobalObject&, Object const& options, PropertyName const& property, Vector const& types, Vector const& values, Value fallback); template Optional> get_string_or_number_option(GlobalObject&, Object const& options, PropertyName const& property, Vector const& string_values, NumberType minimum, NumberType maximum, Value fallback); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index a9fe5f745a..83292c3635 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -92,9 +92,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_from_fields) } // 5. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); // 6. Let result be ? ISODateFromFields(fields, options). auto result = iso_date_from_fields(global_object, fields.as_object(), *options); @@ -126,9 +124,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::year_month_from_fields) } // 5. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); // 6. Let result be ? ISOYearMonthFromFields(fields, options). auto result = iso_year_month_from_fields(global_object, fields.as_object(), *options); @@ -160,9 +156,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::month_day_from_fields) } // 5. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); // 6. Let result be ? ISOMonthDayFromFields(fields, options). auto result = iso_month_day_from_fields(global_object, fields.as_object(), *options); @@ -197,9 +191,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_add) return {}; // 6. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(2)); - if (vm.exception()) - return {}; + 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); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index 449dce9ed2..23e9c17db6 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -190,9 +190,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::until) return {}; // 4. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); // 5. Let smallestUnit be ? ToSmallestTemporalUnit(options, « "year", "month", "week", "day" », "nanosecond"). auto smallest_unit = to_smallest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, "nanosecond"sv); @@ -250,9 +248,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::since) return {}; // 4. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); // 5. Let smallestUnit be ? ToSmallestTemporalUnit(options, « "year", "month", "week", "day" », "nanosecond"). auto smallest_unit = to_smallest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, "nanosecond"sv); @@ -312,9 +308,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round) } // 4. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(0)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0))); // 5. Let smallestUnit be ? ToSmallestTemporalUnit(options, « "year", "month", "week", "day" », undefined). auto smallest_unit_value = to_smallest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, {}); @@ -414,9 +408,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_string) return {}; // 3. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(0)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0))); // 4. Let timeZone be ? Get(options, "timeZone"). auto time_zone = options->get(vm.names.timeZone); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp index c7268df52c..7d7517d752 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp @@ -82,9 +82,7 @@ Value PlainDateConstructor::construct(FunctionObject& new_target) JS_DEFINE_NATIVE_FUNCTION(PlainDateConstructor::from) { // 1. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); auto item = vm.argument(0); // 2. If Type(item) is Object and item has an [[InitializedTemporalDate]] internal slot, then diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp index 982c769c68..bd477a31b9 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp @@ -456,9 +456,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_string) return {}; // 3. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(0)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0))); // 4. Let showCalendar be ? ToShowCalendarOption(options). auto show_calendar = to_show_calendar_option(global_object, *options); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp index 9cc2a6c281..2572501f66 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp @@ -103,9 +103,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimeConstructor::from) auto item = vm.argument(0); // 1. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); // 2. If Type(item) is Object and item has an [[InitializedTemporalDateTime]] internal slot, then if (item.is_object() && is(item.as_object())) { diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp index 0e50d60c7a..9fce7ce72c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp @@ -90,13 +90,11 @@ Value PlainMonthDayConstructor::construct(FunctionObject& new_target) // 10.2.2 Temporal.PlainMonthDay.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.from JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayConstructor::from) { - // 1. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; - auto item = vm.argument(0); + // 1. Set options to ? GetOptionsObject(options). + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); + // 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). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp index 5957df4119..83d3b98c4c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp @@ -124,9 +124,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_string) return {}; // 3. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(0)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0))); // 4. Let showCalendar be ? ToShowCalendarOption(options). auto show_calendar = to_show_calendar_option(global_object, *options); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp index d6cf430838..8dd7e3c17c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp @@ -85,9 +85,7 @@ Value PlainTimeConstructor::construct(FunctionObject& new_target) JS_DEFINE_NATIVE_FUNCTION(PlainTimeConstructor::from) { // 1. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + 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); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp index 877476149d..63200920d6 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp @@ -192,9 +192,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with) auto partial_time = TRY_OR_DISCARD(to_partial_time(global_object, temporal_time_like)); // 10. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + 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); @@ -349,9 +347,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_string) return {}; // 3. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(0)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0))); // 4. Let precision be ? ToSecondsStringPrecision(options). auto precision = to_seconds_string_precision(global_object, *options); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp index b3e3b0cc9a..ffa4f1f3e5 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp @@ -93,9 +93,7 @@ Value PlainYearMonthConstructor::construct(FunctionObject& new_target) JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthConstructor::from) { // 1. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(1)); - if (vm.exception()) - return {}; + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); auto item = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp index d2911795ab..afff17295c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp @@ -243,7 +243,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_string) return {}; // 3. Set options to ? GetOptionsObject(options). - auto* options = get_options_object(global_object, vm.argument(0)); + auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0))); if (vm.exception()) return {};