mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 17:24:48 -05:00
LibJS: Pass ISO types by value vs. const-reference more correctly
We were passing types like ISODate by reference so that they could be
used as forward-declarations. But after commit 021a5f4ded
, we now have
their full definitions anywhere they're needed. So let's pass ISODate by
value everywhere consistently - it is only 8 bytes.
This commit is contained in:
parent
2d9405e5d7
commit
ade510fe17
Notes:
github-actions[bot]
2024-11-26 16:36:32 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/ade510fe17d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2590 Reviewed-by: https://github.com/gmta ✅
6 changed files with 20 additions and 20 deletions
|
@ -75,7 +75,7 @@ double epoch_days_to_epoch_ms(double day, double time)
|
|||
}
|
||||
|
||||
// 13.4 CheckISODaysRange ( isoDate ), https://tc39.es/proposal-temporal/#sec-checkisodaysrange
|
||||
ThrowCompletionOr<void> check_iso_days_range(VM& vm, ISODate const& iso_date)
|
||||
ThrowCompletionOr<void> check_iso_days_range(VM& vm, ISODate iso_date)
|
||||
{
|
||||
// 1. If abs(ISODateToEpochDays(isoDate.[[Year]], isoDate.[[Month]] - 1, isoDate.[[Day]])) > 10**8, then
|
||||
if (fabs(iso_date_to_epoch_days(iso_date.year, iso_date.month - 1, iso_date.day)) > 100'000'000) {
|
||||
|
@ -1725,7 +1725,7 @@ ThrowCompletionOr<String> to_offset_string(VM& vm, Value argument)
|
|||
}
|
||||
|
||||
// 13.42 ISODateToFields ( calendar, isoDate, type ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetofields
|
||||
CalendarFields iso_date_to_fields(StringView calendar, ISODate const& iso_date, DateType type)
|
||||
CalendarFields iso_date_to_fields(StringView calendar, ISODate iso_date, DateType type)
|
||||
{
|
||||
// 1. Let fields be an empty Calendar Fields Record with all fields set to unset.
|
||||
auto fields = CalendarFields::unset();
|
||||
|
|
|
@ -172,7 +172,7 @@ struct DifferenceSettings {
|
|||
|
||||
double iso_date_to_epoch_days(double year, double month, double date);
|
||||
double epoch_days_to_epoch_ms(double day, double time);
|
||||
ThrowCompletionOr<void> check_iso_days_range(VM&, ISODate const&);
|
||||
ThrowCompletionOr<void> check_iso_days_range(VM&, ISODate);
|
||||
ThrowCompletionOr<Overflow> get_temporal_overflow_option(VM&, Object const& options);
|
||||
ThrowCompletionOr<Disambiguation> get_temporal_disambiguation_option(VM&, Object const& options);
|
||||
RoundingMode negate_rounding_mode(RoundingMode);
|
||||
|
@ -206,7 +206,7 @@ ThrowCompletionOr<GC::Ref<Duration>> parse_temporal_duration_string(VM&, StringV
|
|||
ThrowCompletionOr<TimeZone> parse_temporal_time_zone_string(VM&, StringView time_zone_string);
|
||||
ThrowCompletionOr<String> to_month_code(VM&, Value argument);
|
||||
ThrowCompletionOr<String> to_offset_string(VM&, Value argument);
|
||||
CalendarFields iso_date_to_fields(StringView calendar, ISODate const&, DateType);
|
||||
CalendarFields iso_date_to_fields(StringView calendar, ISODate, DateType);
|
||||
ThrowCompletionOr<DifferenceSettings> get_difference_settings(VM&, DurationOperation, Object const& options, UnitGroup, ReadonlySpan<Unit> disallowed_units, Unit fallback_smallest_unit, Unit smallest_largest_default_unit);
|
||||
|
||||
// 13.38 ToIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerwithtruncation
|
||||
|
|
|
@ -316,7 +316,7 @@ CalendarFields calendar_merge_fields(StringView calendar, CalendarFields const&
|
|||
}
|
||||
|
||||
// 12.2.6 CalendarDateAdd ( calendar, isoDate, duration, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateadd
|
||||
ThrowCompletionOr<ISODate> calendar_date_add(VM& vm, StringView calendar, ISODate const& iso_date, DateDuration const& duration, Overflow overflow)
|
||||
ThrowCompletionOr<ISODate> calendar_date_add(VM& vm, StringView calendar, ISODate iso_date, DateDuration const& duration, Overflow overflow)
|
||||
{
|
||||
ISODate result;
|
||||
|
||||
|
@ -349,7 +349,7 @@ ThrowCompletionOr<ISODate> calendar_date_add(VM& vm, StringView calendar, ISODat
|
|||
}
|
||||
|
||||
// 12.2.7 CalendarDateUntil ( calendar, one, two, largestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateuntil
|
||||
DateDuration calendar_date_until(VM& vm, StringView calendar, ISODate const& one, ISODate const& two, Unit largest_unit)
|
||||
DateDuration calendar_date_until(VM& vm, StringView calendar, ISODate one, ISODate two, Unit largest_unit)
|
||||
{
|
||||
// 1. If calendar is "iso8601", then
|
||||
if (calendar == "iso8601"sv) {
|
||||
|
@ -610,7 +610,7 @@ u8 iso_days_in_month(double year, double month)
|
|||
}
|
||||
|
||||
// 12.2.16 ISOWeekOfYear ( isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-isoweekofyear
|
||||
YearWeek iso_week_of_year(ISODate const& iso_date)
|
||||
YearWeek iso_week_of_year(ISODate iso_date)
|
||||
{
|
||||
// 1. Let year be isoDate.[[Year]].
|
||||
auto year = iso_date.year;
|
||||
|
@ -691,7 +691,7 @@ YearWeek iso_week_of_year(ISODate const& iso_date)
|
|||
}
|
||||
|
||||
// 12.2.17 ISODayOfYear ( isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-isodayofyear
|
||||
u16 iso_day_of_year(ISODate const& iso_date)
|
||||
u16 iso_day_of_year(ISODate iso_date)
|
||||
{
|
||||
// 1. Let epochDays be ISODateToEpochDays(isoDate.[[Year]], isoDate.[[Month]] - 1, isoDate.[[Day]]).
|
||||
auto epoch_days = iso_date_to_epoch_days(iso_date.year, iso_date.month - 1, iso_date.day);
|
||||
|
@ -701,7 +701,7 @@ u16 iso_day_of_year(ISODate const& iso_date)
|
|||
}
|
||||
|
||||
// 12.2.18 ISODayOfWeek ( isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-isodayofweek
|
||||
u8 iso_day_of_week(ISODate const& iso_date)
|
||||
u8 iso_day_of_week(ISODate iso_date)
|
||||
{
|
||||
// 1. Let epochDays be ISODateToEpochDays(isoDate.[[Year]], isoDate.[[Month]] - 1, isoDate.[[Day]]).
|
||||
auto epoch_days = iso_date_to_epoch_days(iso_date.year, iso_date.month - 1, iso_date.day);
|
||||
|
@ -764,7 +764,7 @@ ThrowCompletionOr<ISODate> calendar_month_day_to_iso_reference_date(VM& vm, Stri
|
|||
}
|
||||
|
||||
// 12.2.21 CalendarISOToDate ( calendar, isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-calendarisotodate
|
||||
CalendarDate calendar_iso_to_date(StringView calendar, ISODate const& iso_date)
|
||||
CalendarDate calendar_iso_to_date(StringView calendar, ISODate iso_date)
|
||||
{
|
||||
// 1. If calendar is "iso8601", then
|
||||
if (calendar == "iso8601"sv) {
|
||||
|
|
|
@ -105,18 +105,18 @@ ThrowCompletionOr<ISODate> calendar_month_day_from_fields(VM&, StringView calend
|
|||
String format_calendar_annotation(StringView id, ShowCalendar);
|
||||
bool calendar_equals(StringView one, StringView two);
|
||||
u8 iso_days_in_month(double year, double month);
|
||||
YearWeek iso_week_of_year(ISODate const&);
|
||||
u16 iso_day_of_year(ISODate const&);
|
||||
u8 iso_day_of_week(ISODate const&);
|
||||
YearWeek iso_week_of_year(ISODate);
|
||||
u16 iso_day_of_year(ISODate);
|
||||
u8 iso_day_of_week(ISODate);
|
||||
Vector<CalendarField> calendar_field_keys_present(CalendarFields const&);
|
||||
CalendarFields calendar_merge_fields(StringView calendar, CalendarFields const& fields, CalendarFields const& additional_fields);
|
||||
ThrowCompletionOr<ISODate> calendar_date_add(VM&, StringView calendar, ISODate const&, DateDuration const&, Overflow);
|
||||
DateDuration calendar_date_until(VM&, StringView calendar, ISODate const&, ISODate const&, Unit largest_unit);
|
||||
ThrowCompletionOr<ISODate> calendar_date_add(VM&, StringView calendar, ISODate, DateDuration const&, Overflow);
|
||||
DateDuration calendar_date_until(VM&, StringView calendar, ISODate, ISODate, Unit largest_unit);
|
||||
ThrowCompletionOr<String> to_temporal_calendar_identifier(VM&, Value temporal_calendar_like);
|
||||
ThrowCompletionOr<String> get_temporal_calendar_identifier_with_iso_default(VM&, Object const& item);
|
||||
ThrowCompletionOr<ISODate> calendar_date_to_iso(VM&, StringView calendar, CalendarFields const&, Overflow);
|
||||
ThrowCompletionOr<ISODate> calendar_month_day_to_iso_reference_date(VM&, StringView calendar, CalendarFields const&, Overflow);
|
||||
CalendarDate calendar_iso_to_date(StringView calendar, ISODate const&);
|
||||
CalendarDate calendar_iso_to_date(StringView calendar, ISODate);
|
||||
Vector<CalendarField> calendar_extra_fields(StringView calendar, CalendarFieldList);
|
||||
Vector<CalendarField> calendar_field_keys_to_ignore(StringView calendar, ReadonlySpan<CalendarField>);
|
||||
ThrowCompletionOr<void> calendar_resolve_fields(VM&, StringView calendar, CalendarFields&, DateType);
|
||||
|
|
|
@ -29,7 +29,7 @@ PlainDateTime::PlainDateTime(ISODateTime const& iso_date_time, String calendar,
|
|||
}
|
||||
|
||||
// 5.5.3 CombineISODateAndTimeRecord ( isoDate, time ), https://tc39.es/proposal-temporal/#sec-temporal-combineisodateandtimerecord
|
||||
ISODateTime combine_iso_date_and_time_record(ISODate iso_date, Time time)
|
||||
ISODateTime combine_iso_date_and_time_record(ISODate iso_date, Time const& time)
|
||||
{
|
||||
// 1. NOTE: time.[[Days]] is ignored.
|
||||
// 2. Return ISO Date-Time Record { [[ISODate]]: isoDate, [[Time]]: time }.
|
||||
|
@ -43,7 +43,7 @@ static auto const DATETIME_NANOSECONDS_MIN = "-8640000086400000000000"_sbigint;
|
|||
static auto const DATETIME_NANOSECONDS_MAX = "8640000086400000000000"_sbigint;
|
||||
|
||||
// 5.5.4 ISODateTimeWithinLimits ( isoDateTime ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetimewithinlimits
|
||||
bool iso_date_time_within_limits(ISODateTime iso_date_time)
|
||||
bool iso_date_time_within_limits(ISODateTime const& iso_date_time)
|
||||
{
|
||||
// 1. If abs(ISODateToEpochDays(isoDateTime.[[ISODate]].[[Year]], isoDateTime.[[ISODate]].[[Month]] - 1, isoDateTime.[[ISODate]].[[Day]])) > 10**8 + 1, return false.
|
||||
if (fabs(iso_date_to_epoch_days(iso_date_time.iso_date.year, iso_date_time.iso_date.month - 1, iso_date_time.iso_date.day)) > 100000001)
|
||||
|
|
|
@ -32,8 +32,8 @@ private:
|
|||
String m_calendar; // [[Calendar]]
|
||||
};
|
||||
|
||||
ISODateTime combine_iso_date_and_time_record(ISODate, Time);
|
||||
bool iso_date_time_within_limits(ISODateTime);
|
||||
ISODateTime combine_iso_date_and_time_record(ISODate, Time const&);
|
||||
bool iso_date_time_within_limits(ISODateTime const&);
|
||||
ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(VM&, StringView calendar, CalendarFields&, Overflow);
|
||||
ThrowCompletionOr<GC::Ref<PlainDateTime>> to_temporal_date_time(VM&, Value item, Value options = js_undefined());
|
||||
ISODateTime balance_iso_date_time(double year, double month, double day, double hour, double minute, double second, double millisecond, double microsecond, double nanosecond);
|
||||
|
|
Loading…
Reference in a new issue