LibJS: Use Stream::format instead of manually formating and printing

This commit is contained in:
Peter Brottveit Bock 2023-04-22 22:40:10 +02:00 committed by Andreas Kling
parent 6f6d6c654d
commit fac7045a44
Notes: sideshowbarker 2024-07-17 23:00:03 +09:00

View file

@ -140,15 +140,10 @@ DeprecatedString strip_ansi(StringView format_string)
template<typename... Args>
ErrorOr<void> js_out(JS::PrintContext& print_context, CheckedFormatString<Args...> format_string, Args const&... args)
{
DeprecatedString formatted;
if (print_context.strip_ansi)
formatted = DeprecatedString::formatted(strip_ansi(format_string.view()), args...);
TRY(print_context.stream.format(strip_ansi(format_string.view()), args...));
else
formatted = DeprecatedString::formatted(format_string.view(), args...);
auto bytes = formatted.bytes();
while (!bytes.is_empty())
bytes = bytes.slice(TRY(print_context.stream.write_some(bytes)));
TRY(print_context.stream.format(format_string.view(), args...));
return {};
}