From 55d9f1cced2f3ee431222a7d2f52773501a0759d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 3 Apr 2021 15:02:56 +0200 Subject: [PATCH] LibJS: Log any exception, not just the ones with a JS::Error value This was super confusing as we would check if the exception's value is a JS::Error and not log it otherwise, even with m_should_log_exceptions set. As a result, things like DOM exceptions were invisible to us with execution just silently stopping, for example. --- Userland/Libraries/LibJS/Runtime/VM.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 6d52861bc9..1ecf5377bd 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -292,9 +292,14 @@ Value VM::construct(Function& function, Function& new_target, Optionalvalue().is_object() && is(exception->value().as_object())) { - auto& error = static_cast(exception->value().as_object()); - dbgln("Throwing JavaScript Error: {}, {}", error.name(), error.message()); + if (should_log_exceptions()) { + auto value = exception->value(); + if (value.is_object() && is(value.as_object())) { + auto& error = static_cast(value.as_object()); + dbgln("Throwing JavaScript exception: [{}] {}", error.name(), error.message()); + } else { + dbgln("Throwing JavaScript exception: {}", value); + } for (ssize_t i = m_call_stack.size() - 1; i >= 0; --i) { const auto& source_range = m_call_stack[i]->current_node->source_range();