mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +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:
parent
a02b9983f9
commit
5c9d7d8026
1 changed files with 19 additions and 2 deletions
|
@ -363,8 +363,25 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source
|
||||||
print(vm->exception()->value());
|
print(vm->exception()->value());
|
||||||
auto trace = vm->exception()->trace();
|
auto trace = vm->exception()->trace();
|
||||||
if (trace.size() > 1) {
|
if (trace.size() > 1) {
|
||||||
for (auto& function_name : trace)
|
unsigned repetitions = 0;
|
||||||
printf(" -> %s\n", function_name.characters());
|
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();
|
vm->clear_exception();
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue