From 4c8f7d76c4160cf283ec7c901fc55ab909b2fb0f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 27 Jan 2023 15:48:21 -0500 Subject: [PATCH] LibJS: Port Intl.RelativeTimeFormat to String --- .../Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp | 9 +++++---- .../Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.h | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp index 49e65b20e3..0b84d09756 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace JS::Intl { @@ -222,22 +223,22 @@ ThrowCompletionOr> make_parts_list(VM& vm, Stri } // 17.5.4 FormatRelativeTime ( relativeTimeFormat, value, unit ), https://tc39.es/ecma402/#sec-FormatRelativeTime -ThrowCompletionOr format_relative_time(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit) +ThrowCompletionOr format_relative_time(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit) { // 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit). auto parts = TRY(partition_relative_time_pattern(vm, relative_time_format, value, unit)); // 2. Let result be an empty String. - StringBuilder result; + ThrowableStringBuilder result(vm); // 3. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do for (auto& part : parts) { // a. Set result to the string-concatenation of result and part.[[Value]]. - result.append(move(part.value)); + MUST_OR_THROW_OOM(result.append(part.value)); } // 4. Return result. - return result.to_deprecated_string(); + return result.to_string(); } // 17.5.5 FormatRelativeTimeToParts ( relativeTimeFormat, value, unit ), https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.h index 3e8670aefd..d0840b9098 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.h @@ -7,7 +7,6 @@ #pragma once #include -#include #include #include #include @@ -86,7 +85,7 @@ struct PatternPartitionWithUnit : public PatternPartition { ThrowCompletionOr<::Locale::TimeUnit> singular_relative_time_unit(VM&, StringView unit); ThrowCompletionOr> partition_relative_time_pattern(VM&, RelativeTimeFormat&, double value, StringView unit); ThrowCompletionOr> make_parts_list(VM&, StringView pattern, StringView unit, Vector parts); -ThrowCompletionOr format_relative_time(VM&, RelativeTimeFormat&, double value, StringView unit); +ThrowCompletionOr format_relative_time(VM&, RelativeTimeFormat&, double value, StringView unit); ThrowCompletionOr format_relative_time_to_parts(VM&, RelativeTimeFormat&, double value, StringView unit); }