mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:48:13 +00:00
LibJS: Move Interpreter::get_trace() to ConsoleClient
Having it globally on the interpreter is confusing as the last call frame is skipped, which is specific to console.trace().
This commit is contained in:
parent
9e3127785e
commit
a48080f62d
6 changed files with 14 additions and 12 deletions
|
@ -99,7 +99,7 @@ JS::Value BrowserConsoleClient::trace()
|
||||||
{
|
{
|
||||||
StringBuilder html;
|
StringBuilder html;
|
||||||
html.append(interpreter().join_arguments());
|
html.append(interpreter().join_arguments());
|
||||||
auto trace = interpreter().get_trace();
|
auto trace = get_trace();
|
||||||
for (auto& function_name : trace) {
|
for (auto& function_name : trace) {
|
||||||
if (function_name.is_empty())
|
if (function_name.is_empty())
|
||||||
function_name = "<anonymous>";
|
function_name = "<anonymous>";
|
||||||
|
|
|
@ -120,4 +120,14 @@ bool Console::counter_reset(String label)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<String> ConsoleClient::get_trace() const
|
||||||
|
{
|
||||||
|
Vector<String> trace;
|
||||||
|
auto call_stack = m_console.interpreter().call_stack();
|
||||||
|
// -2 to skip the console.trace() call frame
|
||||||
|
for (ssize_t i = call_stack.size() - 2; i >= 0; --i)
|
||||||
|
trace.append(call_stack[i].function_name);
|
||||||
|
return trace;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,8 @@ protected:
|
||||||
Interpreter& interpreter() { return m_console.interpreter(); }
|
Interpreter& interpreter() { return m_console.interpreter(); }
|
||||||
const Interpreter& interpreter() const { return m_console.interpreter(); }
|
const Interpreter& interpreter() const { return m_console.interpreter(); }
|
||||||
|
|
||||||
|
Vector<String> get_trace() const;
|
||||||
|
|
||||||
Console& m_console;
|
Console& m_console;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -282,13 +282,4 @@ String Interpreter::join_arguments() const
|
||||||
return joined_arguments.build();
|
return joined_arguments.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<String> Interpreter::get_trace() const
|
|
||||||
{
|
|
||||||
Vector<String> trace;
|
|
||||||
// -2 to skip the console.trace() call frame
|
|
||||||
for (ssize_t i = m_call_stack.size() - 2; i >= 0; --i)
|
|
||||||
trace.append(m_call_stack[i].function_name);
|
|
||||||
return trace;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,6 @@ public:
|
||||||
const Console& console() const { return m_console; }
|
const Console& console() const { return m_console; }
|
||||||
|
|
||||||
String join_arguments() const;
|
String join_arguments() const;
|
||||||
Vector<String> get_trace() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Interpreter();
|
Interpreter();
|
||||||
|
|
|
@ -501,7 +501,7 @@ public:
|
||||||
virtual JS::Value trace() override
|
virtual JS::Value trace() override
|
||||||
{
|
{
|
||||||
puts(interpreter().join_arguments().characters());
|
puts(interpreter().join_arguments().characters());
|
||||||
auto trace = interpreter().get_trace();
|
auto trace = get_trace();
|
||||||
for (auto& function_name : trace) {
|
for (auto& function_name : trace) {
|
||||||
if (function_name.is_empty())
|
if (function_name.is_empty())
|
||||||
function_name = "<anonymous>";
|
function_name = "<anonymous>";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue