diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 038cf0e5c7..a6f70b0c53 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -2586,6 +2587,12 @@ Bytecode::CodeGenerationErrorOr> SwitchStatement::genera generator.emit(Bytecode::Label { *next_test_block }); + Queue test_blocks; + for (auto& switch_case : m_cases) { + if (switch_case->test()) + test_blocks.enqueue(&generator.make_block()); + } + for (auto& switch_case : m_cases) { auto& case_block = generator.make_block(); if (switch_case->test()) { @@ -2593,7 +2600,7 @@ Bytecode::CodeGenerationErrorOr> SwitchStatement::genera auto test_value = TRY(switch_case->test()->generate_bytecode(generator)).value(); auto result = generator.allocate_register(); generator.emit(result, test_value, discriminant); - next_test_block = &generator.make_block(); + next_test_block = test_blocks.dequeue(); generator.emit( result, Bytecode::Label { case_block },