From e86eafe65eaec4212f640d6a1ef6ee42cfb4ae1e Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 2 Feb 2023 19:23:04 -0500 Subject: [PATCH] LibJS: Replace remaining uses of StringBuilder in the Intl namespace --- .../Libraries/LibJS/Runtime/Intl/DurationFormat.cpp | 7 ++++--- Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp | 10 +++++----- .../LibJS/Runtime/Intl/RelativeTimeFormat.cpp | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index f7cfc73856..12bf0406a3 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace JS::Intl { @@ -507,16 +508,16 @@ ThrowCompletionOr> partition_duration_format_pattern(VM auto parts = MUST_OR_THROW_OOM(partition_number_pattern(vm, *number_format, MathematicalValue(value))); // 6. Let concat be an empty String. - StringBuilder concat; + ThrowableStringBuilder concat(vm); // 7. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do for (auto const& part : parts) { // a. Set concat to the string-concatenation of concat and part.[[Value]]. - concat.append(part.value); + TRY(concat.append(part.value)); } // 8. Append the new Record { [[Type]]: unit, [[Value]]: concat } to the end of result. - result.append({ unit, TRY_OR_THROW_OOM(vm, concat.to_string()) }); + result.append({ unit, MUST_OR_THROW_OOM(concat.to_string()) }); } } } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index c33914d9bf..e099a93ff4 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -1,14 +1,14 @@ /* - * Copyright (c) 2021-2022, Tim Flynn + * Copyright (c) 2021-2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include #include +#include namespace JS::Intl { @@ -188,16 +188,16 @@ ThrowCompletionOr format_list(VM& vm, ListFormat const& list_format, Vec auto parts = MUST_OR_THROW_OOM(create_parts_from_list(vm, list_format, list)); // 2. Let result be an empty String. - StringBuilder result; + ThrowableStringBuilder result(vm); // 3. For each Record { [[Type]], [[Value]] } part in parts, do for (auto& part : parts) { // a. Set result to the string-concatenation of result and part.[[Value]]. - result.append(part.value); + TRY(result.append(part.value)); } // 4. Return result. - return TRY_OR_THROW_OOM(vm, result.to_string()); + return result.to_string(); } // 13.5.4 FormatListToParts ( listFormat, list ), https://tc39.es/ecma402/#sec-formatlisttoparts diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp index ccf636c947..b9d4ee22e0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include