LibJS+LibWeb: Make Console, ConsoleClient & subclasses GC-allocated

These objects had confusing ownership semantics. Let's just throw them
all on the GC heap and stop worrying about it.
This commit is contained in:
Andreas Kling 2024-04-20 21:19:51 +02:00
commit 4db1712f90
Notes: sideshowbarker 2024-07-17 06:20:50 +09:00
13 changed files with 95 additions and 34 deletions

View file

@ -18,11 +18,23 @@
namespace JS {
JS_DEFINE_ALLOCATOR(Console);
JS_DEFINE_ALLOCATOR(ConsoleClient);
Console::Console(Realm& realm)
: m_realm(realm)
{
}
Console::~Console() = default;
void Console::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_realm);
visitor.visit(m_client);
}
// 1.1.1. assert(condition, ...data), https://console.spec.whatwg.org/#assert
ThrowCompletionOr<Value> Console::assert_()
{
@ -543,10 +555,23 @@ ThrowCompletionOr<String> Console::format_time_since(Core::ElapsedTimer timer)
return MUST(builder.to_string());
}
ConsoleClient::ConsoleClient(Console& console)
: m_console(console)
{
}
ConsoleClient::~ConsoleClient() = default;
void ConsoleClient::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_console);
}
// 2.1. Logger(logLevel, args), https://console.spec.whatwg.org/#logger
ThrowCompletionOr<Value> ConsoleClient::logger(Console::LogLevel log_level, MarkedVector<Value> const& args)
{
auto& vm = m_console.realm().vm();
auto& vm = m_console->realm().vm();
// 1. If args is empty, return.
if (args.is_empty())
@ -578,7 +603,7 @@ ThrowCompletionOr<Value> ConsoleClient::logger(Console::LogLevel log_level, Mark
// 2.2. Formatter(args), https://console.spec.whatwg.org/#formatter
ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Value> const& args)
{
auto& realm = m_console.realm();
auto& realm = m_console->realm();
auto& vm = realm.vm();
// 1. If argss size is 1, return args.
@ -691,7 +716,7 @@ ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Val
ThrowCompletionOr<String> ConsoleClient::generically_format_values(MarkedVector<Value> const& values)
{
AllocatingMemoryStream stream;
auto& vm = m_console.realm().vm();
auto& vm = m_console->realm().vm();
PrintContext ctx { vm, stream, true };
bool first = true;
for (auto const& value : values) {