diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-03-31 03:09:36 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-31 18:11:08 +0200 |
commit | 7ea095feb0df1eb7557838273095d867c9ff3cf8 (patch) | |
tree | 110fa49650af61027a707f4b6a1ad773866ac402 | |
parent | 56c0fdc1c429de0b826436b4c6a9ecf5de6b7019 (diff) | |
download | serenity-7ea095feb0df1eb7557838273095d867c9ff3cf8.zip |
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.
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 32f5d50db0..2ade544fe7 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -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())); + } } } } |