From 15f52c5f8e794ac8653ba5cde4685e01613fb802 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 21 Oct 2021 20:16:46 +0100 Subject: [PATCH] LibJS: Convert Temporal.PlainYearMonth functions to ThrowCompletionOr --- .../Temporal/PlainYearMonthConstructor.cpp | 20 +-- .../Temporal/PlainYearMonthConstructor.h | 4 +- .../Temporal/PlainYearMonthPrototype.cpp | 152 +++++++++--------- .../Temporal/PlainYearMonthPrototype.h | 34 ++-- 4 files changed, 104 insertions(+), 106 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp index 0cbc2b007a..edd2b55a15 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp @@ -32,8 +32,8 @@ void PlainYearMonthConstructor::initialize(GlobalObject& global_object) define_direct_property(vm.names.length, Value(2), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; - define_old_native_function(vm.names.from, from, 1, attr); - define_old_native_function(vm.names.compare, compare, 2, attr); + define_native_function(vm.names.from, from, 1, attr); + define_native_function(vm.names.compare, compare, 2, attr); } // 9.1.1 Temporal.PlainYearMonth ( isoYear, isoMonth [ , calendarLike [ , referenceISODay ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth @@ -85,36 +85,36 @@ ThrowCompletionOr PlainYearMonthConstructor::construct(FunctionObject& } // 9.2.2 Temporal.PlainYearMonth.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.from -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthConstructor::from) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthConstructor::from) { // 1. Set options to ? GetOptionsObject(options). - auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1))); + auto* options = TRY(get_options_object(global_object, vm.argument(1))); auto item = vm.argument(0); // 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)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options)); + (void)TRY(to_temporal_overflow(global_object, *options)); auto& plain_year_month_object = static_cast(item.as_object()); // b. Return ? CreateTemporalYearMonth(item.[[ISOYear]], item.[[ISOMonth]], item.[[Calendar]], item.[[ISODay]]). - return TRY_OR_DISCARD(create_temporal_year_month(global_object, plain_year_month_object.iso_year(), plain_year_month_object.iso_month(), plain_year_month_object.calendar(), plain_year_month_object.iso_day())); + return TRY(create_temporal_year_month(global_object, plain_year_month_object.iso_year(), plain_year_month_object.iso_month(), plain_year_month_object.calendar(), plain_year_month_object.iso_day())); } // 3. Return ? ToTemporalYearMonth(item, options). - return TRY_OR_DISCARD(to_temporal_year_month(global_object, item, options)); + return TRY(to_temporal_year_month(global_object, item, options)); } // 9.2.3 Temporal.PlainYearMonth.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.compare -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthConstructor::compare) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthConstructor::compare) { // 1. Set one to ? ToTemporalYearMonth(one). - auto* one = TRY_OR_DISCARD(to_temporal_year_month(global_object, vm.argument(0))); + auto* one = TRY(to_temporal_year_month(global_object, vm.argument(0))); // 2. Set two to ? ToTemporalYearMonth(one). - auto* two = TRY_OR_DISCARD(to_temporal_year_month(global_object, vm.argument(1))); + auto* two = TRY(to_temporal_year_month(global_object, vm.argument(1))); // 3. Return 𝔽(! CompareISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]])). return Value(compare_iso_date(one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day())); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.h index 64a7a9d665..fbb76d0794 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.h @@ -24,8 +24,8 @@ public: private: virtual bool has_constructor() const override { return true; } - JS_DECLARE_OLD_NATIVE_FUNCTION(from); - JS_DECLARE_OLD_NATIVE_FUNCTION(compare); + JS_DECLARE_NATIVE_FUNCTION(from); + JS_DECLARE_NATIVE_FUNCTION(compare); }; } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp index cf79b2a5aa..af2815abf3 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp @@ -28,173 +28,173 @@ void PlainYearMonthPrototype::initialize(GlobalObject& global_object) // 9.3.2 Temporal.PlainYearMonth.prototype[ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype-@@tostringtag define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal.PlainYearMonth"), Attribute::Configurable); - define_old_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.year, year_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.month, month_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.daysInYear, days_in_year_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.daysInMonth, days_in_month_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.monthsInYear, months_in_year_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.era, era_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.eraYear, era_year_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.year, year_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.month, month_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.daysInYear, days_in_year_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.daysInMonth, days_in_month_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.monthsInYear, months_in_year_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.era, era_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.eraYear, era_year_getter, {}, Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; - define_old_native_function(vm.names.equals, equals, 1, attr); - define_old_native_function(vm.names.toString, to_string, 0, attr); - define_old_native_function(vm.names.toLocaleString, to_locale_string, 0, attr); - define_old_native_function(vm.names.toJSON, to_json, 0, attr); - define_old_native_function(vm.names.valueOf, value_of, 0, attr); - define_old_native_function(vm.names.toPlainDate, to_plain_date, 1, attr); - define_old_native_function(vm.names.getISOFields, get_iso_fields, 0, attr); + define_native_function(vm.names.equals, equals, 1, attr); + define_native_function(vm.names.toString, to_string, 0, attr); + define_native_function(vm.names.toLocaleString, to_locale_string, 0, attr); + define_native_function(vm.names.toJSON, to_json, 0, attr); + define_native_function(vm.names.valueOf, value_of, 0, attr); + define_native_function(vm.names.toPlainDate, to_plain_date, 1, attr); + define_native_function(vm.names.getISOFields, get_iso_fields, 0, attr); } // 9.3.3 get Temporal.PlainYearMonth.prototype.calendar, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.calendar -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::calendar_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::calendar_getter) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Return yearMonth.[[Calendar]]. return Value(&year_month->calendar()); } // 9.3.4 get Temporal.PlainYearMonth.prototype.year, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.year -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::year_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::year_getter) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be yearMonth.[[Calendar]]. auto& calendar = year_month->calendar(); // 4. Return 𝔽(? CalendarYear(calendar, yearMonth)). - return Value(TRY_OR_DISCARD(calendar_year(global_object, calendar, *year_month))); + return Value(TRY(calendar_year(global_object, calendar, *year_month))); } // 9.3.5 get Temporal.PlainYearMonth.prototype.month, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.month -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::month_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::month_getter) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be yearMonth.[[Calendar]]. auto& calendar = year_month->calendar(); // 4. Return 𝔽(? CalendarMonth(calendar, yearMonth)). - return Value(TRY_OR_DISCARD(calendar_month(global_object, calendar, *year_month))); + return Value(TRY(calendar_month(global_object, calendar, *year_month))); } // 9.3.6 get Temporal.PlainYearMonth.prototype.monthCode, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.monthCode -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::month_code_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::month_code_getter) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be yearMonth.[[Calendar]]. auto& calendar = year_month->calendar(); // 4. Return ? CalendarMonthCode(calendar, yearMonth). - return js_string(vm, TRY_OR_DISCARD(calendar_month_code(global_object, calendar, *year_month))); + return js_string(vm, TRY(calendar_month_code(global_object, calendar, *year_month))); } // 9.3.7 get Temporal.PlainYearMonth.prototype.daysInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.daysinyear -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::days_in_year_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::days_in_year_getter) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be yearMonth.[[Calendar]]. auto& calendar = year_month->calendar(); // 4. Return ? CalendarDaysInYear(calendar, yearMonth). - return Value(TRY_OR_DISCARD(calendar_days_in_year(global_object, calendar, *year_month))); + return Value(TRY(calendar_days_in_year(global_object, calendar, *year_month))); } // 9.3.8 get Temporal.PlainYearMonth.prototype.daysInMonth, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.daysinmonth -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::days_in_month_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::days_in_month_getter) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be yearMonth.[[Calendar]]. auto& calendar = year_month->calendar(); // 4. Return ? CalendarDaysInMonth(calendar, yearMonth). - return Value(TRY_OR_DISCARD(calendar_days_in_month(global_object, calendar, *year_month))); + return Value(TRY(calendar_days_in_month(global_object, calendar, *year_month))); } // 9.3.9 get Temporal.PlainYearMonth.prototype.monthsInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.monthsinyear -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::months_in_year_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::months_in_year_getter) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be yearMonth.[[Calendar]]. auto& calendar = year_month->calendar(); // 4. Return ? CalendarMonthsInYear(calendar, yearMonth). - return Value(TRY_OR_DISCARD(calendar_months_in_year(global_object, calendar, *year_month))); + return Value(TRY(calendar_months_in_year(global_object, calendar, *year_month))); } // 9.3.10 get Temporal.PlainYearMonth.prototype.inLeapYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.inleapyear -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::in_leap_year_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::in_leap_year_getter) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be yearMonth.[[Calendar]]. auto& calendar = year_month->calendar(); // 4. Return ? CalendarInLeapYear(calendar, yearMonth). - return Value(TRY_OR_DISCARD(calendar_in_leap_year(global_object, calendar, *year_month))); + return Value(TRY(calendar_in_leap_year(global_object, calendar, *year_month))); } // 15.6.9.2 get Temporal.PlainYearMonth.prototype.era, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.era -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::era_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::era_getter) { // 1. Let plainYearMonth be the this value. // 2. Perform ? RequireInternalSlot(plainYearMonth, [[InitializedTemporalYearMonth]]). - auto* plain_year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* plain_year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be plainYearMonth.[[Calendar]]. auto& calendar = plain_year_month->calendar(); // 4. Return ? CalendarEra(calendar, plainYearMonth). - return TRY_OR_DISCARD(calendar_era(global_object, calendar, *plain_year_month)); + return TRY(calendar_era(global_object, calendar, *plain_year_month)); } // 15.6.9.3 get Temporal.PlainYearMonth.prototype.eraYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.erayear -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::era_year_getter) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::era_year_getter) { // 1. Let plainYearMonth be the this value. // 2. Perform ? RequireInternalSlot(plainYearMonth, [[InitializedTemporalYearMonth]]). - auto* plain_year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* plain_year_month = TRY(typed_this_object(global_object)); // 3. Let calendar be plainYearMonth.[[Calendar]]. auto& calendar = plain_year_month->calendar(); // 4. Return ? CalendarEraYear(calendar, plainYearMonth). - return TRY_OR_DISCARD(calendar_era_year(global_object, calendar, *plain_year_month)); + return TRY(calendar_era_year(global_object, calendar, *plain_year_month)); } // 9.3.16 Temporal.PlainYearMonth.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.equals -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::equals) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::equals) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Set other to ? ToTemporalYearMonth(other). - auto* other = TRY_OR_DISCARD(to_temporal_year_month(global_object, vm.argument(0))); + auto* other = TRY(to_temporal_year_month(global_object, vm.argument(0))); // 4. If yearMonth.[[ISOYear]] ≠ other.[[ISOYear]], return false. if (year_month->iso_year() != other->iso_year()) @@ -209,90 +209,88 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::equals) return Value(false); // 7. Return ? CalendarEquals(yearMonth.[[Calendar]], other.[[Calendar]]). - return Value(TRY_OR_DISCARD(calendar_equals(global_object, year_month->calendar(), other->calendar()))); + return Value(TRY(calendar_equals(global_object, year_month->calendar(), other->calendar()))); } // 9.3.17 Temporal.PlainYearMonth.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.tostring -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::to_string) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_string) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Set options to ? GetOptionsObject(options). - auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0))); + auto* options = TRY(get_options_object(global_object, vm.argument(0))); // 4. Let showCalendar be ? ToShowCalendarOption(options). - auto show_calendar = TRY_OR_DISCARD(to_show_calendar_option(global_object, *options)); + auto show_calendar = TRY(to_show_calendar_option(global_object, *options)); // 5. Return ? TemporalYearMonthToString(yearMonth, showCalendar). - return js_string(vm, TRY_OR_DISCARD(temporal_year_month_to_string(global_object, *year_month, show_calendar))); + return js_string(vm, TRY(temporal_year_month_to_string(global_object, *year_month, show_calendar))); } // 9.3.18 Temporal.PlainYearMonth.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.tolocalestring // NOTE: This is the minimum toLocaleString implementation for engines without ECMA-402. -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::to_locale_string) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_locale_string) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Return ? TemporalYearMonthToString(yearMonth, "auto"). - return js_string(vm, TRY_OR_DISCARD(temporal_year_month_to_string(global_object, *year_month, "auto"sv))); + return js_string(vm, TRY(temporal_year_month_to_string(global_object, *year_month, "auto"sv))); } // 9.3.19 Temporal.PlainYearMonth.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.tojson -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::to_json) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_json) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Return ? TemporalYearMonthToString(yearMonth, "auto"). - return js_string(vm, TRY_OR_DISCARD(temporal_year_month_to_string(global_object, *year_month, "auto"sv))); + return js_string(vm, TRY(temporal_year_month_to_string(global_object, *year_month, "auto"sv))); } // 9.3.20 Temporal.PlainYearMonth.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.valueof -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::value_of) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::value_of) { // 1. Throw a TypeError exception. - vm.throw_exception(global_object, ErrorType::Convert, "Temporal.PlainYearMonth", "a primitive value"); - return {}; + return vm.throw_completion(global_object, ErrorType::Convert, "Temporal.PlainYearMonth", "a primitive value"); } // 9.3.21 Temporal.PlainYearMonth.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.toplaindate -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date) { auto item = vm.argument(0); // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. If Type(item) is not Object, then if (!item.is_object()) { // a. Throw a TypeError exception. - vm.throw_exception(global_object, ErrorType::NotAnObject, item); - return {}; + return vm.throw_completion(global_object, ErrorType::NotAnObject, item); } // 4. Let calendar be yearMonth.[[Calendar]]. auto& calendar = year_month->calendar(); // 5. Let receiverFieldNames be ? CalendarFields(calendar, « "monthCode", "year" »). - auto receiver_field_names = TRY_OR_DISCARD(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv })); + auto receiver_field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv })); // 6. Let fields be ? PrepareTemporalFields(yearMonth, receiverFieldNames, «»). - auto* fields = TRY_OR_DISCARD(prepare_temporal_fields(global_object, *year_month, receiver_field_names, {})); + auto* fields = TRY(prepare_temporal_fields(global_object, *year_month, receiver_field_names, {})); // 7. Let inputFieldNames be ? CalendarFields(calendar, « "day" »). - auto input_field_names = TRY_OR_DISCARD(calendar_fields(global_object, calendar, { "day"sv })); + auto input_field_names = TRY(calendar_fields(global_object, calendar, { "day"sv })); // 8. Let inputFields be ? PrepareTemporalFields(item, inputFieldNames, «»). - auto* input_fields = TRY_OR_DISCARD(prepare_temporal_fields(global_object, item.as_object(), input_field_names, {})); + auto* input_fields = TRY(prepare_temporal_fields(global_object, item.as_object(), input_field_names, {})); // 9. Let mergedFields be ? CalendarMergeFields(calendar, fields, inputFields). - auto* merged_fields = TRY_OR_DISCARD(calendar_merge_fields(global_object, calendar, *fields, *input_fields)); + auto* merged_fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *input_fields)); // 10. Let mergedFieldNames be the List containing all the elements of receiverFieldNames followed by all the elements of inputFieldNames, with duplicate elements removed. Vector merged_field_names; @@ -306,7 +304,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date) } // 11. Set mergedFields to ? PrepareTemporalFields(mergedFields, mergedFieldNames, «»). - merged_fields = TRY_OR_DISCARD(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, {})); + merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, {})); // 12. Let options be ! OrdinaryObjectCreate(null). auto* options = Object::create(global_object, nullptr); @@ -315,15 +313,15 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date) MUST(options->create_data_property_or_throw(vm.names.overflow, js_string(vm, vm.names.reject.as_string()))); // 14. Return ? DateFromFields(calendar, mergedFields, options). - return TRY_OR_DISCARD(date_from_fields(global_object, calendar, *merged_fields, *options)); + return TRY(date_from_fields(global_object, calendar, *merged_fields, *options)); } // 9.3.22 Temporal.PlainYearMonth.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.getisofields -JS_DEFINE_OLD_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields) +JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields) { // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). - auto* year_month = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* year_month = TRY(typed_this_object(global_object)); // 3. Let fields be ! OrdinaryObjectCreate(%Object.prototype%). auto* fields = Object::create(global_object, global_object.object_prototype()); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h index a4a48945a0..4dc0ed0135 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h @@ -20,23 +20,23 @@ public: virtual ~PlainYearMonthPrototype() override = default; private: - JS_DECLARE_OLD_NATIVE_FUNCTION(calendar_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(year_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(month_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(month_code_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(days_in_year_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(days_in_month_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(months_in_year_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(in_leap_year_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(era_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(era_year_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(equals); - JS_DECLARE_OLD_NATIVE_FUNCTION(to_string); - JS_DECLARE_OLD_NATIVE_FUNCTION(to_locale_string); - JS_DECLARE_OLD_NATIVE_FUNCTION(to_json); - JS_DECLARE_OLD_NATIVE_FUNCTION(value_of); - JS_DECLARE_OLD_NATIVE_FUNCTION(to_plain_date); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_iso_fields); + JS_DECLARE_NATIVE_FUNCTION(calendar_getter); + JS_DECLARE_NATIVE_FUNCTION(year_getter); + JS_DECLARE_NATIVE_FUNCTION(month_getter); + JS_DECLARE_NATIVE_FUNCTION(month_code_getter); + JS_DECLARE_NATIVE_FUNCTION(days_in_year_getter); + JS_DECLARE_NATIVE_FUNCTION(days_in_month_getter); + JS_DECLARE_NATIVE_FUNCTION(months_in_year_getter); + JS_DECLARE_NATIVE_FUNCTION(in_leap_year_getter); + JS_DECLARE_NATIVE_FUNCTION(era_getter); + JS_DECLARE_NATIVE_FUNCTION(era_year_getter); + JS_DECLARE_NATIVE_FUNCTION(equals); + JS_DECLARE_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(to_locale_string); + JS_DECLARE_NATIVE_FUNCTION(to_json); + JS_DECLARE_NATIVE_FUNCTION(value_of); + JS_DECLARE_NATIVE_FUNCTION(to_plain_date); + JS_DECLARE_NATIVE_FUNCTION(get_iso_fields); }; }