Browse Source

LibJS/JIT: Compile the DeleteByValueWithThis instruction

Jakub Berkop 1 year ago
parent
commit
6a7b9b85a4

+ 11 - 0
Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp

@@ -646,4 +646,15 @@ ThrowCompletionOr<Value> delete_by_value(Bytecode::Interpreter& interpreter, Val
     return Value(TRY(reference.delete_(vm)));
 }
 
+ThrowCompletionOr<Value> delete_by_value_with_this(Bytecode::Interpreter& interpreter, Value base, Value property_key_value, Value this_value)
+{
+    auto& vm = interpreter.vm();
+
+    auto property_key = TRY(property_key_value.to_property_key(vm));
+    bool strict = vm.in_strict_mode();
+    auto reference = Reference { base, property_key, this_value, strict };
+
+    return Value(TRY(reference.delete_(vm)));
+}
+
 }

+ 1 - 0
Userland/Libraries/LibJS/Bytecode/CommonImplementations.h

@@ -41,5 +41,6 @@ ThrowCompletionOr<NonnullGCPtr<Array>> iterator_to_array(VM&, Value iterator);
 ThrowCompletionOr<void> append(VM& vm, Value lhs, Value rhs, bool is_spread);
 ThrowCompletionOr<Value> delete_by_id(Bytecode::Interpreter&, Value base, IdentifierTableIndex identifier);
 ThrowCompletionOr<Value> delete_by_value(Bytecode::Interpreter&, Value base, Value property_key_value);
+ThrowCompletionOr<Value> delete_by_value_with_this(Bytecode::Interpreter&, Value base, Value property_key_value, Value this_value);
 
 }

+ 3 - 7
Userland/Libraries/LibJS/Bytecode/Interpreter.cpp

@@ -1117,16 +1117,12 @@ ThrowCompletionOr<void> DeleteByValue::execute_impl(Bytecode::Interpreter& inter
 
 ThrowCompletionOr<void> DeleteByValueWithThis::execute_impl(Bytecode::Interpreter& interpreter) const
 {
-    auto& vm = interpreter.vm();
-
     // NOTE: Get the property key from the accumulator before side effects have a chance to overwrite it.
     auto property_key_value = interpreter.accumulator();
-
     auto base_value = interpreter.reg(m_base);
-    auto property_key = TRY(property_key_value.to_property_key(vm));
-    bool strict = vm.in_strict_mode();
-    auto reference = Reference { base_value, property_key, interpreter.reg(m_this_value), strict };
-    interpreter.accumulator() = Value(TRY(reference.delete_(vm)));
+    auto this_value = interpreter.reg(m_this_value);
+    interpreter.accumulator() = TRY(delete_by_value_with_this(interpreter, base_value, property_key_value, this_value));
+
     return {};
 }
 

+ 3 - 0
Userland/Libraries/LibJS/Bytecode/Op.h

@@ -850,6 +850,9 @@ public:
     {
     }
 
+    Register base() const { return m_base; }
+    Register this_value() const { return m_this_value; }
+
     ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
     DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
 

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

@@ -1366,6 +1366,21 @@ void Compiler::compile_delete_by_value(Bytecode::Op::DeleteByValue const& op)
     check_exception();
 }
 
+static Value cxx_delete_by_value_with_this(VM& vm, Value base_value, Value property_key_value, Value this_value)
+{
+    return TRY_OR_SET_EXCEPTION(Bytecode::delete_by_value_with_this(vm.bytecode_interpreter(), base_value, property_key_value, this_value));
+}
+
+void Compiler::compile_delete_by_value_with_this(Bytecode::Op::DeleteByValueWithThis const& op)
+{
+    load_vm_register(ARG1, op.base());
+    load_vm_register(ARG2, Bytecode::Register::accumulator());
+    load_vm_register(ARG3, op.this_value());
+    native_call((void*)cxx_delete_by_value_with_this);
+    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

@@ -116,7 +116,8 @@ private:
         O(IteratorToArray, iterator_to_array)                                    \
         O(Append, append)                                                        \
         O(DeleteById, delete_by_id)                                              \
-        O(DeleteByValue, delete_by_value)
+        O(DeleteByValue, delete_by_value)                                        \
+        O(DeleteByValueWithThis, delete_by_value_with_this)
 
 #    define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \
         void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);