diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 4201467660..5a4e8dd37f 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1270,6 +1270,8 @@ static Bytecode::CodeGenerationErrorOr generate_array_binding_pattern_byte VERIFY(name.has()); if (is_rest) { + VERIFY(!initializer); + if (first) { // The iterator has not been called, and is thus known to be not exhausted generator.emit(iterator_reg); @@ -1358,6 +1360,21 @@ static Bytecode::CodeGenerationErrorOr generate_array_binding_pattern_byte // pattern if necessary. generator.switch_to_basic_block(create_binding_block); + if (initializer) { + auto& value_is_undefined_block = generator.make_block(); + auto& value_is_not_undefined_block = generator.make_block(); + + generator.emit().set_targets( + Bytecode::Label { value_is_undefined_block }, + Bytecode::Label { value_is_not_undefined_block }); + + generator.switch_to_basic_block(value_is_undefined_block); + TRY(initializer->generate_bytecode(generator)); + generator.emit(Bytecode::Label { value_is_not_undefined_block }); + + generator.switch_to_basic_block(value_is_not_undefined_block); + } + TRY(assign_accumulator_to_alias(alias)); first = false;