diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index be8d5b8f6d..30d3d4a40e 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -536,8 +537,8 @@ static ThrowCompletionOr pad_string(VM& vm, Utf16String string, PadPlacem auto filler = filler_builder.build(); auto formatted = placement == PadPlacement::Start - ? DeprecatedString::formatted("{}{}", filler, string.view()) - : DeprecatedString::formatted("{}{}", string.view(), filler); + ? TRY(deprecated_format(vm, "{}{}", filler, string.view())) + : TRY(deprecated_format(vm, "{}{}", string.view(), filler)); return PrimitiveString::create(vm, move(formatted)); } diff --git a/Userland/Libraries/LibJS/Runtime/ThrowableFormat.h b/Userland/Libraries/LibJS/Runtime/ThrowableFormat.h new file mode 100644 index 0000000000..ec4d21f6de --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/ThrowableFormat.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace JS { + +template +ThrowCompletionOr deprecated_format(VM& vm, CheckedFormatString&& fmtstr, Args const&... args) +{ + StringBuilder builder; + AK::VariadicFormatParams parameters { args... }; + + TRY_OR_THROW_OOM(vm, vformat(builder, fmtstr.view(), parameters)); + return builder.to_deprecated_string(); +} + +}