mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:57:44 +00:00
LibJS: Track source positions all the way down to exceptions
This makes exceptions have a trace of source positions too, which could probably be helpful in making fancier error tracebacks.
This commit is contained in:
parent
f17874ecd2
commit
b34b681811
10 changed files with 647 additions and 245 deletions
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Runtime/Exception.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
|
||||
|
@ -40,6 +41,13 @@ Exception::Exception(Value value)
|
|||
function_name = "<anonymous>";
|
||||
m_trace.append(function_name);
|
||||
}
|
||||
|
||||
auto& node_stack = vm().node_stack();
|
||||
for (ssize_t i = node_stack.size() - 1; i >= 0; --i) {
|
||||
auto* node = node_stack[i];
|
||||
ASSERT(node);
|
||||
m_source_ranges.append(node->source_range());
|
||||
}
|
||||
}
|
||||
|
||||
Exception::~Exception()
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibJS/Runtime/Cell.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibJS/SourceRange.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -39,6 +40,7 @@ public:
|
|||
|
||||
Value value() const { return m_value; }
|
||||
const Vector<String>& trace() const { return m_trace; }
|
||||
const Vector<SourceRange>& source_ranges() const { return m_source_ranges; }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "Exception"; }
|
||||
|
@ -46,6 +48,7 @@ private:
|
|||
|
||||
Value m_value;
|
||||
Vector<String> m_trace;
|
||||
Vector<SourceRange> m_source_ranges;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -126,10 +126,14 @@ public:
|
|||
|
||||
void pop_call_frame() { m_call_stack.take_last(); }
|
||||
|
||||
void push_ast_node(const ASTNode& node) { m_ast_nodes.append(&node); }
|
||||
void pop_ast_node() { m_ast_nodes.take_last(); }
|
||||
|
||||
CallFrame& call_frame() { return *m_call_stack.last(); }
|
||||
const CallFrame& call_frame() const { return *m_call_stack.last(); }
|
||||
const Vector<CallFrame*>& call_stack() const { return m_call_stack; }
|
||||
Vector<CallFrame*>& call_stack() { return m_call_stack; }
|
||||
const Vector<const ASTNode*>& node_stack() const { return m_ast_nodes; }
|
||||
|
||||
const ScopeObject* current_scope() const { return call_frame().scope; }
|
||||
ScopeObject* current_scope() { return call_frame().scope; }
|
||||
|
@ -249,6 +253,7 @@ private:
|
|||
Vector<Interpreter*> m_interpreters;
|
||||
|
||||
Vector<CallFrame*> m_call_stack;
|
||||
Vector<const ASTNode*> m_ast_nodes;
|
||||
|
||||
Value m_last_value;
|
||||
ScopeType m_unwind_until { ScopeType::None };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue