1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:07:35 +00:00

LibJS+LibWeb+WebContent: Stop using ThrowableStringBuilder

This commit is contained in:
Timothy Flynn 2023-09-06 08:29:01 -04:00 committed by Tim Flynn
parent 54d1f4e234
commit 573cbb5ca0
6 changed files with 43 additions and 46 deletions

View file

@ -7,13 +7,13 @@
*/
#include "WebContentConsoleClient.h"
#include <AK/StringBuilder.h>
#include <AK/TemporaryChange.h>
#include <LibJS/MarkupGenerator.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/ObjectEnvironment.h>
#include <LibJS/Runtime/Realm.h>
#include <LibJS/Runtime/ThrowableStringBuilder.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/HTML/PolicyContainers.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
@ -132,21 +132,19 @@ void WebContentConsoleClient::clear()
// 2.3. Printer(logLevel, args[, options]), https://console.spec.whatwg.org/#printer
JS::ThrowCompletionOr<JS::Value> WebContentConsoleClient::printer(JS::Console::LogLevel log_level, PrinterArguments arguments)
{
auto& vm = m_console.realm().vm();
auto styling = escape_html_entities(m_current_message_style.string_view());
m_current_message_style.clear();
if (log_level == JS::Console::LogLevel::Trace) {
auto trace = arguments.get<JS::Console::Trace>();
JS::ThrowableStringBuilder html(vm);
StringBuilder html;
if (!trace.label.is_empty())
MUST_OR_THROW_OOM(html.appendff("<span class='title' style='{}'>{}</span><br>", styling, escape_html_entities(trace.label)));
html.appendff("<span class='title' style='{}'>{}</span><br>", styling, escape_html_entities(trace.label));
MUST_OR_THROW_OOM(html.append("<span class='trace'>"sv));
html.append("<span class='trace'>"sv);
for (auto& function_name : trace.stack)
MUST_OR_THROW_OOM(html.appendff("-> {}<br>", escape_html_entities(function_name)));
MUST_OR_THROW_OOM(html.append("</span>"sv));
html.appendff("-> {}<br>", escape_html_entities(function_name));
html.append("</span>"sv);
print_html(html.string_view());
return JS::js_undefined();
@ -161,31 +159,31 @@ JS::ThrowCompletionOr<JS::Value> WebContentConsoleClient::printer(JS::Console::L
auto output = TRY(generically_format_values(arguments.get<JS::MarkedVector<JS::Value>>()));
m_console.output_debug_message(log_level, output);
JS::ThrowableStringBuilder html(vm);
StringBuilder html;
switch (log_level) {
case JS::Console::LogLevel::Debug:
MUST_OR_THROW_OOM(html.appendff("<span class=\"debug\" style=\"{}\">(d) "sv, styling));
html.appendff("<span class=\"debug\" style=\"{}\">(d) "sv, styling);
break;
case JS::Console::LogLevel::Error:
MUST_OR_THROW_OOM(html.appendff("<span class=\"error\" style=\"{}\">(e) "sv, styling));
html.appendff("<span class=\"error\" style=\"{}\">(e) "sv, styling);
break;
case JS::Console::LogLevel::Info:
MUST_OR_THROW_OOM(html.appendff("<span class=\"info\" style=\"{}\">(i) "sv, styling));
html.appendff("<span class=\"info\" style=\"{}\">(i) "sv, styling);
break;
case JS::Console::LogLevel::Log:
MUST_OR_THROW_OOM(html.appendff("<span class=\"log\" style=\"{}\"> "sv, styling));
html.appendff("<span class=\"log\" style=\"{}\"> "sv, styling);
break;
case JS::Console::LogLevel::Warn:
case JS::Console::LogLevel::CountReset:
MUST_OR_THROW_OOM(html.appendff("<span class=\"warn\" style=\"{}\">(w) "sv, styling));
html.appendff("<span class=\"warn\" style=\"{}\">(w) "sv, styling);
break;
default:
MUST_OR_THROW_OOM(html.appendff("<span style=\"{}\">"sv, styling));
html.appendff("<span style=\"{}\">"sv, styling);
break;
}
MUST_OR_THROW_OOM(html.append(escape_html_entities(output)));
MUST_OR_THROW_OOM(html.append("</span>"sv));
html.append(escape_html_entities(output));
html.append("</span>"sv);
print_html(html.string_view());
return JS::js_undefined();