mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
LibJS: Change LargerOfTwoTemporalUnits AO to return a StringView
This commit is contained in:
parent
2cea4ad508
commit
1039159a6c
7 changed files with 9 additions and 9 deletions
|
@ -764,7 +764,7 @@ ThrowCompletionOr<void> validate_temporal_unit_range(GlobalObject& global_object
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.23 LargerOfTwoTemporalUnits ( u1, u2 ), https://tc39.es/proposal-temporal/#sec-temporal-largeroftwotemporalunits
|
// 13.23 LargerOfTwoTemporalUnits ( u1, u2 ), https://tc39.es/proposal-temporal/#sec-temporal-largeroftwotemporalunits
|
||||||
String larger_of_two_temporal_units(StringView unit1, StringView unit2)
|
StringView larger_of_two_temporal_units(StringView unit1, StringView unit2)
|
||||||
{
|
{
|
||||||
// 1. If either u1 or u2 is "year", return "year".
|
// 1. If either u1 or u2 is "year", return "year".
|
||||||
if (unit1 == "year"sv || unit2 == "year"sv)
|
if (unit1 == "year"sv || unit2 == "year"sv)
|
||||||
|
|
|
@ -118,7 +118,7 @@ ThrowCompletionOr<Optional<String>> to_smallest_temporal_unit(GlobalObject&, Obj
|
||||||
ThrowCompletionOr<String> to_temporal_duration_total_unit(GlobalObject& global_object, Object const& normalized_options);
|
ThrowCompletionOr<String> to_temporal_duration_total_unit(GlobalObject& global_object, Object const& normalized_options);
|
||||||
ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject&, Object const& options);
|
ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject&, Object const& options);
|
||||||
ThrowCompletionOr<void> validate_temporal_unit_range(GlobalObject&, StringView largest_unit, StringView smallest_unit);
|
ThrowCompletionOr<void> validate_temporal_unit_range(GlobalObject&, StringView largest_unit, StringView smallest_unit);
|
||||||
String larger_of_two_temporal_units(StringView, StringView);
|
StringView larger_of_two_temporal_units(StringView, StringView);
|
||||||
ThrowCompletionOr<Object*> merge_largest_unit_option(GlobalObject&, Object& options, String largest_unit);
|
ThrowCompletionOr<Object*> merge_largest_unit_option(GlobalObject&, Object& options, String largest_unit);
|
||||||
Optional<u16> maximum_temporal_duration_rounding_increment(StringView unit);
|
Optional<u16> maximum_temporal_duration_rounding_increment(StringView unit);
|
||||||
ThrowCompletionOr<void> reject_object_with_calendar_or_time_zone(GlobalObject&, Object&);
|
ThrowCompletionOr<void> reject_object_with_calendar_or_time_zone(GlobalObject&, Object&);
|
||||||
|
|
|
@ -992,7 +992,7 @@ ThrowCompletionOr<TemporalDuration> add_duration(GlobalObject& global_object, do
|
||||||
auto* difference_options = Object::create(global_object, nullptr);
|
auto* difference_options = Object::create(global_object, nullptr);
|
||||||
|
|
||||||
// k. Perform ! CreateDataPropertyOrThrow(differenceOptions, "largestUnit", dateLargestUnit).
|
// k. Perform ! CreateDataPropertyOrThrow(differenceOptions, "largestUnit", dateLargestUnit).
|
||||||
MUST(difference_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, move(date_largest_unit))));
|
MUST(difference_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, date_largest_unit)));
|
||||||
|
|
||||||
// l. Let dateDifference be ? CalendarDateUntil(calendar, relativeTo, end, differenceOptions).
|
// l. Let dateDifference be ? CalendarDateUntil(calendar, relativeTo, end, differenceOptions).
|
||||||
auto* date_difference = TRY(calendar_date_until(global_object, calendar, &relative_to, end, *difference_options));
|
auto* date_difference = TRY(calendar_date_until(global_object, calendar, &relative_to, end, *difference_options));
|
||||||
|
|
|
@ -175,7 +175,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::until)
|
||||||
auto default_largest_unit = larger_of_two_temporal_units("second"sv, *smallest_unit);
|
auto default_largest_unit = larger_of_two_temporal_units("second"sv, *smallest_unit);
|
||||||
|
|
||||||
// 7. Let largestUnit be ? ToLargestTemporalUnit(options, « "year", "month", "week", "day" », "auto", defaultLargestUnit).
|
// 7. Let largestUnit be ? ToLargestTemporalUnit(options, « "year", "month", "week", "day" », "auto", defaultLargestUnit).
|
||||||
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, "auto"sv, move(default_largest_unit)));
|
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, "auto"sv, default_largest_unit));
|
||||||
|
|
||||||
// 8. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
// 8. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
||||||
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
||||||
|
|
|
@ -394,7 +394,7 @@ ThrowCompletionOr<TemporalDuration> difference_iso_date_time(GlobalObject& globa
|
||||||
auto date_largest_unit = larger_of_two_temporal_units("day"sv, largest_unit);
|
auto date_largest_unit = larger_of_two_temporal_units("day"sv, largest_unit);
|
||||||
|
|
||||||
// 11. Let untilOptions be ? MergeLargestUnitOption(options, dateLargestUnit).
|
// 11. Let untilOptions be ? MergeLargestUnitOption(options, dateLargestUnit).
|
||||||
auto* until_options = TRY(merge_largest_unit_option(global_object, *options, move(date_largest_unit)));
|
auto* until_options = TRY(merge_largest_unit_option(global_object, *options, date_largest_unit));
|
||||||
|
|
||||||
// 12. Let dateDifference be ? CalendarDateUntil(calendar, date1, date2, untilOptions).
|
// 12. Let dateDifference be ? CalendarDateUntil(calendar, date1, date2, untilOptions).
|
||||||
auto* date_difference = TRY(calendar_date_until(global_object, calendar, date1, date2, *until_options));
|
auto* date_difference = TRY(calendar_date_until(global_object, calendar, date1, date2, *until_options));
|
||||||
|
|
|
@ -532,7 +532,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::until)
|
||||||
auto default_largest_unit = larger_of_two_temporal_units("day"sv, *smallest_unit);
|
auto default_largest_unit = larger_of_two_temporal_units("day"sv, *smallest_unit);
|
||||||
|
|
||||||
// 8. Let largestUnit be ? ToLargestTemporalUnit(options, « », "auto", defaultLargestUnit).
|
// 8. Let largestUnit be ? ToLargestTemporalUnit(options, « », "auto", defaultLargestUnit).
|
||||||
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, {}, "auto"sv, move(default_largest_unit)));
|
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, {}, "auto"sv, default_largest_unit));
|
||||||
|
|
||||||
// 9. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
// 9. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
||||||
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
||||||
|
@ -586,7 +586,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::since)
|
||||||
auto default_largest_unit = larger_of_two_temporal_units("day"sv, *smallest_unit);
|
auto default_largest_unit = larger_of_two_temporal_units("day"sv, *smallest_unit);
|
||||||
|
|
||||||
// 8. Let largestUnit be ? ToLargestTemporalUnit(options, « », "auto", defaultLargestUnit).
|
// 8. Let largestUnit be ? ToLargestTemporalUnit(options, « », "auto", defaultLargestUnit).
|
||||||
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, {}, "auto"sv, move(default_largest_unit)));
|
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, {}, "auto"sv, default_largest_unit));
|
||||||
|
|
||||||
// 9. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
// 9. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
||||||
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
||||||
|
|
|
@ -970,7 +970,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::until)
|
||||||
auto default_largest_unit = larger_of_two_temporal_units("hour"sv, *smallest_unit);
|
auto default_largest_unit = larger_of_two_temporal_units("hour"sv, *smallest_unit);
|
||||||
|
|
||||||
// 8. Let largestUnit be ? ToLargestTemporalUnit(options, « », "auto", defaultLargestUnit).
|
// 8. Let largestUnit be ? ToLargestTemporalUnit(options, « », "auto", defaultLargestUnit).
|
||||||
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, {}, "auto"sv, move(default_largest_unit)));
|
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, {}, "auto"sv, default_largest_unit));
|
||||||
|
|
||||||
// 9. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
// 9. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
||||||
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
||||||
|
@ -1044,7 +1044,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::since)
|
||||||
auto default_largest_unit = larger_of_two_temporal_units("hour"sv, *smallest_unit);
|
auto default_largest_unit = larger_of_two_temporal_units("hour"sv, *smallest_unit);
|
||||||
|
|
||||||
// 8. Let largestUnit be ? ToLargestTemporalUnit(options, « », "auto", defaultLargestUnit).
|
// 8. Let largestUnit be ? ToLargestTemporalUnit(options, « », "auto", defaultLargestUnit).
|
||||||
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, {}, "auto"sv, move(default_largest_unit)));
|
auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, {}, "auto"sv, default_largest_unit));
|
||||||
|
|
||||||
// 9. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
// 9. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
||||||
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
TRY(validate_temporal_unit_range(global_object, *largest_unit, *smallest_unit));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue