From bdcb5ed510b9b3fc5bd5c5b99cd3660b12a87f08 Mon Sep 17 00:00:00 2001 From: cola119 Date: Wed, 27 Dec 2023 16:19:01 +0900 Subject: [PATCH] tools: update inspector_protocol to c488ba2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/51293 Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca --- .../inspector_protocol/lib/Forward_h.template | 1 - tools/inspector_protocol/lib/Maybe_h.template | 84 +++++++------------ 2 files changed, 31 insertions(+), 54 deletions(-) diff --git a/tools/inspector_protocol/lib/Forward_h.template b/tools/inspector_protocol/lib/Forward_h.template index ff5e685863395b..746ba20bba15f4 100644 --- a/tools/inspector_protocol/lib/Forward_h.template +++ b/tools/inspector_protocol/lib/Forward_h.template @@ -28,7 +28,6 @@ class DispatchResponse; class ErrorSupport; class FundamentalValue; class ListValue; -template class Maybe; class Object; using Response = DispatchResponse; class SerializedValue; diff --git a/tools/inspector_protocol/lib/Maybe_h.template b/tools/inspector_protocol/lib/Maybe_h.template index 15b0aa4a22f629..8dfee7e9d5cb72 100644 --- a/tools/inspector_protocol/lib/Maybe_h.template +++ b/tools/inspector_protocol/lib/Maybe_h.template @@ -13,12 +13,13 @@ namespace {{namespace}} { {% endfor %} +namespace detail { template -class Maybe { +class PtrMaybe { public: - Maybe() : m_value() { } - Maybe(std::unique_ptr value) : m_value(std::move(value)) { } - Maybe(Maybe&& other) noexcept : m_value(std::move(other.m_value)) {} + PtrMaybe() = default; + PtrMaybe(std::unique_ptr value) : m_value(std::move(value)) { } + PtrMaybe(PtrMaybe&& other) noexcept : m_value(std::move(other.m_value)) {} void operator=(std::unique_ptr value) { m_value = std::move(value); } T* fromJust() const { DCHECK(m_value); return m_value.get(); } T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; } @@ -29,68 +30,45 @@ private: }; template -class MaybeBase { +class ValueMaybe { public: - MaybeBase() : m_isJust(false) { } - MaybeBase(T value) : m_isJust(true), m_value(value) { } - MaybeBase(MaybeBase&& other) noexcept + ValueMaybe() : m_isJust(false), m_value() { } + ValueMaybe(T value) : m_isJust(true), m_value(std::move(value)) { } + ValueMaybe(ValueMaybe&& other) noexcept : m_isJust(other.m_isJust), m_value(std::move(other.m_value)) {} void operator=(T value) { m_value = value; m_isJust = true; } - T fromJust() const { DCHECK(m_isJust); return m_value; } - T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; } + const T& fromJust() const { DCHECK(m_isJust); return m_value; } + const T& fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; } bool isJust() const { return m_isJust; } - T takeJust() { DCHECK(m_isJust); return m_value; } - -protected: + T takeJust() { DCHECK(m_isJust); return std::move(m_value); } +private: bool m_isJust; T m_value; }; -template<> -class Maybe : public MaybeBase { -public: - Maybe() { m_value = false; } - Maybe(bool value) : MaybeBase(value) { } - Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {} - using MaybeBase::operator=; -}; +template +struct MaybeTypedef { typedef PtrMaybe type; }; -template<> -class Maybe : public MaybeBase { -public: - Maybe() { m_value = 0; } - Maybe(int value) : MaybeBase(value) { } - Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {} - using MaybeBase::operator=; -}; +template <> +struct MaybeTypedef { typedef ValueMaybe type; }; -template<> -class Maybe : public MaybeBase { -public: - Maybe() { m_value = 0; } - Maybe(double value) : MaybeBase(value) { } - Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {} - using MaybeBase::operator=; -}; +template <> +struct MaybeTypedef { typedef ValueMaybe type; }; -template<> -class Maybe : public MaybeBase { -public: - Maybe() { } - Maybe(const String& value) : MaybeBase(value) { } - Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {} - using MaybeBase::operator=; -}; +template <> +struct MaybeTypedef { typedef ValueMaybe type; }; -template<> -class Maybe : public MaybeBase { -public: - Maybe() { } - Maybe(Binary value) : MaybeBase(value) { } - Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {} - using MaybeBase::operator=; -}; +template <> +struct MaybeTypedef { typedef ValueMaybe type; }; + +template <> +struct MaybeTypedef { typedef ValueMaybe type; }; + +} // namespace detail + +template +using Maybe = typename detail::MaybeTypedef::type; {% for namespace in config.protocol.namespace %} } // namespace {{namespace}}