1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:27:45 +00:00

LibJS: Fix TemporalDurationLike property order

The table is sorted alphabetically and supposed to be iterated in that
oder. Also move this to a templated lambda for later re-use with
different target structs and value types.
This commit is contained in:
Linus Groh 2021-07-18 22:28:30 +01:00
parent 152251f5a7
commit 7355c23e17
2 changed files with 26 additions and 18 deletions

View file

@ -57,6 +57,31 @@ struct PartialDuration {
Optional<double> nanoseconds;
};
// Table 7: Properties of a TemporalDurationLike, https://tc39.es/proposal-temporal/#table-temporal-temporaldurationlike-properties
template<typename StructT, typename ValueT>
struct TemporalDurationLikeProperty {
ValueT StructT::*internal_slot { nullptr };
PropertyName property;
};
template<typename StructT, typename ValueT>
auto temporal_duration_like_properties = [](VM& vm) {
using PropertyT = TemporalDurationLikeProperty<StructT, ValueT>;
return AK::Array<PropertyT, 10> {
PropertyT { &StructT::days, vm.names.days },
PropertyT { &StructT::hours, vm.names.hours },
PropertyT { &StructT::microseconds, vm.names.microseconds },
PropertyT { &StructT::milliseconds, vm.names.milliseconds },
PropertyT { &StructT::minutes, vm.names.minutes },
PropertyT { &StructT::months, vm.names.months },
PropertyT { &StructT::nanoseconds, vm.names.nanoseconds },
PropertyT { &StructT::seconds, vm.names.seconds },
PropertyT { &StructT::weeks, vm.names.weeks },
PropertyT { &StructT::years, vm.names.years },
};
};
i8 duration_sign(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
bool is_valid_duration(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
PartialDuration to_partial_duration(GlobalObject&, Value temporal_duration_like);