diff --git a/Applications/Browser/BrowserConsoleClient.cpp b/Applications/Browser/BrowserConsoleClient.cpp index a444814df2..3c121c48da 100644 --- a/Applications/Browser/BrowserConsoleClient.cpp +++ b/Applications/Browser/BrowserConsoleClient.cpp @@ -99,7 +99,7 @@ JS::Value BrowserConsoleClient::trace() { StringBuilder html; html.append(interpreter().join_arguments()); - auto trace = interpreter().get_trace(); + auto trace = get_trace(); for (auto& function_name : trace) { if (function_name.is_empty()) function_name = "<anonymous>"; diff --git a/Libraries/LibJS/Console.cpp b/Libraries/LibJS/Console.cpp index 3926840c3c..5033ed25c9 100644 --- a/Libraries/LibJS/Console.cpp +++ b/Libraries/LibJS/Console.cpp @@ -120,4 +120,14 @@ bool Console::counter_reset(String label) return true; } +Vector ConsoleClient::get_trace() const +{ + Vector 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; +} + } diff --git a/Libraries/LibJS/Console.h b/Libraries/LibJS/Console.h index beb59031ce..7465f1c32d 100644 --- a/Libraries/LibJS/Console.h +++ b/Libraries/LibJS/Console.h @@ -94,6 +94,8 @@ protected: Interpreter& interpreter() { return m_console.interpreter(); } const Interpreter& interpreter() const { return m_console.interpreter(); } + Vector get_trace() const; + Console& m_console; }; diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp index d7b3a51fa5..c51e586488 100644 --- a/Libraries/LibJS/Interpreter.cpp +++ b/Libraries/LibJS/Interpreter.cpp @@ -282,13 +282,4 @@ String Interpreter::join_arguments() const return joined_arguments.build(); } -Vector Interpreter::get_trace() const -{ - Vector 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; -} - } diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h index 659d7e67f8..0e877f5049 100644 --- a/Libraries/LibJS/Interpreter.h +++ b/Libraries/LibJS/Interpreter.h @@ -181,7 +181,6 @@ public: const Console& console() const { return m_console; } String join_arguments() const; - Vector get_trace() const; private: Interpreter(); diff --git a/Userland/js.cpp b/Userland/js.cpp index f244bd2e65..cfc30d217f 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -501,7 +501,7 @@ public: virtual JS::Value trace() override { puts(interpreter().join_arguments().characters()); - auto trace = interpreter().get_trace(); + auto trace = get_trace(); for (auto& function_name : trace) { if (function_name.is_empty()) function_name = "";