Skip to content

Commit ade510f

Browse files
committed
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 021a5f4, we now have their full definitions anywhere they're needed. So let's pass ISODate by value everywhere consistently - it is only 8 bytes.
1 parent 2d9405e commit ade510f

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ double epoch_days_to_epoch_ms(double day, double time)
7575
}
7676

7777
// 13.4 CheckISODaysRange ( isoDate ), https://tc39.es/proposal-temporal/#sec-checkisodaysrange
78-
ThrowCompletionOr<void> check_iso_days_range(VM& vm, ISODate const& iso_date)
78+
ThrowCompletionOr<void> check_iso_days_range(VM& vm, ISODate iso_date)
7979
{
8080
// 1. If abs(ISODateToEpochDays(isoDate.[[Year]], isoDate.[[Month]] - 1, isoDate.[[Day]])) > 10**8, then
8181
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)
17251725
}
17261726

17271727
// 13.42 ISODateToFields ( calendar, isoDate, type ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetofields
1728-
CalendarFields iso_date_to_fields(StringView calendar, ISODate const& iso_date, DateType type)
1728+
CalendarFields iso_date_to_fields(StringView calendar, ISODate iso_date, DateType type)
17291729
{
17301730
// 1. Let fields be an empty Calendar Fields Record with all fields set to unset.
17311731
auto fields = CalendarFields::unset();

Libraries/LibJS/Runtime/Temporal/AbstractOperations.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct DifferenceSettings {
172172

173173
double iso_date_to_epoch_days(double year, double month, double date);
174174
double epoch_days_to_epoch_ms(double day, double time);
175-
ThrowCompletionOr<void> check_iso_days_range(VM&, ISODate const&);
175+
ThrowCompletionOr<void> check_iso_days_range(VM&, ISODate);
176176
ThrowCompletionOr<Overflow> get_temporal_overflow_option(VM&, Object const& options);
177177
ThrowCompletionOr<Disambiguation> get_temporal_disambiguation_option(VM&, Object const& options);
178178
RoundingMode negate_rounding_mode(RoundingMode);
@@ -206,7 +206,7 @@ ThrowCompletionOr<GC::Ref<Duration>> parse_temporal_duration_string(VM&, StringV
206206
ThrowCompletionOr<TimeZone> parse_temporal_time_zone_string(VM&, StringView time_zone_string);
207207
ThrowCompletionOr<String> to_month_code(VM&, Value argument);
208208
ThrowCompletionOr<String> to_offset_string(VM&, Value argument);
209-
CalendarFields iso_date_to_fields(StringView calendar, ISODate const&, DateType);
209+
CalendarFields iso_date_to_fields(StringView calendar, ISODate, DateType);
210210
ThrowCompletionOr<DifferenceSettings> get_difference_settings(VM&, DurationOperation, Object const& options, UnitGroup, ReadonlySpan<Unit> disallowed_units, Unit fallback_smallest_unit, Unit smallest_largest_default_unit);
211211

212212
// 13.38 ToIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerwithtruncation

Libraries/LibJS/Runtime/Temporal/Calendar.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ CalendarFields calendar_merge_fields(StringView calendar, CalendarFields const&
316316
}
317317

318318
// 12.2.6 CalendarDateAdd ( calendar, isoDate, duration, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateadd
319-
ThrowCompletionOr<ISODate> calendar_date_add(VM& vm, StringView calendar, ISODate const& iso_date, DateDuration const& duration, Overflow overflow)
319+
ThrowCompletionOr<ISODate> calendar_date_add(VM& vm, StringView calendar, ISODate iso_date, DateDuration const& duration, Overflow overflow)
320320
{
321321
ISODate result;
322322

@@ -349,7 +349,7 @@ ThrowCompletionOr<ISODate> calendar_date_add(VM& vm, StringView calendar, ISODat
349349
}
350350

351351
// 12.2.7 CalendarDateUntil ( calendar, one, two, largestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateuntil
352-
DateDuration calendar_date_until(VM& vm, StringView calendar, ISODate const& one, ISODate const& two, Unit largest_unit)
352+
DateDuration calendar_date_until(VM& vm, StringView calendar, ISODate one, ISODate two, Unit largest_unit)
353353
{
354354
// 1. If calendar is "iso8601", then
355355
if (calendar == "iso8601"sv) {
@@ -610,7 +610,7 @@ u8 iso_days_in_month(double year, double month)
610610
}
611611

612612
// 12.2.16 ISOWeekOfYear ( isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-isoweekofyear
613-
YearWeek iso_week_of_year(ISODate const& iso_date)
613+
YearWeek iso_week_of_year(ISODate iso_date)
614614
{
615615
// 1. Let year be isoDate.[[Year]].
616616
auto year = iso_date.year;
@@ -691,7 +691,7 @@ YearWeek iso_week_of_year(ISODate const& iso_date)
691691
}
692692

693693
// 12.2.17 ISODayOfYear ( isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-isodayofyear
694-
u16 iso_day_of_year(ISODate const& iso_date)
694+
u16 iso_day_of_year(ISODate iso_date)
695695
{
696696
// 1. Let epochDays be ISODateToEpochDays(isoDate.[[Year]], isoDate.[[Month]] - 1, isoDate.[[Day]]).
697697
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)
701701
}
702702

703703
// 12.2.18 ISODayOfWeek ( isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-isodayofweek
704-
u8 iso_day_of_week(ISODate const& iso_date)
704+
u8 iso_day_of_week(ISODate iso_date)
705705
{
706706
// 1. Let epochDays be ISODateToEpochDays(isoDate.[[Year]], isoDate.[[Month]] - 1, isoDate.[[Day]]).
707707
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
764764
}
765765

766766
// 12.2.21 CalendarISOToDate ( calendar, isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-calendarisotodate
767-
CalendarDate calendar_iso_to_date(StringView calendar, ISODate const& iso_date)
767+
CalendarDate calendar_iso_to_date(StringView calendar, ISODate iso_date)
768768
{
769769
// 1. If calendar is "iso8601", then
770770
if (calendar == "iso8601"sv) {

Libraries/LibJS/Runtime/Temporal/Calendar.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,18 @@ ThrowCompletionOr<ISODate> calendar_month_day_from_fields(VM&, StringView calend
105105
String format_calendar_annotation(StringView id, ShowCalendar);
106106
bool calendar_equals(StringView one, StringView two);
107107
u8 iso_days_in_month(double year, double month);
108-
YearWeek iso_week_of_year(ISODate const&);
109-
u16 iso_day_of_year(ISODate const&);
110-
u8 iso_day_of_week(ISODate const&);
108+
YearWeek iso_week_of_year(ISODate);
109+
u16 iso_day_of_year(ISODate);
110+
u8 iso_day_of_week(ISODate);
111111
Vector<CalendarField> calendar_field_keys_present(CalendarFields const&);
112112
CalendarFields calendar_merge_fields(StringView calendar, CalendarFields const& fields, CalendarFields const& additional_fields);
113-
ThrowCompletionOr<ISODate> calendar_date_add(VM&, StringView calendar, ISODate const&, DateDuration const&, Overflow);
114-
DateDuration calendar_date_until(VM&, StringView calendar, ISODate const&, ISODate const&, Unit largest_unit);
113+
ThrowCompletionOr<ISODate> calendar_date_add(VM&, StringView calendar, ISODate, DateDuration const&, Overflow);
114+
DateDuration calendar_date_until(VM&, StringView calendar, ISODate, ISODate, Unit largest_unit);
115115
ThrowCompletionOr<String> to_temporal_calendar_identifier(VM&, Value temporal_calendar_like);
116116
ThrowCompletionOr<String> get_temporal_calendar_identifier_with_iso_default(VM&, Object const& item);
117117
ThrowCompletionOr<ISODate> calendar_date_to_iso(VM&, StringView calendar, CalendarFields const&, Overflow);
118118
ThrowCompletionOr<ISODate> calendar_month_day_to_iso_reference_date(VM&, StringView calendar, CalendarFields const&, Overflow);
119-
CalendarDate calendar_iso_to_date(StringView calendar, ISODate const&);
119+
CalendarDate calendar_iso_to_date(StringView calendar, ISODate);
120120
Vector<CalendarField> calendar_extra_fields(StringView calendar, CalendarFieldList);
121121
Vector<CalendarField> calendar_field_keys_to_ignore(StringView calendar, ReadonlySpan<CalendarField>);
122122
ThrowCompletionOr<void> calendar_resolve_fields(VM&, StringView calendar, CalendarFields&, DateType);

Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PlainDateTime::PlainDateTime(ISODateTime const& iso_date_time, String calendar,
2929
}
3030

3131
// 5.5.3 CombineISODateAndTimeRecord ( isoDate, time ), https://tc39.es/proposal-temporal/#sec-temporal-combineisodateandtimerecord
32-
ISODateTime combine_iso_date_and_time_record(ISODate iso_date, Time time)
32+
ISODateTime combine_iso_date_and_time_record(ISODate iso_date, Time const& time)
3333
{
3434
// 1. NOTE: time.[[Days]] is ignored.
3535
// 2. Return ISO Date-Time Record { [[ISODate]]: isoDate, [[Time]]: time }.
@@ -43,7 +43,7 @@ static auto const DATETIME_NANOSECONDS_MIN = "-8640000086400000000000"_sbigint;
4343
static auto const DATETIME_NANOSECONDS_MAX = "8640000086400000000000"_sbigint;
4444

4545
// 5.5.4 ISODateTimeWithinLimits ( isoDateTime ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetimewithinlimits
46-
bool iso_date_time_within_limits(ISODateTime iso_date_time)
46+
bool iso_date_time_within_limits(ISODateTime const& iso_date_time)
4747
{
4848
// 1. If abs(ISODateToEpochDays(isoDateTime.[[ISODate]].[[Year]], isoDateTime.[[ISODate]].[[Month]] - 1, isoDateTime.[[ISODate]].[[Day]])) > 10**8 + 1, return false.
4949
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)

Libraries/LibJS/Runtime/Temporal/PlainDateTime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class PlainDateTime final : public Object {
3232
String m_calendar; // [[Calendar]]
3333
};
3434

35-
ISODateTime combine_iso_date_and_time_record(ISODate, Time);
36-
bool iso_date_time_within_limits(ISODateTime);
35+
ISODateTime combine_iso_date_and_time_record(ISODate, Time const&);
36+
bool iso_date_time_within_limits(ISODateTime const&);
3737
ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(VM&, StringView calendar, CalendarFields&, Overflow);
3838
ThrowCompletionOr<GC::Ref<PlainDateTime>> to_temporal_date_time(VM&, Value item, Value options = js_undefined());
3939
ISODateTime balance_iso_date_time(double year, double month, double day, double hour, double minute, double second, double millisecond, double microsecond, double nanosecond);

0 commit comments

Comments
 (0)