mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:27:35 +00:00
LibWeb: Make ExceptionOr capable of holding all error types in the spec
The WebIDL spec specifies a few "simple" exception types in addition to the DOMException type, let's support all of those. This allows functions returning ExceptionOr<T> to throw regular javascript exceptions (as limited by the webidl spec) by returning a `DOM::SimpleException { DOM::SimpleExceptionType::T, "error message" }` which is pretty damn cool :^)
This commit is contained in:
parent
bda19a9ff3
commit
fd72597999
4 changed files with 77 additions and 35 deletions
|
@ -24,7 +24,10 @@ template<typename T>
|
|||
ALWAYS_INLINE bool throw_dom_exception(JS::VM& vm, JS::GlobalObject& global_object, DOM::ExceptionOr<T>& result)
|
||||
{
|
||||
if (result.is_exception()) {
|
||||
vm.throw_exception(global_object, DOMExceptionWrapper::create(global_object, const_cast<DOM::DOMException&>(result.exception())));
|
||||
result.materialized_exception(global_object)
|
||||
.visit(
|
||||
[&](NonnullRefPtr<DOM::DOMException> dom_exception) { vm.throw_exception(global_object, DOMExceptionWrapper::create(global_object, move(dom_exception))); },
|
||||
[&](auto* js_exception) { vm.throw_exception(global_object, js_exception); });
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -47,6 +50,11 @@ struct ExtractExceptionOrValueType<void> {
|
|||
using Type = JS::Value;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ExtractExceptionOrValueType<DOM::ExceptionOr<Empty>> {
|
||||
using Type = JS::Value;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ExtractExceptionOrValueType<DOM::ExceptionOr<void>> {
|
||||
using Type = JS::Value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue