Преглед на файлове

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.
Aliaksandr Kalenik преди 2 години
родител
ревизия
167495b87b
променени са 1 файла, в които са добавени 4 реда и са изтрити 1 реда
  1. 4 1
      Userland/Libraries/LibJS/Bytecode/Generator.cpp

+ 4 - 1
Userland/Libraries/LibJS/Bytecode/Generator.cpp

@@ -298,7 +298,10 @@ CodeGenerationErrorOr<void> Generator::emit_delete_reference(JS::ASTNode const&
 {
 {
     if (is<Identifier>(node)) {
     if (is<Identifier>(node)) {
         auto& identifier = static_cast<Identifier const&>(node);
         auto& identifier = static_cast<Identifier const&>(node);
-        emit<Bytecode::Op::DeleteVariable>(intern_identifier(identifier.string()));
+        if (identifier.is_local())
+            emit<Bytecode::Op::LoadImmediate>(Value(false));
+        else
+            emit<Bytecode::Op::DeleteVariable>(intern_identifier(identifier.string()));
         return {};
         return {};
     }
     }