From 260836135a17596e5b481edcf81a79824b44ca51 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 10 Dec 2021 12:26:25 +0000 Subject: LibJS+WebContent+js: Reimplement console.log() and friends to spec This implements the Logger and Printer abstract operations defined in the console spec, and stubs out the Formatter AO. These are then used for the "output a categorized log message" functions. --- Userland/Utilities/js.cpp | 58 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 30 deletions(-) (limited to 'Userland/Utilities') diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 85a24ae7e4..335ea81fe6 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -1122,36 +1122,6 @@ public: { } - virtual JS::Value log() override - { - js_outln("{}", vm().join_arguments()); - return JS::js_undefined(); - } - - virtual JS::Value info() override - { - js_outln("(i) {}", vm().join_arguments()); - return JS::js_undefined(); - } - - virtual JS::Value debug() override - { - js_outln("\033[36;1m{}\033[0m", vm().join_arguments()); - return JS::js_undefined(); - } - - virtual JS::Value warn() override - { - js_outln("\033[33;1m{}\033[0m", vm().join_arguments()); - return JS::js_undefined(); - } - - virtual JS::Value error() override - { - js_outln("\033[31;1m{}\033[0m", vm().join_arguments()); - return JS::js_undefined(); - } - virtual JS::Value clear() override { js_out("\033[3J\033[H\033[2J"); @@ -1202,6 +1172,34 @@ public: } return JS::js_undefined(); } + + virtual JS::ThrowCompletionOr printer(JS::Console::LogLevel log_level, Vector& arguments) override + { + auto output = String::join(" ", arguments); + m_console.output_debug_message(log_level, output); + + switch (log_level) { + case JS::Console::LogLevel::Debug: + js_outln("\033[36;1m{}\033[0m", output); + break; + case JS::Console::LogLevel::Error: + js_outln("\033[31;1m{}\033[0m", output); + break; + case JS::Console::LogLevel::Info: + js_outln("(i) {}", output); + break; + case JS::Console::LogLevel::Log: + js_outln("{}", output); + break; + case JS::Console::LogLevel::Warn: + js_outln("\033[33;1m{}\033[0m", output); + break; + default: + js_outln("{}", output); + break; + } + return JS::js_undefined(); + } }; ErrorOr serenity_main(Main::Arguments arguments) -- cgit v1.2.3