diff --git a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h index 57862eaa23..ef888bbc9e 100644 --- a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h +++ b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, the SerenityOS developers. + * Copyright (c) 2021-2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -75,6 +75,9 @@ ALWAYS_INLINE JS::Completion dom_exception_to_throw_completion(auto&& vm, auto&& }, [&](JS::NonnullGCPtr const& exception) { return throw_completion(exception); + }, + [&](JS::Completion const& completion) { + return completion; }); } diff --git a/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h b/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h index aec297d69d..c771db12b0 100644 --- a/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h +++ b/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace Web::WebIDL { @@ -59,9 +60,18 @@ public: { } - ExceptionOr(Variant> exception) - : m_exception(move(exception).template downcast>()) + ExceptionOr(JS::Completion exception) + : m_exception(move(exception)) { + auto const& completion = m_exception.get(); + VERIFY(completion.is_error()); + } + + ExceptionOr(Variant, JS::Completion> exception) + : m_exception(move(exception).template downcast, JS::Completion>()) + { + if (auto* completion = m_exception.template get_pointer()) + VERIFY(completion->is_error()); } ExceptionOr(ExceptionOr&& other) = default; @@ -78,9 +88,9 @@ public: return m_result.release_value(); } - Variant> exception() const + Variant, JS::Completion> exception() const { - return m_exception.template downcast>(); + return m_exception.template downcast, JS::Completion>(); } bool is_exception() const @@ -90,13 +100,13 @@ public: // These are for compatibility with the TRY() macro in AK. [[nodiscard]] bool is_error() const { return is_exception(); } - Variant> release_error() { return exception(); } + Variant, JS::Completion> release_error() { return exception(); } private: Optional m_result; // https://webidl.spec.whatwg.org/#idl-exceptions - Variant> m_exception {}; + Variant, JS::Completion> m_exception {}; }; template<>