diff --git a/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Libraries/LibJS/Bytecode/ASTCodegen.cpp index c070c4768b5..550d78fbbbb 100644 --- a/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -625,9 +625,9 @@ Bytecode::CodeGenerationErrorOr> AssignmentExpression::g if (expression.is_computed()) { if (!lhs_is_super_expression) - generator.emit(*base, *computed_property, rval, Bytecode::Op::PropertyKind::KeyValue, move(base_identifier)); + generator.emit_put_by_value(*base, *computed_property, rval, Bytecode::Op::PropertyKind::KeyValue, move(base_identifier)); else - generator.emit(*base, *computed_property, *this_value, rval); + generator.emit_put_by_value_with_this(*base, *computed_property, *this_value, rval, Op::PropertyKind::KeyValue); } else if (expression.property().is_identifier()) { auto identifier_table_ref = generator.intern_identifier(as(expression.property()).string()); if (!lhs_is_super_expression) @@ -1180,7 +1180,7 @@ Bytecode::CodeGenerationErrorOr> ObjectExpression::gener auto property_name = TRY(property->key().generate_bytecode(generator)).value(); auto value = TRY(property->value().generate_bytecode(generator)).value(); - generator.emit(object, property_name, value, property_kind); + generator.emit_put_by_value(object, property_name, value, property_kind, {}); } } diff --git a/Libraries/LibJS/Bytecode/Generator.cpp b/Libraries/LibJS/Bytecode/Generator.cpp index 518f3c06d51..4ce726fe7c4 100644 --- a/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Libraries/LibJS/Bytecode/Generator.cpp @@ -760,7 +760,7 @@ CodeGenerationErrorOr Generator::emit_store_to_reference(JS::ASTNode const if (super_reference.referenced_name.has_value()) { // 5. Let propertyKey be ? ToPropertyKey(propertyNameValue). // FIXME: This does ToPropertyKey out of order, which is observable by Symbol.toPrimitive! - emit(*super_reference.base, *super_reference.referenced_name, *super_reference.this_value, value); + emit_put_by_value_with_this(*super_reference.base, *super_reference.referenced_name, *super_reference.this_value, value, Op::PropertyKind::KeyValue); } else { // 3. Let propertyKey be StringValue of IdentifierName. auto identifier_table_ref = intern_identifier(as(expression.property()).string()); @@ -771,7 +771,7 @@ CodeGenerationErrorOr Generator::emit_store_to_reference(JS::ASTNode const if (expression.is_computed()) { auto property = TRY(expression.property().generate_bytecode(*this)).value(); - emit(object, property, value); + emit_put_by_value(object, property, value, Op::PropertyKind::KeyValue, {}); } else if (expression.property().is_identifier()) { auto identifier_table_ref = intern_identifier(as(expression.property()).string()); emit(object, identifier_table_ref, value, Bytecode::Op::PropertyKind::KeyValue, next_property_lookup_cache()); @@ -809,9 +809,9 @@ CodeGenerationErrorOr Generator::emit_store_to_reference(ReferenceOperands return {}; } if (reference.base == reference.this_value) - emit(*reference.base, *reference.referenced_name, value); + emit_put_by_value(*reference.base, *reference.referenced_name, value, Op::PropertyKind::KeyValue, {}); else - emit(*reference.base, *reference.referenced_name, *reference.this_value, value); + emit_put_by_value_with_this(*reference.base, *reference.referenced_name, *reference.this_value, value, Op::PropertyKind::KeyValue); return {}; } @@ -1146,6 +1146,30 @@ void Generator::emit_get_by_value_with_this(ScopedOperand dst, ScopedOperand bas emit(dst, base, property, this_value); } +void Generator::emit_put_by_value(ScopedOperand base, ScopedOperand property, ScopedOperand src, Bytecode::Op::PropertyKind kind, Optional base_identifier) +{ + if (property.operand().is_constant() && get_constant(property).is_string()) { + auto property_key = MUST(get_constant(property).to_property_key(vm())); + if (property_key.is_string()) { + emit(base, intern_identifier(property_key.as_string()), src, kind, m_next_property_lookup_cache++, base_identifier); + return; + } + } + emit(base, property, src, kind, base_identifier); +} + +void Generator::emit_put_by_value_with_this(ScopedOperand base, ScopedOperand property, ScopedOperand this_value, ScopedOperand src, Bytecode::Op::PropertyKind kind) +{ + if (property.operand().is_constant() && get_constant(property).is_string()) { + auto property_key = MUST(get_constant(property).to_property_key(vm())); + if (property_key.is_string()) { + emit(base, this_value, intern_identifier(property_key.as_string()), src, kind, m_next_property_lookup_cache++); + return; + } + } + emit(base, property, this_value, src, kind); +} + void Generator::emit_iterator_value(ScopedOperand dst, ScopedOperand result) { emit_get_by_id(dst, result, intern_identifier("value"_fly_string)); diff --git a/Libraries/LibJS/Bytecode/Generator.h b/Libraries/LibJS/Bytecode/Generator.h index ecba219c9c8..51b17d602c9 100644 --- a/Libraries/LibJS/Bytecode/Generator.h +++ b/Libraries/LibJS/Bytecode/Generator.h @@ -327,6 +327,9 @@ public: void emit_get_by_value(ScopedOperand dst, ScopedOperand base, ScopedOperand property, Optional base_identifier = {}); void emit_get_by_value_with_this(ScopedOperand dst, ScopedOperand base, ScopedOperand property, ScopedOperand this_value); + void emit_put_by_value(ScopedOperand base, ScopedOperand property, ScopedOperand src, Bytecode::Op::PropertyKind, Optional base_identifier); + void emit_put_by_value_with_this(ScopedOperand base, ScopedOperand property, ScopedOperand this_value, ScopedOperand src, Bytecode::Op::PropertyKind); + void emit_iterator_value(ScopedOperand dst, ScopedOperand result); void emit_iterator_complete(ScopedOperand dst, ScopedOperand result);