mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 23:09:08 +00:00
This commit removes all exception related code: Remove VM::exception(), VM::throw_exception() etc. Any leftover throw_exception calls are moved to throw_completion. The one method left is clear_exception() which is now a no-op. Most of these calls are just to clear whatever exception might have been thrown when handling a Completion. So to have a cleaner commit this will be removed in a next commit. It also removes the actual Exception and TemporaryClearException classes since these are no longer used. In any spot where the exception was actually used an attempt was made to preserve that behavior. However since it is no longer tracked by the VM we cannot access exceptions which were thrown in previous calls. There are two such cases which might have different behavior: - In Web::DOM::Document::interpreter() the on_call_stack_emptied hook used to print any uncaught exception but this is now no longer possible as the VM does not store uncaught exceptions. - In js the code used to be interruptable by throwing an exception on the VM. This is no longer possible but was already somewhat fragile before as you could happen to throw an exception just before a VERIFY.
45 lines
2 KiB
C++
45 lines
2 KiB
C++
/*
|
|
* Copyright (c) 2022, David Tuin <davidot@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/TypeCasts.h>
|
|
#include <LibJS/Runtime/VM.h>
|
|
#include <LibJS/Runtime/Value.h>
|
|
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
// https://html.spec.whatwg.org/#report-the-exception
|
|
void report_exception(JS::ThrowCompletionOr<JS::Value> const& result)
|
|
{
|
|
// FIXME: This is just old code, and does not strictly follow the spec of report an exception.
|
|
// FIXME: We should probably also report these exceptions to the JS console.
|
|
VERIFY(result.throw_completion().value().has_value());
|
|
auto thrown_value = *result.throw_completion().value();
|
|
if (thrown_value.is_object()) {
|
|
auto& object = thrown_value.as_object();
|
|
auto& vm = object.vm();
|
|
auto name = object.get_without_side_effects(vm.names.name).value_or(JS::js_undefined());
|
|
auto message = object.get_without_side_effects(vm.names.message).value_or(JS::js_undefined());
|
|
if (name.is_accessor() || message.is_accessor()) {
|
|
// The result is not going to be useful, let's just print the value. This affects DOMExceptions, for example.
|
|
dbgln("\033[31;1mUnhandled JavaScript exception:\033[0m {}", thrown_value);
|
|
} else {
|
|
dbgln("\033[31;1mUnhandled JavaScript exception:\033[0m [{}] {}", name, message);
|
|
}
|
|
if (is<JS::Error>(object)) {
|
|
auto const& error_value = static_cast<JS::Error const&>(object);
|
|
for (auto const& traceback_frame : error_value.traceback()) {
|
|
auto const& function_name = traceback_frame.function_name;
|
|
auto const& source_range = traceback_frame.source_range;
|
|
dbgln(" {} at {}:{}:{}", function_name, source_range.filename, source_range.start.line, source_range.start.column);
|
|
}
|
|
}
|
|
} else {
|
|
dbgln("\033[31;1mUnhandled JavaScript exception:\033[0m {}", thrown_value);
|
|
}
|
|
}
|
|
|
|
}
|