From e2f5bfb4c43bc08d5bea7b445f5f35a262cf9584 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 27 Oct 2023 11:12:52 +0200 Subject: [PATCH] LibJS/JIT: Always mask everything but LSB in ToBoolean As it turns out, cxx_to_boolean() may return "bool" as other values than just 0 or 1. This happens when the C++ compiler decides to only update the AL portion of the RAX return value register instead of the whole thing. --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index e374f35d49..882b0abda6 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -127,11 +127,6 @@ void Compiler::compile_to_boolean(Assembler::Reg dst, Assembler::Reg src) Assembler::Operand::Register(dst), Assembler::Operand::Register(src)); - // dst &= 1; - m_assembler.bitwise_and( - Assembler::Operand::Register(dst), - Assembler::Operand::Imm32(1)); - // goto end; auto end = m_assembler.jump(); @@ -147,6 +142,11 @@ void Compiler::compile_to_boolean(Assembler::Reg dst, Assembler::Reg src) // end: end.link(m_assembler); + + // dst &= 1; + m_assembler.bitwise_and( + Assembler::Operand::Register(dst), + Assembler::Operand::Imm32(1)); } void Compiler::compile_jump_conditional(Bytecode::Op::JumpConditional const& op)