diff --git a/Userland/js.cpp b/Userland/js.cpp index 316160e0d7..9170c7526e 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -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;