mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibJS: Store basic traceback in Exception
Nothing fancy like line numbers, but Exception now stores a list of function names up to the current call frame.
This commit is contained in:
parent
a48080f62d
commit
4f6912c605
Notes:
sideshowbarker
2024-07-19 05:53:15 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/4f6912c6056 Pull-request: https://github.com/SerenityOS/serenity/pull/2481 Reviewed-by: https://github.com/awesomekling
2 changed files with 10 additions and 0 deletions
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/Exception.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -31,6 +32,13 @@ namespace JS {
|
|||
Exception::Exception(Value value)
|
||||
: m_value(value)
|
||||
{
|
||||
auto call_stack = interpreter().call_stack();
|
||||
for (ssize_t i = call_stack.size() - 1; i >= 0; --i) {
|
||||
auto function_name = call_stack[i].function_name;
|
||||
if (function_name.is_empty())
|
||||
function_name = "<anonymous>";
|
||||
m_trace.append(function_name);
|
||||
}
|
||||
}
|
||||
|
||||
Exception::~Exception()
|
||||
|
|
|
@ -37,12 +37,14 @@ public:
|
|||
virtual ~Exception() override;
|
||||
|
||||
Value value() const { return m_value; }
|
||||
const Vector<String>& trace() const { return m_trace; }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "Exception"; }
|
||||
virtual void visit_children(Visitor&) override;
|
||||
|
||||
Value m_value;
|
||||
Vector<String> m_trace;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue