Просмотр исходного кода

LibJS/JIT: Compile the DeleteVariable instruction

Simon Wanner 1 год назад
Родитель
Сommit
06ea4cfc4f
2 измененных файлов с 18 добавлено и 1 удалено
  1. 16 0
      Userland/Libraries/LibJS/JIT/Compiler.cpp
  2. 2 1
      Userland/Libraries/LibJS/JIT/Compiler.h

+ 16 - 0
Userland/Libraries/LibJS/JIT/Compiler.cpp

@@ -1552,6 +1552,22 @@ void Compiler::compile_get_import_meta(Bytecode::Op::GetImportMeta const&)
     store_vm_register(Bytecode::Register::accumulator(), RET);
 }
 
+static Value cxx_delete_variable(VM& vm, DeprecatedFlyString const& identifier)
+{
+    auto reference = TRY_OR_SET_EXCEPTION(vm.resolve_binding(identifier));
+    return Value(TRY_OR_SET_EXCEPTION(reference.delete_(vm)));
+}
+
+void Compiler::compile_delete_variable(Bytecode::Op::DeleteVariable const& op)
+{
+    m_assembler.mov(
+        Assembler::Operand::Register(ARG1),
+        Assembler::Operand::Imm(bit_cast<u64>(&m_bytecode_executable.get_identifier(op.identifier().value()))));
+    native_call((void*)cxx_delete_variable);
+    store_vm_register(Bytecode::Register::accumulator(), RET);
+    check_exception();
+}
+
 void Compiler::jump_to_exit()
 {
     m_assembler.jump(m_exit_label);

+ 2 - 1
Userland/Libraries/LibJS/JIT/Compiler.h

@@ -128,7 +128,8 @@ private:
         O(PutByIdWithThis, put_by_id_with_this)                                  \
         O(PutPrivateById, put_private_by_id)                                     \
         O(ImportCall, import_call)                                               \
-        O(GetImportMeta, get_import_meta)
+        O(GetImportMeta, get_import_meta)                                        \
+        O(DeleteVariable, delete_variable)
 
 #    define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \
         void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);