mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:38:12 +00:00
LibJS: Don't evaluate computed MemberExpression LHS twice in assignments
The following snippet would cause "i" to be incremented twice(!): let a = [] let i = 0 a[++i] += 0 This patch solves the issue by remembering the base object and property name for computed MemberExpression LHS in codegen. We the store the result of the assignment to the same object and property (instead of computing the LHS again). 3 new passes on test262. :^)
This commit is contained in:
parent
2083376618
commit
732b39d120
3 changed files with 42 additions and 15 deletions
|
@ -74,15 +74,17 @@ public:
|
|||
op->set_source_record({ m_current_ast_node->start_offset(), m_current_ast_node->end_offset() });
|
||||
}
|
||||
|
||||
CodeGenerationErrorOr<void> emit_load_from_reference(JS::ASTNode const&);
|
||||
struct ReferenceRegisters {
|
||||
Register base; // [[Base]]
|
||||
Optional<Register> referenced_name; // [[ReferencedName]]
|
||||
Register this_value; // [[ThisValue]]
|
||||
};
|
||||
|
||||
CodeGenerationErrorOr<Optional<ReferenceRegisters>> emit_load_from_reference(JS::ASTNode const&);
|
||||
CodeGenerationErrorOr<void> emit_store_to_reference(JS::ASTNode const&);
|
||||
CodeGenerationErrorOr<void> emit_store_to_reference(ReferenceRegisters const&);
|
||||
CodeGenerationErrorOr<void> emit_delete_reference(JS::ASTNode const&);
|
||||
|
||||
struct ReferenceRegisters {
|
||||
Register base; // [[Base]]
|
||||
Optional<Bytecode::Register> referenced_name; // [[ReferencedName]]
|
||||
Register this_value; // [[ThisValue]]
|
||||
};
|
||||
CodeGenerationErrorOr<ReferenceRegisters> emit_super_reference(MemberExpression const&);
|
||||
|
||||
void emit_set_variable(JS::Identifier const& identifier, Bytecode::Op::SetVariable::InitializationMode initialization_mode = Bytecode::Op::SetVariable::InitializationMode::Set, Bytecode::Op::EnvironmentMode mode = Bytecode::Op::EnvironmentMode::Lexical);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue