From a2b01546616c1cb6d6c0c1c2216a9f0ce9b9f057 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Mon, 30 Oct 2023 02:17:24 +0100 Subject: [PATCH] LibJS/JIT: Compile the AsyncIteratorClose instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 3 +++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 23 +++++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 3 ++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 3c145f20b0..7a67528c1b 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -1411,6 +1411,9 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + Completion::Type completion_type() const { return m_completion_type; } + Optional const& completion_value() const { return m_completion_value; } + private: Completion::Type m_completion_type { Completion::Type::Normal }; Optional m_completion_value; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index ca675abbb1..a535fd9885 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1717,6 +1717,29 @@ void Compiler::compile_copy_object_excluding_properties(Bytecode::Op::CopyObject check_exception(); } +static Value cxx_async_iterator_close(VM& vm, Value iterator, Completion::Type completion_type, Optional const& completion_value) +{ + auto iterator_object = TRY_OR_SET_EXCEPTION(iterator.to_object(vm)); + auto iterator_record = Bytecode::object_to_iterator(vm, iterator_object); + + // FIXME: Return the value of the resulting completion. (Note that completion_value can be empty!) + TRY_OR_SET_EXCEPTION(async_iterator_close(vm, iterator_record, Completion { completion_type, completion_value, {} })); + return {}; +} + +void Compiler::compile_async_iterator_close(Bytecode::Op::AsyncIteratorClose const& op) +{ + load_vm_register(ARG1, Bytecode::Register::accumulator()); + m_assembler.mov( + Assembler::Operand::Register(ARG2), + Assembler::Operand::Imm(to_underlying(op.completion_type()))); + m_assembler.mov( + Assembler::Operand::Register(ARG3), + Assembler::Operand::Imm(bit_cast(&op.completion_value()))); + native_call((void*)cxx_async_iterator_close); + check_exception(); +} + void Compiler::jump_to_exit() { m_assembler.jump(m_exit_label); diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 367debf903..fb21624ec5 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -139,7 +139,8 @@ private: O(GetNewTarget, get_new_target) \ O(HasPrivateId, has_private_id) \ O(PutByValueWithThis, put_by_value_with_this) \ - O(CopyObjectExcludingProperties, copy_object_excluding_properties) + O(CopyObjectExcludingProperties, copy_object_excluding_properties) \ + O(AsyncIteratorClose, async_iterator_close) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case, ...) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);