1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:18:12 +00:00

LibJS: Don't assume that for-in/of target is a variable on LHS::Assign

e.g. `for ([foo.bar] in ...)` is actually a binding pattern.
This commit is contained in:
Ali Mohammad Pur 2022-03-31 03:09:36 +04:30 committed by Andreas Kling
parent 56c0fdc1c4
commit 7ea095feb0

View file

@ -1910,7 +1910,12 @@ static Bytecode::CodeGenerationErrorOr<void> for_in_of_body_evaluation(Bytecode:
VERIFY(declaration.declarations().size() == 1);
TRY(assign_accumulator_to_variable_declarator(generator, declaration.declarations().first(), declaration));
} else {
TRY(generator.emit_store_to_reference(*lhs.get<NonnullRefPtr<ASTNode>>()));
if (auto ptr = lhs.get_pointer<NonnullRefPtr<ASTNode>>()) {
TRY(generator.emit_store_to_reference(**ptr));
} else {
auto& binding_pattern = lhs.get<NonnullRefPtr<BindingPattern>>();
TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, Bytecode::Op::SetVariable::InitializationMode::Set, Bytecode::Register::accumulator()));
}
}
}
}