| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Brandon Scott <xeon.productions@gmail.com> | 
					
						
							|  |  |  |  * Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com> | 
					
						
							| 
									
										
										
										
											2022-11-19 16:12:19 +00:00
										 |  |  |  * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							| 
									
										
										
										
											2024-08-09 23:24:26 +02:00
										 |  |  |  * Copyright (c) 2024, Gasim Gasimzada <gasim@gasimzada.net> | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-09 23:24:26 +02:00
										 |  |  | #include <AK/MemoryStream.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  | #include <AK/StringBuilder.h>
 | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | #include <LibJS/MarkupGenerator.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-09 23:24:26 +02:00
										 |  |  | #include <LibJS/Print.h>
 | 
					
						
							| 
									
										
										
										
											2024-10-31 08:03:32 -04:00
										 |  |  | #include <LibJS/Runtime/GlobalEnvironment.h>
 | 
					
						
							|  |  |  | #include <LibJS/Runtime/ObjectEnvironment.h>
 | 
					
						
							| 
									
										
										
										
											2023-02-10 11:40:52 -05:00
										 |  |  | #include <LibJS/Runtime/Realm.h>
 | 
					
						
							|  |  |  | #include <LibJS/Runtime/VM.h>
 | 
					
						
							| 
									
										
										
										
											2024-10-31 08:03:32 -04:00
										 |  |  | #include <LibWeb/HTML/Scripting/ClassicScript.h>
 | 
					
						
							|  |  |  | #include <LibWeb/HTML/Scripting/Environments.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | #include <LibWeb/HTML/Window.h>
 | 
					
						
							| 
									
										
										
										
											2022-12-09 18:48:25 +01:00
										 |  |  | #include <WebContent/ConsoleGlobalEnvironmentExtensions.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | #include <WebContent/PageClient.h>
 | 
					
						
							|  |  |  | #include <WebContent/WebContentConsoleClient.h>
 | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace WebContent { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-20 21:19:51 +02:00
										 |  |  | JS_DEFINE_ALLOCATOR(WebContentConsoleClient); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, JS::Realm& realm, PageClient& client) | 
					
						
							| 
									
										
										
										
											2021-09-03 10:16:36 +01:00
										 |  |  |     : ConsoleClient(console) | 
					
						
							|  |  |  |     , m_client(client) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-12-09 18:48:25 +01:00
										 |  |  |     auto& window = verify_cast<Web::HTML::Window>(realm.global_object()); | 
					
						
							| 
									
										
										
										
											2023-08-13 13:05:26 +02:00
										 |  |  |     m_console_global_environment_extensions = realm.heap().allocate<ConsoleGlobalEnvironmentExtensions>(realm, realm, window); | 
					
						
							| 
									
										
										
										
											2021-09-03 10:16:36 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-20 21:19:51 +02:00
										 |  |  | WebContentConsoleClient::~WebContentConsoleClient() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WebContentConsoleClient::visit_edges(JS::Cell::Visitor& visitor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Base::visit_edges(visitor); | 
					
						
							|  |  |  |     visitor.visit(m_client); | 
					
						
							|  |  |  |     visitor.visit(m_console_global_environment_extensions); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | void WebContentConsoleClient::handle_input(ByteString const& js_source) | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-12-09 18:48:25 +01:00
										 |  |  |     if (!m_console_global_environment_extensions) | 
					
						
							| 
									
										
										
										
											2022-09-01 20:08:38 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-31 08:03:32 -04:00
										 |  |  |     auto& settings = Web::HTML::relevant_settings_object(*m_console_global_environment_extensions); | 
					
						
							|  |  |  |     auto script = Web::HTML::ClassicScript::create("(console)", js_source, settings.realm(), settings.api_base_url()); | 
					
						
							| 
									
										
										
										
											2021-10-03 13:58:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-31 08:03:32 -04:00
										 |  |  |     auto with_scope = JS::new_object_environment(*m_console_global_environment_extensions, true, &settings.realm().global_environment()); | 
					
						
							| 
									
										
										
										
											2021-10-03 13:58:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-31 08:03:32 -04:00
										 |  |  |     // FIXME: Add parse error printouts back once ClassicScript can report parse errors.
 | 
					
						
							|  |  |  |     auto result = script->run(Web::HTML::ClassicScript::RethrowErrors::No, with_scope); | 
					
						
							| 
									
										
										
										
											2021-10-14 16:12:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-31 08:03:32 -04:00
										 |  |  |     if (result.value().has_value()) { | 
					
						
							|  |  |  |         m_console_global_environment_extensions->set_most_recent_result(result.value().value()); | 
					
						
							|  |  |  |         print_html(JS::MarkupGenerator::html_from_value(*result.value()).release_value_but_fixme_should_propagate_errors().to_byte_string()); | 
					
						
							| 
									
										
										
										
											2022-10-03 14:41:41 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 19:38:32 +04:00
										 |  |  | void WebContentConsoleClient::report_exception(JS::Error const& exception, bool in_promise) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |     print_html(JS::MarkupGenerator::html_from_error(exception, in_promise).release_value_but_fixme_should_propagate_errors().to_byte_string()); | 
					
						
							| 
									
										
										
										
											2022-10-08 19:38:32 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | void WebContentConsoleClient::print_html(ByteString const& line) | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |     m_message_log.append({ .type = ConsoleOutput::Type::HTML, .data = line }); | 
					
						
							| 
									
										
										
										
											2024-04-05 13:47:57 -07:00
										 |  |  |     m_client->did_output_js_console_message(m_message_log.size() - 1); | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WebContentConsoleClient::clear_output() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |     m_message_log.append({ .type = ConsoleOutput::Type::Clear, .data = "" }); | 
					
						
							| 
									
										
										
										
											2024-04-05 13:47:57 -07:00
										 |  |  |     m_client->did_output_js_console_message(m_message_log.size() - 1); | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | void WebContentConsoleClient::begin_group(ByteString const& label, bool start_expanded) | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     m_message_log.append({ .type = start_expanded ? ConsoleOutput::Type::BeginGroup : ConsoleOutput::Type::BeginGroupCollapsed, .data = label }); | 
					
						
							| 
									
										
										
										
											2024-04-05 13:47:57 -07:00
										 |  |  |     m_client->did_output_js_console_message(m_message_log.size() - 1); | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WebContentConsoleClient::end_group() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_message_log.append({ .type = ConsoleOutput::Type::EndGroup, .data = "" }); | 
					
						
							| 
									
										
										
										
											2024-04-05 13:47:57 -07:00
										 |  |  |     m_client->did_output_js_console_message(m_message_log.size() - 1); | 
					
						
							| 
									
										
										
										
											2021-09-04 11:45:36 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WebContentConsoleClient::send_messages(i32 start_index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // FIXME: Cap the number of messages we send at once?
 | 
					
						
							|  |  |  |     auto messages_to_send = m_message_log.size() - start_index; | 
					
						
							|  |  |  |     if (messages_to_send < 1) { | 
					
						
							|  |  |  |         // When the console is first created, it requests any messages that happened before
 | 
					
						
							|  |  |  |         // then, by requesting with start_index=0. If we don't have any messages at all, that
 | 
					
						
							|  |  |  |         // is still a valid request, and we can just ignore it.
 | 
					
						
							|  |  |  |         if (start_index != 0) | 
					
						
							| 
									
										
										
										
											2024-04-05 13:47:57 -07:00
										 |  |  |             m_client->console_peer_did_misbehave("Requested non-existent console message index."); | 
					
						
							| 
									
										
										
										
											2021-09-04 11:45:36 +01:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // FIXME: Replace with a single Vector of message structs
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |     Vector<ByteString> message_types; | 
					
						
							|  |  |  |     Vector<ByteString> messages; | 
					
						
							| 
									
										
										
										
											2021-09-04 11:45:36 +01:00
										 |  |  |     message_types.ensure_capacity(messages_to_send); | 
					
						
							|  |  |  |     messages.ensure_capacity(messages_to_send); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (size_t i = start_index; i < m_message_log.size(); i++) { | 
					
						
							|  |  |  |         auto& message = m_message_log[i]; | 
					
						
							|  |  |  |         switch (message.type) { | 
					
						
							|  |  |  |         case ConsoleOutput::Type::HTML: | 
					
						
							| 
									
										
										
										
											2022-07-11 17:32:29 +00:00
										 |  |  |             message_types.append("html"sv); | 
					
						
							| 
									
										
										
										
											2021-09-04 11:45:36 +01:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case ConsoleOutput::Type::Clear: | 
					
						
							| 
									
										
										
										
											2022-07-11 17:32:29 +00:00
										 |  |  |             message_types.append("clear"sv); | 
					
						
							| 
									
										
										
										
											2021-09-04 11:45:36 +01:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |         case ConsoleOutput::Type::BeginGroup: | 
					
						
							| 
									
										
										
										
											2022-07-11 17:32:29 +00:00
										 |  |  |             message_types.append("group"sv); | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case ConsoleOutput::Type::BeginGroupCollapsed: | 
					
						
							| 
									
										
										
										
											2022-07-11 17:32:29 +00:00
										 |  |  |             message_types.append("groupCollapsed"sv); | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case ConsoleOutput::Type::EndGroup: | 
					
						
							| 
									
										
										
										
											2022-07-11 17:32:29 +00:00
										 |  |  |             message_types.append("groupEnd"sv); | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2021-09-04 11:45:36 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |         messages.append(message.data); | 
					
						
							| 
									
										
										
										
											2021-09-04 11:45:36 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-05 13:47:57 -07:00
										 |  |  |     m_client->did_get_js_console_messages(start_index, message_types, messages); | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-08 19:24:17 +00:00
										 |  |  | void WebContentConsoleClient::clear() | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | { | 
					
						
							|  |  |  |     clear_output(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-10 13:48:38 +00:00
										 |  |  | // 2.3. Printer(logLevel, args[, options]), https://console.spec.whatwg.org/#printer
 | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  | JS::ThrowCompletionOr<JS::Value> WebContentConsoleClient::printer(JS::Console::LogLevel log_level, PrinterArguments arguments) | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-09-20 18:23:04 +01:00
										 |  |  |     auto styling = escape_html_entities(m_current_message_style.string_view()); | 
					
						
							|  |  |  |     m_current_message_style.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-09 23:24:26 +02:00
										 |  |  |     if (log_level == JS::Console::LogLevel::Table) { | 
					
						
							|  |  |  |         auto& vm = m_console->realm().vm(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         auto table_args = arguments.get<JS::MarkedVector<JS::Value>>(); | 
					
						
							|  |  |  |         auto& table = table_args.at(0).as_object(); | 
					
						
							|  |  |  |         auto& columns = TRY(table.get(JS::PropertyKey("columns"))).as_array().indexed_properties(); | 
					
						
							|  |  |  |         auto& rows = TRY(table.get(JS::PropertyKey("rows"))).as_array().indexed_properties(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         StringBuilder html; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         html.appendff("<div class=\"console-log-table\">"); | 
					
						
							|  |  |  |         html.appendff("<table>"); | 
					
						
							|  |  |  |         html.appendff("<thead>"); | 
					
						
							|  |  |  |         html.appendff("<tr>"); | 
					
						
							|  |  |  |         for (auto const& col : columns) { | 
					
						
							|  |  |  |             auto index = col.index(); | 
					
						
							|  |  |  |             auto value = columns.storage()->get(index).value().value; | 
					
						
							|  |  |  |             html.appendff("<td>{}</td>", value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         html.appendff("</tr>"); | 
					
						
							|  |  |  |         html.appendff("</thead>"); | 
					
						
							|  |  |  |         html.appendff("<tbody>"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (auto const& row : rows) { | 
					
						
							|  |  |  |             auto row_index = row.index(); | 
					
						
							|  |  |  |             auto& row_obj = rows.storage()->get(row_index).value().value.as_object(); | 
					
						
							|  |  |  |             html.appendff("<tr>"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (auto const& col : columns) { | 
					
						
							|  |  |  |                 auto col_index = col.index(); | 
					
						
							|  |  |  |                 auto col_name = columns.storage()->get(col_index).value().value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 auto property_key = TRY(JS::PropertyKey::from_value(vm, col_name)); | 
					
						
							|  |  |  |                 auto cell = TRY(row_obj.get(property_key)); | 
					
						
							|  |  |  |                 html.appendff("<td>"); | 
					
						
							|  |  |  |                 if (TRY(cell.is_array(vm))) { | 
					
						
							|  |  |  |                     AllocatingMemoryStream stream; | 
					
						
							|  |  |  |                     JS::PrintContext ctx { vm, stream, true }; | 
					
						
							|  |  |  |                     TRY_OR_THROW_OOM(vm, stream.write_until_depleted(" "sv.bytes())); | 
					
						
							|  |  |  |                     TRY_OR_THROW_OOM(vm, JS::print(cell, ctx)); | 
					
						
							|  |  |  |                     auto output = TRY_OR_THROW_OOM(vm, String::from_stream(stream, stream.used_buffer_size())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     auto size = cell.as_array().indexed_properties().array_like_size(); | 
					
						
							|  |  |  |                     html.appendff("<details><summary>Array({})</summary>{}</details>", size, output); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 } else if (cell.is_object()) { | 
					
						
							|  |  |  |                     AllocatingMemoryStream stream; | 
					
						
							|  |  |  |                     JS::PrintContext ctx { vm, stream, true }; | 
					
						
							|  |  |  |                     TRY_OR_THROW_OOM(vm, stream.write_until_depleted(" "sv.bytes())); | 
					
						
							|  |  |  |                     TRY_OR_THROW_OOM(vm, JS::print(cell, ctx)); | 
					
						
							|  |  |  |                     auto output = TRY_OR_THROW_OOM(vm, String::from_stream(stream, stream.used_buffer_size())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     html.appendff("<details><summary>Object({{...}})</summary>{}</details>", output); | 
					
						
							|  |  |  |                 } else if (cell.is_function() || cell.is_constructor()) { | 
					
						
							|  |  |  |                     html.appendff("Æ’"); | 
					
						
							|  |  |  |                 } else if (!cell.is_undefined()) { | 
					
						
							|  |  |  |                     html.appendff("{}", cell); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 html.appendff("</td>"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             html.appendff("</tr>"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         html.appendff("</tbody>"); | 
					
						
							|  |  |  |         html.appendff("</table>"); | 
					
						
							|  |  |  |         html.appendff("</div>"); | 
					
						
							|  |  |  |         print_html(html.string_view()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         auto output = TRY(generically_format_values(table_args)); | 
					
						
							|  |  |  |         m_console->output_debug_message(log_level, output); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return JS::js_undefined(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-10 13:48:38 +00:00
										 |  |  |     if (log_level == JS::Console::LogLevel::Trace) { | 
					
						
							|  |  |  |         auto trace = arguments.get<JS::Console::Trace>(); | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |         StringBuilder html; | 
					
						
							| 
									
										
										
										
											2021-12-10 13:48:38 +00:00
										 |  |  |         if (!trace.label.is_empty()) | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |             html.appendff("<span class='title' style='{}'>{}</span><br>", styling, escape_html_entities(trace.label)); | 
					
						
							| 
									
										
										
										
											2021-12-10 13:48:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |         html.append("<span class='trace'>"sv); | 
					
						
							| 
									
										
										
										
											2021-12-10 13:48:38 +00:00
										 |  |  |         for (auto& function_name : trace.stack) | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |             html.appendff("-> {}<br>", escape_html_entities(function_name)); | 
					
						
							|  |  |  |         html.append("</span>"sv); | 
					
						
							| 
									
										
										
										
											2021-12-10 13:48:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         print_html(html.string_view()); | 
					
						
							|  |  |  |         return JS::js_undefined(); | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |     if (log_level == JS::Console::LogLevel::Group || log_level == JS::Console::LogLevel::GroupCollapsed) { | 
					
						
							|  |  |  |         auto group = arguments.get<JS::Console::Group>(); | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         begin_group(ByteString::formatted("<span style='{}'>{}</span>", styling, escape_html_entities(group.label)), log_level == JS::Console::LogLevel::Group); | 
					
						
							| 
									
										
										
										
											2021-12-22 12:32:15 +00:00
										 |  |  |         return JS::js_undefined(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-08 10:42:26 -07:00
										 |  |  |     auto output = TRY(generically_format_values(arguments.get<JS::MarkedVector<JS::Value>>())); | 
					
						
							| 
									
										
										
										
											2024-04-20 21:19:51 +02:00
										 |  |  |     m_console->output_debug_message(log_level, output); | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |     StringBuilder html; | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |     switch (log_level) { | 
					
						
							|  |  |  |     case JS::Console::LogLevel::Debug: | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |         html.appendff("<span class=\"debug\" style=\"{}\">(d) "sv, styling); | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case JS::Console::LogLevel::Error: | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |         html.appendff("<span class=\"error\" style=\"{}\">(e) "sv, styling); | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case JS::Console::LogLevel::Info: | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |         html.appendff("<span class=\"info\" style=\"{}\">(i) "sv, styling); | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case JS::Console::LogLevel::Log: | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |         html.appendff("<span class=\"log\" style=\"{}\"> "sv, styling); | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case JS::Console::LogLevel::Warn: | 
					
						
							| 
									
										
										
										
											2021-12-08 19:12:06 +00:00
										 |  |  |     case JS::Console::LogLevel::CountReset: | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |         html.appendff("<span class=\"warn\" style=\"{}\">(w) "sv, styling); | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |         html.appendff("<span style=\"{}\">"sv, styling); | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-06 08:29:01 -04:00
										 |  |  |     html.append(escape_html_entities(output)); | 
					
						
							|  |  |  |     html.append("</span>"sv); | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |     print_html(html.string_view()); | 
					
						
							| 
									
										
										
										
											2023-02-10 11:40:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-10 12:26:25 +00:00
										 |  |  |     return JS::js_undefined(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | } |