1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 17:44:56 +09:00

LibJS: Allow creating the specialized Optional<Value> from OptionalNone

This allows, for example:

    ThrowCompletionOr<Optional<Value>> foo()
    {
        return OptionalNone {};
    }

The constructors and constraints here are lifted verbatim from
AK::Optional.
This commit is contained in:
Timothy Flynn 2024-02-01 12:41:46 -05:00 committed by Tim Flynn
parent 36553d4566
commit 3ca86cd044
Notes: sideshowbarker 2024-07-16 17:12:03 +09:00

View file

@ -602,6 +602,9 @@ public:
Optional() = default;
template<SameAs<OptionalNone> V>
Optional(V) { }
Optional(Optional<JS::Value> const& other)
{
if (other.has_value())
@ -614,12 +617,20 @@ public:
}
template<typename U = JS::Value>
requires(!IsSame<OptionalNone, RemoveCVReference<U>>)
explicit(!IsConvertible<U&&, JS::Value>) Optional(U&& value)
requires(!IsSame<RemoveCVReference<U>, Optional<JS::Value>> && IsConstructible<JS::Value, U &&>)
: m_value(forward<U>(value))
{
}
template<SameAs<OptionalNone> V>
Optional& operator=(V)
{
clear();
return *this;
}
Optional& operator=(Optional const& other)
{
if (this != &other) {