1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:57:46 +00:00

LibJS: Return Optional<T> from Completion::{value,target}(), not T

In the end this is a nicer API than having separate has_{value,target}()
and having to check those first, and then making another Optional from
the unwrapped value:

    completion.has_value() ? completion.value() : Optional<Value> {}
    //                       ^^^^^^^^^^^^^^^^^^
    //         Implicit creation of non-empty Optional<Value>

This way we need to unwrap the optional ourselves, but can easily pass
it to something else as well.

This is in anticipation of the AST using completions :^)
This commit is contained in:
Linus Groh 2021-12-28 17:42:14 +01:00
parent b39aede8fe
commit 85f0fc2b83
15 changed files with 55 additions and 57 deletions

View file

@ -60,12 +60,10 @@ public:
}
[[nodiscard]] Type type() const { return m_type; }
[[nodiscard]] bool has_value() const { return m_value.has_value(); }
[[nodiscard]] Value value() const { return *m_value; }
[[nodiscard]] bool has_target() const { return m_target.has_value(); }
[[nodiscard]] FlyString const& target() const { return *m_target; }
[[nodiscard]] Optional<Value>& value() { return m_value; }
[[nodiscard]] Optional<Value> const& value() const { return m_value; }
[[nodiscard]] Optional<FlyString>& target() { return m_target; }
[[nodiscard]] Optional<FlyString> const& target() const { return m_target; }
// "abrupt completion refers to any completion with a [[Type]] value other than normal"
[[nodiscard]] bool is_abrupt() const { return m_type != Type::Normal; }