From 5947c37637f8ea3d4c323a04e5e5dfe9fad5a4d7 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 13 Dec 2024 11:50:55 -0500 Subject: [PATCH] LibJS: Return the allocated dst register from deleting super properties Even though calling delete on a super property will ultimately throw a ReferenceError, we must return the allocated register for the result of the delete operation (which would normally be a boolean). If the delete operation is used in a return statement, the bytecode generator for the return statement must be able to assume the statement had some output. --- Libraries/LibJS/Bytecode/Generator.cpp | 2 +- Libraries/LibJS/Tests/operators/delete-basic.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Libraries/LibJS/Bytecode/Generator.cpp b/Libraries/LibJS/Bytecode/Generator.cpp index f4c99673a1c..dcd7b04efa4 100644 --- a/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Libraries/LibJS/Bytecode/Generator.cpp @@ -812,7 +812,7 @@ CodeGenerationErrorOr> Generator::emit_delete_reference( emit(dst, *super_reference.base, *super_reference.this_value, identifier_table_ref); } - return Optional {}; + return dst; } auto object = TRY(expression.object().generate_bytecode(*this)).value(); diff --git a/Libraries/LibJS/Tests/operators/delete-basic.js b/Libraries/LibJS/Tests/operators/delete-basic.js index f41269c5fc9..fc6d58b057a 100644 --- a/Libraries/LibJS/Tests/operators/delete-basic.js +++ b/Libraries/LibJS/Tests/operators/delete-basic.js @@ -93,6 +93,13 @@ test("deleting super property", () => { } } + class D { + static foo() { + const deleter = () => delete super.foo; + deleter(); + } + } + const obj = new B(); expect(() => { obj.bar(); @@ -106,6 +113,10 @@ test("deleting super property", () => { expect(() => { C.foo(); }).toThrowWithMessage(ReferenceError, "Can't delete a property on 'super'"); + + expect(() => { + D.foo(); + }).toThrowWithMessage(ReferenceError, "Can't delete a property on 'super'"); }); test("deleting an object computed property coerces the object to a property key", () => {