1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 13:27:35 +00:00

LibJS+LibWeb: Log JavaScript exceptions raised by web content

Instead of hiding JS exceptions raised on the web, we now print them to
the debug log. This will make it a bit easier to work out why some web
pages aren't working right. :^)
This commit is contained in:
Andreas Kling 2020-11-29 16:48:14 +01:00
parent 2dd03a4200
commit 01c8765519
3 changed files with 10 additions and 4 deletions

View file

@ -264,8 +264,7 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
void VM::throw_exception(Exception* exception) void VM::throw_exception(Exception* exception)
{ {
#ifdef VM_DEBUG if (should_log_exceptions() && exception->value().is_object() && exception->value().as_object().is_error()) {
if (exception->value().is_object() && exception->value().as_object().is_error()) {
auto& error = static_cast<Error&>(exception->value().as_object()); auto& error = static_cast<Error&>(exception->value().as_object());
dbgln("Throwing JavaScript Error: {}, {}", error.name(), error.message()); dbgln("Throwing JavaScript Error: {}, {}", error.name(), error.message());
@ -276,7 +275,7 @@ void VM::throw_exception(Exception* exception)
dbgln(" {}", function_name); dbgln(" {}", function_name);
} }
} }
#endif
m_exception = exception; m_exception = exception;
unwind(ScopeType::Try); unwind(ScopeType::Try);
} }

View file

@ -75,6 +75,9 @@ public:
static NonnullRefPtr<VM> create(); static NonnullRefPtr<VM> create();
~VM(); ~VM();
bool should_log_exceptions() const { return m_should_log_exceptions; }
void set_should_log_exceptions(bool b) { m_should_log_exceptions = b; }
Heap& heap() { return m_heap; } Heap& heap() { return m_heap; }
const Heap& heap() const { return m_heap; } const Heap& heap() const { return m_heap; }
@ -275,6 +278,8 @@ private:
#undef __JS_ENUMERATE #undef __JS_ENUMERATE
Shape* m_scope_object_shape { nullptr }; Shape* m_scope_object_shape { nullptr };
bool m_should_log_exceptions { false };
}; };
template<> template<>

View file

@ -488,8 +488,10 @@ Color Document::visited_link_color() const
static JS::VM& main_thread_vm() static JS::VM& main_thread_vm()
{ {
static RefPtr<JS::VM> vm; static RefPtr<JS::VM> vm;
if (!vm) if (!vm) {
vm = JS::VM::create(); vm = JS::VM::create();
vm->set_should_log_exceptions(true);
}
return *vm; return *vm;
} }