diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-12-10 12:26:25 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-27 21:44:07 +0100 |
commit | 260836135a17596e5b481edcf81a79824b44ca51 (patch) | |
tree | 244840a9a4d7ccd7ae0dfaa135fa5ea19b711e30 /Userland/Utilities | |
parent | fd7163b1255526e49a33f6bcb92c0243a5e7cdbd (diff) | |
download | serenity-260836135a17596e5b481edcf81a79824b44ca51.zip |
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.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/js.cpp | 58 |
1 files changed, 28 insertions, 30 deletions
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<JS::Value> printer(JS::Console::LogLevel log_level, Vector<JS::Value>& 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<int> serenity_main(Main::Arguments arguments) |