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

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

View file

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