mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
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.
This commit is contained in:
parent
fd7163b125
commit
260836135a
5 changed files with 211 additions and 125 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue