mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibJS+WebContent+js: Bring console.trace() to spec
The spec very kindly defines `Printer` as accepting "Implementation-specific representations of printable things such as a stack trace or group." for the `args`. We make use of that here by passing the `Trace` itself to `Printer`, instead of having to produce a representation of the stack trace in advance and then pass that to `Printer`. That both avoids the hassle of tracking whether the data has been html-encoded or not, and means clients don't have to implement the whole `trace()` algorithm, but only the code needed to output the trace.
This commit is contained in:
parent
ce694490f3
commit
ff5e07d718
5 changed files with 68 additions and 50 deletions
|
@ -1128,21 +1128,22 @@ public:
|
|||
fflush(stdout);
|
||||
}
|
||||
|
||||
virtual JS::Value trace() override
|
||||
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, Variant<Vector<JS::Value>, JS::Console::Trace> arguments) override
|
||||
{
|
||||
js_outln("{}", vm().join_arguments());
|
||||
auto trace = get_trace();
|
||||
for (auto& function_name : trace) {
|
||||
if (function_name.is_empty())
|
||||
function_name = "<anonymous>";
|
||||
js_outln(" -> {}", function_name);
|
||||
}
|
||||
return JS::js_undefined();
|
||||
}
|
||||
if (log_level == JS::Console::LogLevel::Trace) {
|
||||
auto trace = arguments.get<JS::Console::Trace>();
|
||||
StringBuilder builder;
|
||||
if (!trace.label.is_empty())
|
||||
builder.appendff("\033[36;1m{}\033[0m\n", trace.label);
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, Vector<JS::Value>& arguments) override
|
||||
{
|
||||
auto output = String::join(" ", arguments);
|
||||
for (auto& function_name : trace.stack)
|
||||
builder.appendff("-> {}\n", function_name);
|
||||
|
||||
js_outln("{}", builder.string_view());
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
auto output = String::join(" ", arguments.get<Vector<JS::Value>>());
|
||||
m_console.output_debug_message(log_level, output);
|
||||
|
||||
switch (log_level) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue