1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

js: Limit number of consecutive error trace entries being printed

> function f(){f()}f()
    Uncaught exception: [RuntimeError]: Call stack size limit exceeded
     -> f
     1234 more calls
     -> (global execution context)
    > function a(x){if(x>0){a(x-1)}else{throw Error()}}function b(x){if(x>0){b(x-1)}else{a(5)}}function c(){b(2)}c()
    Uncaught exception: [Error]
     -> a
     5 more calls
     -> b
     -> b
     -> b
     -> c
     -> (global execution context)
This commit is contained in:
Linus Groh 2020-11-08 12:58:49 +00:00 committed by Andreas Kling
parent a02b9983f9
commit 5c9d7d8026

View file

@ -363,8 +363,25 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source
print(vm->exception()->value());
auto trace = vm->exception()->trace();
if (trace.size() > 1) {
for (auto& function_name : trace)
printf(" -> %s\n", function_name.characters());
unsigned repetitions = 0;
for (size_t i = 0; i < trace.size(); ++i) {
auto& function_name = trace[i];
if (i + 1 < trace.size() && trace[i + 1] == function_name) {
repetitions++;
continue;
}
if (repetitions > 4) {
// If more than 5 (1 + >4) consecutive function calls with the same name, print
// the name only once and show the number of repetitions instead. This prevents
// printing ridiculously large call stacks of recursive functions.
outln(" -> {}", function_name);
outln(" {} more calls", repetitions);
} else {
for (size_t j = 0; j < repetitions + 1; ++j)
outln(" -> {}", function_name);
}
repetitions = 0;
}
}
vm->clear_exception();
return false;