LibJS: Ensure Optional<Completion>'s defaults to empty completion

Default-constructing the m_value Completion made it have an undefined
JS value when not overridden in a constructor, such as the conditional
initialization in Optional(Optional<JS::Completion> const&).

See investigation by Tim here:
https://github.com/SerenityOS/serenity/pull/16498#discussion_r1049090456

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
This commit is contained in:
Linus Groh 2022-12-15 09:12:12 +00:00 committed by Tim Flynn
parent 0991464de6
commit 029db614e3
Notes: sideshowbarker 2024-07-17 03:09:38 +09:00

View file

@ -131,10 +131,7 @@ class Optional<JS::Completion> {
public:
using ValueType = JS::Completion;
Optional()
: m_value(JS::Completion(JS::Completion::EmptyTag {}))
{
}
Optional() = default;
Optional(Optional<JS::Completion> const& other)
{
@ -228,7 +225,7 @@ public:
JS::Completion* operator->() { return &value(); }
private:
JS::Completion m_value;
JS::Completion m_value { JS::Completion::EmptyTag {} };
};
}