From 7085458a230b9307682a4a4b86ec2d1a22ceaa6e Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 21 Oct 2021 20:18:24 +0100 Subject: [PATCH] LibJS: Convert Temporal.TimeZone functions to ThrowCompletionOr --- .../Runtime/Temporal/TimeZoneConstructor.cpp | 6 +-- .../Runtime/Temporal/TimeZoneConstructor.h | 2 +- .../Runtime/Temporal/TimeZonePrototype.cpp | 46 +++++++++---------- .../Runtime/Temporal/TimeZonePrototype.h | 12 ++--- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp index 2d99e5b22b..6d1038f5ac 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp @@ -26,7 +26,7 @@ void TimeZoneConstructor::initialize(GlobalObject& global_object) define_direct_property(vm.names.prototype, global_object.temporal_time_zone_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; - define_old_native_function(vm.names.from, from, 1, attr); + define_native_function(vm.names.from, from, 1, attr); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -77,12 +77,12 @@ ThrowCompletionOr TimeZoneConstructor::construct(FunctionObject& new_ta } // 11.3.2 Temporal.TimeZone.from ( item ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.from -JS_DEFINE_OLD_NATIVE_FUNCTION(TimeZoneConstructor::from) +JS_DEFINE_NATIVE_FUNCTION(TimeZoneConstructor::from) { auto item = vm.argument(0); // 1. Return ? ToTemporalTimeZone(item). - return TRY_OR_DISCARD(to_temporal_time_zone(global_object, item)); + return TRY(to_temporal_time_zone(global_object, item)); } } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.h b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.h index 0b071fb722..b5b51265ae 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.h @@ -24,7 +24,7 @@ public: private: virtual bool has_constructor() const override { return true; } - JS_DECLARE_OLD_NATIVE_FUNCTION(from); + JS_DECLARE_NATIVE_FUNCTION(from); }; } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp index 36388ab8e9..9e11fe628f 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp @@ -27,36 +27,36 @@ void TimeZonePrototype::initialize(GlobalObject& global_object) auto& vm = this->vm(); u8 attr = Attribute::Writable | Attribute::Configurable; - define_old_native_accessor(vm.names.id, id_getter, {}, Attribute::Configurable); - define_old_native_function(vm.names.getOffsetNanosecondsFor, get_offset_nanoseconds_for, 1, attr); - define_old_native_function(vm.names.getOffsetStringFor, get_offset_string_for, 1, attr); - define_old_native_function(vm.names.getPlainDateTimeFor, get_plain_date_time_for, 1, attr); - define_old_native_function(vm.names.toString, to_string, 0, attr); - define_old_native_function(vm.names.toJSON, to_json, 0, attr); + define_native_accessor(vm.names.id, id_getter, {}, Attribute::Configurable); + define_native_function(vm.names.getOffsetNanosecondsFor, get_offset_nanoseconds_for, 1, attr); + define_native_function(vm.names.getOffsetStringFor, get_offset_string_for, 1, attr); + define_native_function(vm.names.getPlainDateTimeFor, get_plain_date_time_for, 1, attr); + define_native_function(vm.names.toString, to_string, 0, attr); + define_native_function(vm.names.toJSON, to_json, 0, attr); // 11.4.2 Temporal.TimeZone.prototype[ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype-@@tostringtag define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal.TimeZone"), Attribute::Configurable); } // 11.4.3 get Temporal.TimeZone.prototype.id, https://tc39.es/proposal-temporal/#sec-get-temporal.timezone.prototype.id -JS_DEFINE_OLD_NATIVE_FUNCTION(TimeZonePrototype::id_getter) +JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::id_getter) { // 1. Let timeZone be the this value. auto time_zone = vm.this_value(global_object); // 2. Return ? ToString(timeZone). - return js_string(vm, TRY_OR_DISCARD(time_zone.to_string(global_object))); + return js_string(vm, TRY(time_zone.to_string(global_object))); } // 11.4.4 Temporal.TimeZone.prototype.getOffsetNanosecondsFor ( instant ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getoffsetnanosecondsfor -JS_DEFINE_OLD_NATIVE_FUNCTION(TimeZonePrototype::get_offset_nanoseconds_for) +JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_offset_nanoseconds_for) { // 1. Let timeZone be the this value. // 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimeZone]]). - auto* time_zone = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* time_zone = TRY(typed_this_object(global_object)); // 3. Set instant to ? ToTemporalInstant(instant). - auto* instant = TRY_OR_DISCARD(to_temporal_instant(global_object, vm.argument(0))); + auto* instant = TRY(to_temporal_instant(global_object, vm.argument(0))); // 4. If timeZone.[[OffsetNanoseconds]] is not undefined, return 𝔽(timeZone.[[OffsetNanoseconds]]). if (time_zone->offset_nanoseconds().has_value()) @@ -67,55 +67,55 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(TimeZonePrototype::get_offset_nanoseconds_for) } // 11.4.5 Temporal.TimeZone.prototype.getOffsetStringFor ( instant ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getoffsetstringfor -JS_DEFINE_OLD_NATIVE_FUNCTION(TimeZonePrototype::get_offset_string_for) +JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_offset_string_for) { // 1. Let timeZone be the this value. // 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimeZone]]). - auto* time_zone = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* time_zone = TRY(typed_this_object(global_object)); // 3. Set instant to ? ToTemporalInstant(instant). - auto* instant = TRY_OR_DISCARD(to_temporal_instant(global_object, vm.argument(0))); + auto* instant = TRY(to_temporal_instant(global_object, vm.argument(0))); // 4. Return ? BuiltinTimeZoneGetOffsetStringFor(timeZone, instant). - auto offset_string = TRY_OR_DISCARD(builtin_time_zone_get_offset_string_for(global_object, time_zone, *instant)); + auto offset_string = TRY(builtin_time_zone_get_offset_string_for(global_object, time_zone, *instant)); return js_string(vm, move(offset_string)); } // 11.4.6 Temporal.TimeZone.prototype.getPlainDateTimeFor ( instant [ , calendarLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getplaindatetimefor -JS_DEFINE_OLD_NATIVE_FUNCTION(TimeZonePrototype::get_plain_date_time_for) +JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_plain_date_time_for) { // 1. Let timeZone be the this value. auto time_zone = vm.this_value(global_object); // 2. Set instant to ? ToTemporalInstant(instant). - auto* instant = TRY_OR_DISCARD(to_temporal_instant(global_object, vm.argument(0))); + auto* instant = TRY(to_temporal_instant(global_object, vm.argument(0))); // 3. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). - auto* calendar = TRY_OR_DISCARD(to_temporal_calendar_with_iso_default(global_object, vm.argument(1))); + auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, vm.argument(1))); // 4. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar). - return TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar)); + return TRY(builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar)); } // 11.4.11 Temporal.TimeZone.prototype.toString ( ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.tostring -JS_DEFINE_OLD_NATIVE_FUNCTION(TimeZonePrototype::to_string) +JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::to_string) { // 1. Let timeZone be the this value. // 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimeZone]]). - auto* time_zone = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* time_zone = TRY(typed_this_object(global_object)); // 3. Return timeZone.[[Identifier]]. return js_string(vm, time_zone->identifier()); } // 11.4.12 Temporal.TimeZone.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.tojson -JS_DEFINE_OLD_NATIVE_FUNCTION(TimeZonePrototype::to_json) +JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::to_json) { // 1. Let timeZone be the this value. auto time_zone = vm.this_value(global_object); // 2. Return ? ToString(timeZone). - return js_string(vm, TRY_OR_DISCARD(time_zone.to_string(global_object))); + return js_string(vm, TRY(time_zone.to_string(global_object))); } } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.h index 62f30c4a2c..3137cb5ee3 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.h @@ -20,12 +20,12 @@ public: virtual ~TimeZonePrototype() override = default; private: - JS_DECLARE_OLD_NATIVE_FUNCTION(id_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_offset_nanoseconds_for); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_offset_string_for); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_plain_date_time_for); - JS_DECLARE_OLD_NATIVE_FUNCTION(to_string); - JS_DECLARE_OLD_NATIVE_FUNCTION(to_json); + JS_DECLARE_NATIVE_FUNCTION(id_getter); + JS_DECLARE_NATIVE_FUNCTION(get_offset_nanoseconds_for); + JS_DECLARE_NATIVE_FUNCTION(get_offset_string_for); + JS_DECLARE_NATIVE_FUNCTION(get_plain_date_time_for); + JS_DECLARE_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(to_json); }; }