From 847889343f0ea3cc1189b3bcf264b2c81d960750 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Mon, 30 Oct 2023 01:12:58 +0100 Subject: [PATCH] LibJS/JIT: Compile the New##ErrorName instructions --- Userland/Libraries/LibJS/Bytecode/Op.h | 2 ++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 19 ++++++++++++++++++- Userland/Libraries/LibJS/JIT/Compiler.h | 6 +++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 8eee7b7c11..f93dfc511f 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -212,6 +212,8 @@ private: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; \ DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \ \ + StringTableIndex error_string() const { return m_error_string; } \ + \ private: \ StringTableIndex m_error_string; \ }; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 5985fc9ca1..714b491a89 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1635,6 +1635,23 @@ void Compiler::compile_has_private_id(Bytecode::Op::HasPrivateId const& op) check_exception(); } +# define COMPILE_NEW_BUILTIN_ERROR_OP(NewErrorName, new_error_name, ErrorName) \ + static Value cxx_##new_error_name(VM& vm, DeprecatedString const& error_string) \ + { \ + return ErrorName::create(*vm.current_realm(), error_string); \ + } \ + \ + void Compiler::compile_##new_error_name(Bytecode::Op::NewErrorName const& op) \ + { \ + m_assembler.mov( \ + Assembler::Operand::Register(ARG1), \ + Assembler::Operand::Imm(bit_cast(&m_bytecode_executable.get_string(op.error_string())))); \ + native_call((void*)cxx_##new_error_name); \ + store_vm_register(Bytecode::Register::accumulator(), RET); \ + } +JS_ENUMERATE_NEW_BUILTIN_ERROR_BYTECODE_OPS(COMPILE_NEW_BUILTIN_ERROR_OP) +# undef COMPILE_NEW_BUILTIN_ERROR_OP + void Compiler::jump_to_exit() { m_assembler.jump(m_exit_label); @@ -1684,7 +1701,7 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut while (!it.at_end()) { auto const& op = *it; switch (op.type()) { -# define CASE_BYTECODE_OP(OpTitleCase, op_snake_case) \ +# define CASE_BYTECODE_OP(OpTitleCase, op_snake_case, ...) \ case Bytecode::Instruction::Type::OpTitleCase: \ compiler.compile_##op_snake_case(static_cast(op)); \ break; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index d21902af3b..7f9ff10680 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -62,9 +62,13 @@ private: O(RightShift, right_shift) \ O(UnsignedRightShift, unsigned_right_shift) +# define JS_ENUMERATE_NEW_BUILTIN_ERROR_BYTECODE_OPS(O) \ + O(NewTypeError, new_type_error, TypeError) + # define JS_ENUMERATE_IMPLEMENTED_JIT_OPS(O) \ JS_ENUMERATE_COMMON_BINARY_OPS(O) \ JS_ENUMERATE_COMMON_UNARY_OPS(O) \ + JS_ENUMERATE_NEW_BUILTIN_ERROR_BYTECODE_OPS(O) \ O(LoadImmediate, load_immediate) \ O(Load, load) \ O(Store, store) \ @@ -135,7 +139,7 @@ private: O(GetNewTarget, get_new_target) \ O(HasPrivateId, has_private_id) -# define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \ +# define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case, ...) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&); JS_ENUMERATE_IMPLEMENTED_JIT_OPS(DECLARE_COMPILE_OP)