summaryrefslogtreecommitdiff
path: root/Userland/Utilities
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-04-24 18:15:02 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-24 20:11:04 +0200
commit97d49cb92bab1ef353153da54b7f4cb08d65b25e (patch)
tree480a8999f42440a9477bd296393f88b8ce1753ca /Userland/Utilities
parent0cf04d07aa6da1399f1c847453e1bfd815fe4dc2 (diff)
downloadserenity-97d49cb92bab1ef353153da54b7f4cb08d65b25e.zip
LibJS: Consolidate exception function names and source ranges
Instead of storing the function names (in a badly named Vector<String>) and source ranges separately, consolidate them into a new struct: TracebackFrame. This makes it both easier to use now and easier to extend in the future. Unlike before we now keep each call frame's current node source range in the traceback frame next to the function name, meaning we can display line and column numbers outside of the VM and after the call stack is emptied.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r--Userland/Utilities/js.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index 391520e789..b2f2ed09fe 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -489,24 +489,27 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source
vm->clear_exception();
out("Uncaught exception: ");
print(exception->value());
- auto& trace = exception->trace();
- if (trace.size() > 1) {
+ auto& traceback = exception->traceback();
+ if (traceback.size() > 1) {
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;
+ for (size_t i = 0; i < traceback.size(); ++i) {
+ auto& traceback_frame = traceback[i];
+ if (i + 1 < traceback.size()) {
+ auto& next_traceback_frame = traceback[i + 1];
+ if (next_traceback_frame.function_name == traceback_frame.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(" -> {}", traceback_frame.function_name);
outln(" {} more calls", repetitions);
} else {
for (size_t j = 0; j < repetitions + 1; ++j)
- outln(" -> {}", function_name);
+ outln(" -> {}", traceback_frame.function_name);
}
repetitions = 0;
}