From 029db614e3c04279b9ae6c7e21e07baeccad63fd Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 15 Dec 2022 09:12:12 +0000 Subject: [PATCH] LibJS: Ensure Optional'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 const&). See investigation by Tim here: https://github.com/SerenityOS/serenity/pull/16498#discussion_r1049090456 Co-authored-by: Timothy Flynn --- Userland/Libraries/LibJS/Runtime/Completion.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index 0367d25727..1ca4fa4260 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -131,10 +131,7 @@ class Optional { public: using ValueType = JS::Completion; - Optional() - : m_value(JS::Completion(JS::Completion::EmptyTag {})) - { - } + Optional() = default; Optional(Optional const& other) { @@ -228,7 +225,7 @@ public: JS::Completion* operator->() { return &value(); } private: - JS::Completion m_value; + JS::Completion m_value { JS::Completion::EmptyTag {} }; }; }