LibJS: Fix bytecode generation for super property stores and loads

The new test case crashes during bytecode generation due to
`emit_super_reference` not correctly generating the reference record
for the property access.
This commit is contained in:
Jess 2025-02-13 22:10:58 +13:00 committed by Tim Flynn
parent 778947213b
commit 356728b1e0
Notes: github-actions[bot] 2025-02-15 12:01:01 +00:00
2 changed files with 17 additions and 0 deletions

View file

@ -607,12 +607,18 @@ CodeGenerationErrorOr<Generator::ReferenceOperands> Generator::emit_super_refere
auto actual_this = get_this();
Optional<ScopedOperand> computed_property_value;
Optional<IdentifierTableIndex> property_key_id;
if (expression.is_computed()) {
// SuperProperty : super [ Expression ]
// 3. Let propertyNameReference be ? Evaluation of Expression.
// 4. Let propertyNameValue be ? GetValue(propertyNameReference).
computed_property_value = TRY(expression.property().generate_bytecode(*this)).value();
} else {
// SuperProperty : super . IdentifierName
// 3. Let propertyKey be the StringValue of IdentifierName.
auto const identifier_name = as<Identifier>(expression.property()).string();
property_key_id = intern_identifier(identifier_name);
}
// 5/7. Return ? MakeSuperPropertyReference(actualThis, propertyKey, strict).
@ -628,6 +634,7 @@ CodeGenerationErrorOr<Generator::ReferenceOperands> Generator::emit_super_refere
return ReferenceOperands {
.base = base_value,
.referenced_name = computed_property_value,
.referenced_identifier = property_key_id,
.this_value = actual_this,
};
}

View file

@ -181,6 +181,16 @@ test("Issue #7044, super property access before super() call", () => {
new Foo();
});
test("super property load and store by identifier", () => {
class Foo {
constructor() {
super.bar += "1337";
}
}
new Foo();
});
test("Issue #8574, super property access before super() call", () => {
var hit = false;