diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 205b8dee2f..4ef2ad6776 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -386,6 +386,19 @@ void Compiler::compile_get_by_id(Bytecode::Op::GetById const& op) check_exception(); } +static Value cxx_to_numeric(VM& vm, Value value) +{ + return TRY_OR_SET_EXCEPTION(value.to_numeric(vm)); +} + +void Compiler::compile_to_numeric(Bytecode::Op::ToNumeric const&) +{ + load_vm_register(ARG1, Bytecode::Register::accumulator()); + m_assembler.native_call((void*)cxx_to_numeric); + store_vm_register(Bytecode::Register::accumulator(), RET); + check_exception(); +} + OwnPtr Compiler::compile(Bytecode::Executable& bytecode_executable) { if (getenv("LIBJS_NO_JIT")) @@ -453,6 +466,9 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut case Bytecode::Instruction::Type::GetById: compiler.compile_get_by_id(static_cast(op)); break; + case Bytecode::Instruction::Type::ToNumeric: + compiler.compile_to_numeric(static_cast(op)); + break; #define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \ case Bytecode::Instruction::Type::TitleCaseName: \ diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 01c5ac15fb..e68336c06f 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -41,6 +41,7 @@ private: void compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const&); void compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext const&); void compile_throw(Bytecode::Op::Throw const&); + void compile_to_numeric(Bytecode::Op::ToNumeric const&); #define DO_COMPILE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);