diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index db7763d0a7..c789f4d36a 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -126,7 +126,7 @@ Optional LogicalExpression::generate_bytecode(Bytecode::Gene auto result_reg = generator.allocate_register(); auto lhs_reg = m_lhs->generate_bytecode(generator); - Bytecode::Instruction* test_instr; + Bytecode::Op::Jump* test_instr; switch (m_op) { case LogicalOp::And: test_instr = &generator.emit(*lhs_reg); @@ -145,20 +145,7 @@ Optional LogicalExpression::generate_bytecode(Bytecode::Gene auto& end_jump = generator.emit(); auto rhs_label = generator.make_label(); - - switch (m_op) { - case LogicalOp::And: - static_cast(test_instr)->set_target(rhs_label); - break; - case LogicalOp::Or: - static_cast(test_instr)->set_target(rhs_label); - break; - case LogicalOp::NullishCoalescing: - static_cast(test_instr)->set_target(rhs_label); - break; - default: - VERIFY_NOT_REACHED(); - } + test_instr->set_target(rhs_label); auto rhs_reg = m_rhs->generate_bytecode(generator); generator.emit(result_reg, *rhs_reg); diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index d60138196c..b80b744a77 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -229,8 +229,14 @@ private: Register m_src; }; -class Jump final : public Instruction { +class Jump : public Instruction { public: + explicit Jump(Type type, Optional