diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 4e51f78bd6..4201467660 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -521,6 +521,8 @@ Bytecode::CodeGenerationErrorOr Identifier::generate_bytecode(Bytecode::Ge return {}; } +static Bytecode::CodeGenerationErrorOr generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode, Bytecode::Register const& value_reg); + Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(Bytecode::Generator& generator) const { if (m_op == AssignmentOp::Assignment) { @@ -600,7 +602,18 @@ Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(By }, // 2. Let assignmentPattern be the AssignmentPattern that is covered by LeftHandSideExpression. [&](NonnullRefPtr const& pattern) -> Bytecode::CodeGenerationErrorOr { - TODO(); + // 3. Let rref be the result of evaluating AssignmentExpression. + // 4. Let rval be ? GetValue(rref). + TRY(m_rhs->generate_bytecode(generator)); + auto value_register = generator.allocate_register(); + generator.emit(value_register); + + // 5. Perform ? DestructuringAssignmentEvaluation of assignmentPattern with argument rval. + TRY(generate_binding_pattern_bytecode(generator, pattern, Bytecode::Op::SetVariable::InitializationMode::Set, value_register)); + + // 6. Return rval. + generator.emit(value_register); + return {}; }); } @@ -1107,8 +1120,6 @@ Bytecode::CodeGenerationErrorOr FunctionExpression::generate_bytecode(Byte return {}; } -static Bytecode::CodeGenerationErrorOr generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode, Bytecode::Register const& value_reg); - static Bytecode::CodeGenerationErrorOr generate_object_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Register const& value_reg) { Vector excluded_property_names;