/* * Copyright (c) 2021, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::DOM { template class ExceptionOr { public: ExceptionOr(const ValueType& result) : m_result(result) { } ExceptionOr(ValueType&& result) : m_result(move(result)) { } ExceptionOr(const NonnullRefPtr exception) : m_exception(exception) { } ExceptionOr(ExceptionOr&& other) = default; ExceptionOr(const ExceptionOr& other) = default; ~ExceptionOr() = default; ValueType& value() { return m_result.value(); } ValueType release_value() { return m_result.release_value(); } const DOMException& exception() const { return *m_exception; } bool is_exception() const { return m_exception; } private: Optional m_result; RefPtr m_exception; }; template<> class ExceptionOr { public: ExceptionOr(const NonnullRefPtr exception) : m_exception(exception) { } ExceptionOr() = default; ExceptionOr(ExceptionOr&& other) = default; ExceptionOr(const ExceptionOr& other) = default; ~ExceptionOr() = default; const DOMException& exception() const { return *m_exception; } bool is_exception() const { return m_exception; } private: RefPtr m_exception; }; }