From 426e32e5c0658c2cd3741392c88ad9202c542a6f Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 25 Sep 2022 19:11:43 +0100 Subject: [PATCH] LibWeb: Add WebIDL::ExceptionOr constructor for wrapped ValueType This is copied from JS::ThrowCompletionOr and will allow using them interchangeably with types wrapped by JS::Value such as JS::Object*. --- Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h b/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h index c771db12b0..9ce61493b6 100644 --- a/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h +++ b/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h @@ -50,6 +50,15 @@ public: { } + // Allows implicit construction of ExceptionOr from a type U if T(U) is a supported constructor. + // Most commonly: Value from Object* or similar, so we can omit the curly braces from "return { TRY(...) };". + // Disabled for POD types to avoid weird conversion shenanigans. + template + ExceptionOr(WrappedValueType result) requires(!IsPOD) + : m_result(move(result)) + { + } + ExceptionOr(JS::NonnullGCPtr exception) : m_exception(move(exception)) {