Skip to content

Commit 167495b

Browse files
kalenikaliaksandrawesomekling
authored andcommitted
LibJS/Bytecode: Always return false on attempt to delete local variable
Since it is not possible for delete operator to return true when it is applied to local variable, DeleteVariable can safely always return false for locals. This also fixes operators/delete-local-variable.js in test-js.
1 parent 0c5c75e commit 167495b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Userland/Libraries/LibJS/Bytecode/Generator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ CodeGenerationErrorOr<void> Generator::emit_delete_reference(JS::ASTNode const&
298298
{
299299
if (is<Identifier>(node)) {
300300
auto& identifier = static_cast<Identifier const&>(node);
301-
emit<Bytecode::Op::DeleteVariable>(intern_identifier(identifier.string()));
301+
if (identifier.is_local())
302+
emit<Bytecode::Op::LoadImmediate>(Value(false));
303+
else
304+
emit<Bytecode::Op::DeleteVariable>(intern_identifier(identifier.string()));
302305
return {};
303306
}
304307

0 commit comments

Comments
 (0)