From d2c10f6bea2b088e98557ccd2ccd252840aa6096 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 26 Jan 2023 15:48:03 +0000 Subject: [PATCH] LibJS: Port temporal_instant_to_string() to String --- .../Libraries/LibJS/Runtime/Temporal/Instant.cpp | 12 ++++++------ Userland/Libraries/LibJS/Runtime/Temporal/Instant.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp index 75f008448b..8f2804aaf2 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Linus Groh + * Copyright (c) 2021-2023, Linus Groh * Copyright (c) 2021, Idan Horowitz * * SPDX-License-Identifier: BSD-2-Clause @@ -239,7 +239,7 @@ BigInt* round_temporal_instant(VM& vm, BigInt const& nanoseconds, u64 increment, } // 8.5.9 TemporalInstantToString ( instant, timeZone, precision ), https://tc39.es/proposal-temporal/#sec-temporal-temporalinstanttostring -ThrowCompletionOr temporal_instant_to_string(VM& vm, Instant& instant, Value time_zone, Variant const& precision) +ThrowCompletionOr temporal_instant_to_string(VM& vm, Instant& instant, Value time_zone, Variant const& precision) { // 1. Assert: Type(instant) is Object. // 2. Assert: instant has an [[InitializedTemporalInstant]] internal slot. @@ -262,12 +262,12 @@ ThrowCompletionOr temporal_instant_to_string(VM& vm, Instant& // 7. Let dateTimeString be ! TemporalDateTimeToString(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], undefined, precision, "never"). auto date_time_string = MUST(temporal_date_time_to_string(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), nullptr, precision, "never"sv)); - DeprecatedString time_zone_string; + String time_zone_string; // 8. If timeZone is undefined, then if (time_zone.is_undefined()) { // a. Let timeZoneString be "Z". - time_zone_string = "Z"sv; + time_zone_string = String::from_utf8_short_string("Z"sv); } // 9. Else, else { @@ -275,11 +275,11 @@ ThrowCompletionOr temporal_instant_to_string(VM& vm, Instant& auto offset_ns = TRY(get_offset_nanoseconds_for(vm, time_zone, instant)); // b. Let timeZoneString be ! FormatISOTimeZoneOffsetString(offsetNs). - time_zone_string = format_iso_time_zone_offset_string(offset_ns); + time_zone_string = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(format_iso_time_zone_offset_string(offset_ns))); } // 10. Return the string-concatenation of dateTimeString and timeZoneString. - return DeprecatedString::formatted("{}{}", date_time_string, time_zone_string); + return TRY_OR_THROW_OOM(vm, String::formatted("{}{}", date_time_string, time_zone_string)); } // 8.5.10 DifferenceTemporalInstant ( operation, instant, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalinstant diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h index 0118086808..3881f32963 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Linus Groh + * Copyright (c) 2021-2023, Linus Groh * Copyright (c) 2021, Idan Horowitz * * SPDX-License-Identifier: BSD-2-Clause @@ -50,7 +50,7 @@ i32 compare_epoch_nanoseconds(BigInt const&, BigInt const&); ThrowCompletionOr add_instant(VM&, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds); BigInt* difference_instant(VM&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode); BigInt* round_temporal_instant(VM&, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode); -ThrowCompletionOr temporal_instant_to_string(VM&, Instant&, Value time_zone, Variant const& precision); +ThrowCompletionOr temporal_instant_to_string(VM&, Instant&, Value time_zone, Variant const& precision); ThrowCompletionOr difference_temporal_instant(VM&, DifferenceOperation, Instant const&, Value other, Value options); ThrowCompletionOr add_duration_to_or_subtract_duration_from_instant(VM&, ArithmeticOperation, Instant const&, Value temporal_duration_like);