diff options
author | Linus Groh <mail@linusgroh.de> | 2020-06-02 13:54:26 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-02 15:22:34 +0200 |
commit | a48080f62daa3b236f5d077ae42726cb3121bb43 (patch) | |
tree | e1cc3811d34ee917d0b7f57c092f4f3ebe15d24d /Libraries | |
parent | 9e3127785e2950fa849ebf7bcabf3a41286bf009 (diff) | |
download | serenity-a48080f62daa3b236f5d077ae42726cb3121bb43.zip |
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().
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Console.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibJS/Console.h | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Interpreter.cpp | 9 | ||||
-rw-r--r-- | Libraries/LibJS/Interpreter.h | 1 |
4 files changed, 12 insertions, 10 deletions
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<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; +} + } 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<String> 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<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; -} - } 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<String> get_trace() const; private: Interpreter(); |