diff options
author | Andreas Kling <kling@serenityos.org> | 2021-06-21 20:54:02 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-21 20:58:55 +0200 |
commit | 0d2aba07aaf3fa6829a140ad471b212c9ec5dc72 (patch) | |
tree | aecc51c6c1d56cf38c34c92da156fcd3548820b6 /Userland/Libraries/LibJS | |
parent | 4c8df58e088570cf97a7ad807cf4f1190a380453 (diff) | |
download | serenity-0d2aba07aaf3fa6829a140ad471b212c9ec5dc72.zip |
LibJS: Add VM::dump_scope_chain()
This is a handy helper that dumps the current scope chain, starting at
the innermost scope.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/VM.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/VM.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 2efebbe12d..17bc99b593 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -622,4 +622,17 @@ void VM::dump_backtrace() const dbgln("-> {}", m_call_stack[i]->function_name); } +void VM::dump_scope_chain() const +{ + for (auto* scope = current_scope(); scope; scope = scope->parent()) { + dbgln("+> {} ({:p})", scope->class_name(), scope); + if (is<LexicalEnvironment>(*scope)) { + auto& lexical_environment = static_cast<LexicalEnvironment const&>(*scope); + for (auto& variable : lexical_environment.variables()) { + dbgln(" {}", variable.key); + } + } + } +} + } diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 8f70ffb614..ef2510cf21 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -72,6 +72,7 @@ public: void clear_exception() { m_exception = nullptr; } void dump_backtrace() const; + void dump_scope_chain() const; class InterpreterExecutionScope { public: |