diff --git a/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Libraries/LibJS/Bytecode/ASTCodegen.cpp index df208a3b4cb..0ed6109711e 100644 --- a/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -3456,8 +3456,9 @@ Bytecode::CodeGenerationErrorOr> ClassFieldInitializerSt { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(*m_expression, generator.intern_identifier(m_class_field_identifier_name), preferred_dst)); + VERIFY(value.has_value()); generator.perform_needed_unwinds(); - generator.emit(value.has_value() ? value->operand() : Optional {}); + generator.emit(value->operand()); return value; } diff --git a/Libraries/LibJS/Bytecode/Interpreter.cpp b/Libraries/LibJS/Bytecode/Interpreter.cpp index c91d6cc330e..2815ac10270 100644 --- a/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -2925,10 +2925,7 @@ void NewFunction::execute_impl(Bytecode::Interpreter& interpreter) const void Return::execute_impl(Bytecode::Interpreter& interpreter) const { - if (m_value.has_value()) - interpreter.do_return(interpreter.get(*m_value)); - else - interpreter.do_return(js_undefined()); + interpreter.do_return(interpreter.get(m_value)); } ThrowCompletionOr Increment::execute_impl(Bytecode::Interpreter& interpreter) const @@ -3781,9 +3778,7 @@ ByteString NewClass::to_byte_string_impl(Bytecode::Executable const& executable) ByteString Return::to_byte_string_impl(Bytecode::Executable const& executable) const { - if (m_value.has_value()) - return ByteString::formatted("Return {}", format_operand("value"sv, m_value.value(), executable)); - return "Return"; + return ByteString::formatted("Return {}", format_operand("value"sv, m_value, executable)); } ByteString Increment::to_byte_string_impl(Bytecode::Executable const& executable) const diff --git a/Libraries/LibJS/Bytecode/Op.h b/Libraries/LibJS/Bytecode/Op.h index 56737394b3c..479fce53a60 100644 --- a/Libraries/LibJS/Bytecode/Op.h +++ b/Libraries/LibJS/Bytecode/Op.h @@ -2176,7 +2176,7 @@ class Return final : public Instruction { public: constexpr static bool IsTerminator = true; - explicit Return(Optional value = {}) + explicit Return(Operand value) : Instruction(Type::Return) , m_value(value) { @@ -2186,14 +2186,13 @@ public: ByteString to_byte_string_impl(Bytecode::Executable const&) const; void visit_operands_impl(Function visitor) { - if (m_value.has_value()) - visitor(m_value.value()); + visitor(m_value); } - Optional const& value() const { return m_value; } + Operand const& value() const { return m_value; } private: - Optional m_value; + Operand m_value; }; class Increment final : public Instruction {