diff options
author | Linus Groh <mail@linusgroh.de> | 2023-01-26 14:07:33 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-26 20:20:54 +0000 |
commit | 654911444e73dfee473aebf5b95b504b9fa752ab (patch) | |
tree | da8aaaae530b4ff3281e4f6a3a99419f2d87981d /Userland/Libraries | |
parent | 918122c1e3e9e30af8060024731f2c7bfe124022 (diff) | |
download | serenity-654911444e73dfee473aebf5b95b504b9fa752ab.zip |
LibJS: Port merge_largest_unit_option() to String
Diffstat (limited to 'Userland/Libraries')
6 files changed, 9 insertions, 9 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 5cff3878c0..ee303fcdcd 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -735,7 +735,7 @@ StringView larger_of_two_temporal_units(StringView unit1, StringView unit2) } // 13.18 MergeLargestUnitOption ( options, largestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-mergelargestunitoption -ThrowCompletionOr<Object*> merge_largest_unit_option(VM& vm, Object const& options, DeprecatedString largest_unit) +ThrowCompletionOr<Object*> merge_largest_unit_option(VM& vm, Object const& options, String largest_unit) { auto& realm = *vm.current_realm(); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index 8f418871dc..40948829ea 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -149,7 +149,7 @@ ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(VM&, Objec ThrowCompletionOr<Optional<String>> get_temporal_unit(VM&, Object const& normalized_options, PropertyKey const&, UnitGroup, TemporalUnitDefault const& default_, Vector<StringView> const& extra_values = {}); ThrowCompletionOr<Value> to_relative_temporal_object(VM&, Object const& options); StringView larger_of_two_temporal_units(StringView, StringView); -ThrowCompletionOr<Object*> merge_largest_unit_option(VM&, Object const& options, DeprecatedString largest_unit); +ThrowCompletionOr<Object*> merge_largest_unit_option(VM&, Object const& options, String largest_unit); Optional<u16> maximum_temporal_duration_rounding_increment(StringView unit); ThrowCompletionOr<void> reject_object_with_calendar_or_time_zone(VM&, Object&); DeprecatedString format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp index a72c59f637..2c90d8528e 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org> - * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -510,7 +510,7 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_date(VM& vm, DifferenceOp auto settings = TRY(get_difference_settings(vm, operation, options_value, UnitGroup::Date, {}, { "day"sv }, "day"sv)); // 5. Let untilOptions be ? MergeLargestUnitOption(settings.[[Options]], settings.[[LargestUnit]]). - auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, settings.largest_unit)); + auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(settings.largest_unit)))); // 6. Let result be ? CalendarDateUntil(temporalDate.[[Calendar]], temporalDate, other, untilOptions). auto* duration = TRY(calendar_date_until(vm, temporal_date.calendar(), &temporal_date, other, *until_options)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp index 983f986ff4..3b57fe6d3a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org> - * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -369,7 +369,7 @@ ThrowCompletionOr<DurationRecord> difference_iso_date_time(VM& vm, i32 year1, u8 auto date_largest_unit = larger_of_two_temporal_units("day"sv, largest_unit); // 11. Let untilOptions be ? MergeLargestUnitOption(options, dateLargestUnit). - auto* until_options = TRY(merge_largest_unit_option(vm, options, date_largest_unit)); + auto* until_options = TRY(merge_largest_unit_option(vm, options, TRY_OR_THROW_OOM(vm, String::from_utf8(date_largest_unit)))); // 12. Let dateDifference be ? CalendarDateUntil(calendar, date1, date2, untilOptions). auto* date_difference = TRY(calendar_date_until(vm, calendar, date1, date2, *until_options)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp index 5560ccc45d..1e41aec2dc 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -270,7 +270,7 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(VM& vm, Differ auto* this_date = TRY(calendar_date_from_fields(vm, calendar, *this_fields)); // 13. Let untilOptions be ? MergeLargestUnitOption(settings.[[Options]], settings.[[LargestUnit]]). - auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, settings.largest_unit)); + auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(settings.largest_unit)))); // 14. Let result be ? CalendarDateUntil(calendar, thisDate, otherDate, untilOptions). auto* duration = TRY(calendar_date_until(vm, calendar, this_date, other_date, *until_options)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index 0ab087778c..42f2e854ff 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp @@ -604,7 +604,7 @@ ThrowCompletionOr<Duration*> difference_temporal_zoned_date_time(VM& vm, Differe } // 7. Let untilOptions be ? MergeLargestUnitOption(settings.[[Options]], settings.[[LargestUnit]]). - auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, settings.largest_unit)); + auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(settings.largest_unit)))); // 8. Let difference be ? DifferenceZonedDateTime(zonedDateTime.[[Nanoseconds]], other.[[Nanoseconds]], zonedDateTime.[[TimeZone]], zonedDateTime.[[Calendar]], settings.[[LargestUnit]], untilOptions). auto difference = TRY(difference_zoned_date_time(vm, zoned_date_time.nanoseconds(), other->nanoseconds(), zoned_date_time.time_zone(), zoned_date_time.calendar(), settings.largest_unit, *until_options)); |