summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Ladybird/ConsoleClient.cpp2
-rw-r--r--Userland/Libraries/LibJS/Console.cpp19
-rw-r--r--Userland/Libraries/LibJS/Console.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerDebugConsoleClient.cpp2
-rw-r--r--Userland/Services/WebContent/WebContentConsoleClient.cpp2
-rw-r--r--Userland/Utilities/js.cpp2
6 files changed, 25 insertions, 4 deletions
diff --git a/Ladybird/ConsoleClient.cpp b/Ladybird/ConsoleClient.cpp
index e7cb384643..399ca986f0 100644
--- a/Ladybird/ConsoleClient.cpp
+++ b/Ladybird/ConsoleClient.cpp
@@ -168,7 +168,7 @@ JS::ThrowCompletionOr<JS::Value> ConsoleClient::printer(JS::Console::LogLevel lo
return JS::js_undefined();
}
- auto output = DeprecatedString::join(' ', arguments.get<JS::MarkedVector<JS::Value>>());
+ auto output = TRY(generically_format_values(arguments.get<JS::MarkedVector<JS::Value>>()));
m_console.output_debug_message(log_level, output);
StringBuilder html;
diff --git a/Userland/Libraries/LibJS/Console.cpp b/Userland/Libraries/LibJS/Console.cpp
index 37f1e80e74..99da170119 100644
--- a/Userland/Libraries/LibJS/Console.cpp
+++ b/Userland/Libraries/LibJS/Console.cpp
@@ -6,8 +6,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/MemoryStream.h>
#include <LibJS/Console.h>
+#include <LibJS/Print.h>
#include <LibJS/Runtime/AbstractOperations.h>
+#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/StringConstructor.h>
#include <LibJS/Runtime/Temporal/Duration.h>
#include <LibJS/Runtime/ThrowableStringBuilder.h>
@@ -669,4 +672,20 @@ ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Val
return formatter(result);
}
+ThrowCompletionOr<String> ConsoleClient::generically_format_values(MarkedVector<Value> const& values)
+{
+ AllocatingMemoryStream stream;
+ auto& vm = m_console.realm().vm();
+ PrintContext ctx { vm, stream, true };
+ bool first = true;
+ for (auto const& value : values) {
+ if (!first)
+ TRY_OR_THROW_OOM(vm, stream.write(" "sv.bytes()));
+ TRY_OR_THROW_OOM(vm, JS::print(value, ctx));
+ first = false;
+ }
+ // FIXME: Is it possible we could end up serializing objects to invalid UTF-8?
+ return TRY_OR_THROW_OOM(vm, String::from_stream(stream, stream.used_buffer_size()));
+}
+
}
diff --git a/Userland/Libraries/LibJS/Console.h b/Userland/Libraries/LibJS/Console.h
index 34f45a71b5..6394c14e50 100644
--- a/Userland/Libraries/LibJS/Console.h
+++ b/Userland/Libraries/LibJS/Console.h
@@ -116,6 +116,8 @@ public:
virtual void clear() = 0;
virtual void end_group() = 0;
+ ThrowCompletionOr<String> generically_format_values(MarkedVector<Value> const&);
+
protected:
virtual ~ConsoleClient() = default;
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerDebugConsoleClient.cpp b/Userland/Libraries/LibWeb/HTML/WorkerDebugConsoleClient.cpp
index f2a490cc63..659d2cd6f0 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerDebugConsoleClient.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WorkerDebugConsoleClient.cpp
@@ -58,7 +58,7 @@ JS::ThrowCompletionOr<JS::Value> WorkerDebugConsoleClient::printer(JS::Console::
return JS::js_undefined();
}
- auto output = TRY_OR_THROW_OOM(vm, String::join(' ', arguments.get<JS::MarkedVector<JS::Value>>()));
+ auto output = TRY(generically_format_values(arguments.get<JS::MarkedVector<JS::Value>>()));
m_console.output_debug_message(log_level, output);
switch (log_level) {
diff --git a/Userland/Services/WebContent/WebContentConsoleClient.cpp b/Userland/Services/WebContent/WebContentConsoleClient.cpp
index 208879268a..a41272b76e 100644
--- a/Userland/Services/WebContent/WebContentConsoleClient.cpp
+++ b/Userland/Services/WebContent/WebContentConsoleClient.cpp
@@ -158,7 +158,7 @@ JS::ThrowCompletionOr<JS::Value> WebContentConsoleClient::printer(JS::Console::L
return JS::js_undefined();
}
- auto output = TRY_OR_THROW_OOM(vm, String::join(' ', arguments.get<JS::MarkedVector<JS::Value>>()));
+ auto output = TRY(generically_format_values(arguments.get<JS::MarkedVector<JS::Value>>()));
m_console.output_debug_message(log_level, output);
JS::ThrowableStringBuilder html(vm);
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index 162741661f..7a08f4beec 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -558,7 +558,7 @@ public:
return JS::js_undefined();
}
- auto output = TRY_OR_THROW_OOM(*g_vm, String::join(' ', arguments.get<JS::MarkedVector<JS::Value>>()));
+ auto output = TRY(generically_format_values(arguments.get<JS::MarkedVector<JS::Value>>()));
#ifdef AK_OS_SERENITY
m_console.output_debug_message(log_level, output);
#endif