1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:47:35 +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:
Sam Atkins 2021-12-10 13:48:38 +00:00 committed by Andreas Kling
parent ce694490f3
commit ff5e07d718
5 changed files with 68 additions and 50 deletions

View file

@ -43,6 +43,11 @@ public:
Warn,
};
struct Trace {
String label;
Vector<String> stack;
};
explicit Console(GlobalObject&);
void set_client(ConsoleClient& client) { m_client = &client; }
@ -62,7 +67,7 @@ public:
ThrowCompletionOr<Value> log();
ThrowCompletionOr<Value> warn();
Value clear();
Value trace();
ThrowCompletionOr<Value> trace();
ThrowCompletionOr<Value> count();
ThrowCompletionOr<Value> count_reset();
ThrowCompletionOr<Value> assert_();
@ -85,10 +90,9 @@ public:
ThrowCompletionOr<Value> logger(Console::LogLevel log_level, Vector<Value>& args);
ThrowCompletionOr<Vector<Value>> formatter(Vector<Value>& args);
virtual ThrowCompletionOr<Value> printer(Console::LogLevel log_level, Vector<Value>&) = 0;
virtual ThrowCompletionOr<Value> printer(Console::LogLevel log_level, Variant<Vector<Value>, Console::Trace>) = 0;
virtual void clear() = 0;
virtual Value trace() = 0;
protected:
virtual ~ConsoleClient() = default;
@ -98,8 +102,6 @@ protected:
GlobalObject& global_object() { return m_console.global_object(); }
const GlobalObject& global_object() const { return m_console.global_object(); }
Vector<String> get_trace() const;
Console& m_console;
};