From a48080f62daa3b236f5d077ae42726cb3121bb43 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 2 Jun 2020 13:54:26 +0100 Subject: [PATCH] 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(). --- Applications/Browser/BrowserConsoleClient.cpp | 2 +- Libraries/LibJS/Console.cpp | 10 ++++++++++ Libraries/LibJS/Console.h | 2 ++ Libraries/LibJS/Interpreter.cpp | 9 --------- Libraries/LibJS/Interpreter.h | 1 - Userland/js.cpp | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Applications/Browser/BrowserConsoleClient.cpp b/Applications/Browser/BrowserConsoleClient.cpp index a444814df2a..3c121c48da2 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 3926840c3c6..5033ed25c99 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 beb59031ced..7465f1c32d0 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 d7b3a51fa5e..c51e586488a 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 659d7e67f87..0e877f50499 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 f244bd2e65a..cfc30d217f5 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 = "";