diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-21 19:56:25 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-21 22:31:09 +0100 |
commit | 5e9e3f9dc868121a8d8b274756f32cddabb72f6a (patch) | |
tree | 1800aaf602c6a725ea4c9afee739dc2f5ba25fc1 /Userland | |
parent | 2d2ba4eec66205834e3c1a97b716cd3d68f41a6c (diff) | |
download | serenity-5e9e3f9dc868121a8d8b274756f32cddabb72f6a.zip |
LibJS: Convert Temporal.Duration functions to ThrowCompletionOr
Diffstat (limited to 'Userland')
4 files changed, 72 insertions, 73 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp index 8c898e6c9b..3adb296e8f 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp @@ -28,7 +28,7 @@ void DurationConstructor::initialize(GlobalObject& global_object) define_direct_property(vm.names.prototype, global_object.temporal_duration_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(0), Attribute::Configurable); } @@ -84,7 +84,7 @@ ThrowCompletionOr<Object*> DurationConstructor::construct(FunctionObject& new_ta } // 7.2.2 Temporal.Duration.from ( item ), https://tc39.es/proposal-temporal/#sec-temporal.duration.from -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationConstructor::from) +JS_DEFINE_NATIVE_FUNCTION(DurationConstructor::from) { auto item = vm.argument(0); @@ -93,11 +93,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DurationConstructor::from) auto& duration = static_cast<Duration&>(item.as_object()); // a. Return ? CreateTemporalDuration(item.[[Years]], item.[[Months]], item.[[Weeks]], item.[[Days]], item.[[Hours]], item.[[Minutes]], item.[[Seconds]], item.[[Milliseconds]], item.[[Microseconds]], item.[[Nanoseconds]]). - return TRY_OR_DISCARD(create_temporal_duration(global_object, duration.years(), duration.months(), duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.milliseconds(), duration.microseconds(), duration.nanoseconds())); + return TRY(create_temporal_duration(global_object, duration.years(), duration.months(), duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.milliseconds(), duration.microseconds(), duration.nanoseconds())); } // 2. Return ? ToTemporalDuration(item). - return TRY_OR_DISCARD(to_temporal_duration(global_object, item)); + return TRY(to_temporal_duration(global_object, item)); } } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.h b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.h index 47a2f1ddf2..35cd992b8c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.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/DurationPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp index 8c27e90281..9b097af06d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp @@ -27,153 +27,153 @@ void DurationPrototype::initialize(GlobalObject& global_object) // 7.3.2 Temporal.Duration.prototype[ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype-@@tostringtag define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal.Duration"), Attribute::Configurable); - define_old_native_accessor(vm.names.years, years_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.months, months_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.weeks, weeks_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.days, days_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.hours, hours_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.minutes, minutes_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.seconds, seconds_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.milliseconds, milliseconds_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.microseconds, microseconds_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.nanoseconds, nanoseconds_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.sign, sign_getter, {}, Attribute::Configurable); - define_old_native_accessor(vm.names.blank, blank_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.years, years_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.months, months_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.weeks, weeks_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.days, days_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.hours, hours_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.minutes, minutes_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.seconds, seconds_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.milliseconds, milliseconds_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.microseconds, microseconds_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.nanoseconds, nanoseconds_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.sign, sign_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.blank, blank_getter, {}, Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; - define_old_native_function(vm.names.with, with, 1, attr); - define_old_native_function(vm.names.negated, negated, 0, attr); - define_old_native_function(vm.names.abs, abs, 0, attr); - define_old_native_function(vm.names.valueOf, value_of, 0, attr); + define_native_function(vm.names.with, with, 1, attr); + define_native_function(vm.names.negated, negated, 0, attr); + define_native_function(vm.names.abs, abs, 0, attr); + define_native_function(vm.names.valueOf, value_of, 0, attr); } // 7.3.3 get Temporal.Duration.prototype.years, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.years -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::years_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::years_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Years]]. return Value(duration->years()); } // 7.3.4 get Temporal.Duration.prototype.months, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.months -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::months_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::months_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Months]]. return Value(duration->months()); } // 7.3.5 get Temporal.Duration.prototype.weeks, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.weeks -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::weeks_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::weeks_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Weeks]]. return Value(duration->weeks()); } // 7.3.6 get Temporal.Duration.prototype.days, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.days -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::days_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::days_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Days]]. return Value(duration->days()); } // 7.3.7 get Temporal.Duration.prototype.hours, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.hours -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::hours_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::hours_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Hours]]. return Value(duration->hours()); } // 7.3.8 get Temporal.Duration.prototype.minutes, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.minutes -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::minutes_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::minutes_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Minutes]]. return Value(duration->minutes()); } // 7.3.9 get Temporal.Duration.prototype.seconds, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.seconds -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::seconds_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::seconds_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Seconds]]. return Value(duration->seconds()); } // 7.3.10 get Temporal.Duration.prototype.milliseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.milliseconds -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::milliseconds_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::milliseconds_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Milliseconds]]. return Value(duration->milliseconds()); } // 7.3.11 get Temporal.Duration.prototype.microseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.microseconds -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::microseconds_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::microseconds_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Microseconds]]. return Value(duration->microseconds()); } // 7.3.12 get Temporal.Duration.prototype.nanoseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.nanoseconds -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::nanoseconds_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::nanoseconds_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return duration.[[Nanoseconds]]. return Value(duration->nanoseconds()); } // 7.3.13 get Temporal.Duration.prototype.sign, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.sign -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::sign_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::sign_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return ! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]). return Value(duration_sign(duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds())); } // 7.3.14 get Temporal.Duration.prototype.blank, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.blank -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::blank_getter) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::blank_getter) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Let sign be ! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]). auto sign = duration_sign(duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds()); @@ -187,14 +187,14 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::blank_getter) } // 7.3.15 Temporal.Duration.prototype.with ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.with -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::with) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::with) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Let temporalDurationLike be ? ToPartialDuration(temporalDurationLike). - auto temporal_duration_like = TRY_OR_DISCARD(to_partial_duration(global_object, vm.argument(0))); + auto temporal_duration_like = TRY(to_partial_duration(global_object, vm.argument(0))); // 4. If temporalDurationLike.[[Years]] is not undefined, then // a. Let years be temporalDurationLike.[[Years]]. @@ -257,37 +257,36 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::with) auto nanoseconds = temporal_duration_like.nanoseconds.value_or(duration->nanoseconds()); // 24. Return ? CreateTemporalDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds). - return TRY_OR_DISCARD(create_temporal_duration(global_object, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds)); + return TRY(create_temporal_duration(global_object, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds)); } // 7.3.16 Temporal.Duration.prototype.negated ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.negated -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::negated) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::negated) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return ! CreateNegatedTemporalDuration(duration). return create_negated_temporal_duration(global_object, *duration); } // 7.3.17 Temporal.Duration.prototype.abs ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.abs -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::abs) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::abs) { // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration = TRY_OR_DISCARD(typed_this_object(global_object)); + auto* duration = TRY(typed_this_object(global_object)); // 3. Return ! CreateTemporalDuration(abs(duration.[[Years]]), abs(duration.[[Months]]), abs(duration.[[Weeks]]), abs(duration.[[Days]]), abs(duration.[[Hours]]), abs(duration.[[Minutes]]), abs(duration.[[Seconds]]), abs(duration.[[Milliseconds]]), abs(duration.[[Microseconds]]), abs(duration.[[Nanoseconds]])). - return TRY_OR_DISCARD(create_temporal_duration(global_object, fabs(duration->years()), fabs(duration->months()), fabs(duration->weeks()), fabs(duration->days()), fabs(duration->hours()), fabs(duration->minutes()), fabs(duration->seconds()), fabs(duration->milliseconds()), fabs(duration->microseconds()), fabs(duration->nanoseconds()))); + return TRY(create_temporal_duration(global_object, fabs(duration->years()), fabs(duration->months()), fabs(duration->weeks()), fabs(duration->days()), fabs(duration->hours()), fabs(duration->minutes()), fabs(duration->seconds()), fabs(duration->milliseconds()), fabs(duration->microseconds()), fabs(duration->nanoseconds()))); } // 7.3.25 Temporal.Duration.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.valueof -JS_DEFINE_OLD_NATIVE_FUNCTION(DurationPrototype::value_of) +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::value_of) { // 1. Throw a TypeError exception. - vm.throw_exception<TypeError>(global_object, ErrorType::Convert, "Temporal.Duration", "a primitive value"); - return {}; + return vm.throw_completion<TypeError>(global_object, ErrorType::Convert, "Temporal.Duration", "a primitive value"); } } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.h index ad5bb382d7..24d82649fe 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.h @@ -20,22 +20,22 @@ public: virtual ~DurationPrototype() override = default; private: - JS_DECLARE_OLD_NATIVE_FUNCTION(years_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(months_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(weeks_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(days_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(hours_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(minutes_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(seconds_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(milliseconds_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(microseconds_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(nanoseconds_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(sign_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(blank_getter); - JS_DECLARE_OLD_NATIVE_FUNCTION(with); - JS_DECLARE_OLD_NATIVE_FUNCTION(negated); - JS_DECLARE_OLD_NATIVE_FUNCTION(abs); - JS_DECLARE_OLD_NATIVE_FUNCTION(value_of); + JS_DECLARE_NATIVE_FUNCTION(years_getter); + JS_DECLARE_NATIVE_FUNCTION(months_getter); + JS_DECLARE_NATIVE_FUNCTION(weeks_getter); + JS_DECLARE_NATIVE_FUNCTION(days_getter); + JS_DECLARE_NATIVE_FUNCTION(hours_getter); + JS_DECLARE_NATIVE_FUNCTION(minutes_getter); + JS_DECLARE_NATIVE_FUNCTION(seconds_getter); + JS_DECLARE_NATIVE_FUNCTION(milliseconds_getter); + JS_DECLARE_NATIVE_FUNCTION(microseconds_getter); + JS_DECLARE_NATIVE_FUNCTION(nanoseconds_getter); + JS_DECLARE_NATIVE_FUNCTION(sign_getter); + JS_DECLARE_NATIVE_FUNCTION(blank_getter); + JS_DECLARE_NATIVE_FUNCTION(with); + JS_DECLARE_NATIVE_FUNCTION(negated); + JS_DECLARE_NATIVE_FUNCTION(abs); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; } |