1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +00:00

LibJS: Lazily collect stack trace information

The previous implementation was calling `backtrace()` for every
function call, which is quite slow.

Instead, this implementation provides VM::stack_trace() which unwinds
the native stack, maps it through NativeExecutable::get_source_range
and combines it with source ranges from interpreted call frames.
This commit is contained in:
Simon Wanner 2023-11-01 00:39:28 +01:00 committed by Andreas Kling
parent 77dc7c4d36
commit 68f4d21de2
11 changed files with 96 additions and 46 deletions

View file

@ -75,13 +75,13 @@ ThrowCompletionOr<void> Error::install_error_cause(Value options)
void Error::populate_stack()
{
auto& vm = this->vm();
m_traceback.ensure_capacity(vm.execution_context_stack().size());
for (ssize_t i = vm.execution_context_stack().size() - 1; i >= 0; i--) {
auto context = vm.execution_context_stack()[i];
auto stack_trace = vm().stack_trace();
m_traceback.ensure_capacity(stack_trace.size());
for (auto& element : stack_trace) {
auto* context = element.execution_context;
UnrealizedSourceRange range = {};
if (context->instruction_stream_iterator.has_value())
range = context->instruction_stream_iterator->source_range();
if (element.source_range.has_value())
range = element.source_range.value();
TracebackFrame frame {
.function_name = context->function_name,
.source_range_storage = range,