diff --git a/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 14ab23641be..6763d2118dc 100644 --- a/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -113,13 +113,13 @@ static ThrowCompletionOr constant_fold_binary_expression(Generato case BinaryOp::Exponentiation: return generator.add_constant(TRY(exp(generator.vm(), lhs, rhs))); case BinaryOp::GreaterThan: - return generator.add_constant(TRY(greater_than(generator.vm(), lhs, rhs))); + return generator.add_constant(Value { TRY(greater_than(generator.vm(), lhs, rhs)) }); case BinaryOp::GreaterThanEquals: - return generator.add_constant(TRY(greater_than_equals(generator.vm(), lhs, rhs))); + return generator.add_constant(Value { TRY(greater_than_equals(generator.vm(), lhs, rhs)) }); case BinaryOp::LessThan: - return generator.add_constant(TRY(less_than(generator.vm(), lhs, rhs))); + return generator.add_constant(Value { TRY(less_than(generator.vm(), lhs, rhs)) }); case BinaryOp::LessThanEquals: - return generator.add_constant(TRY(less_than_equals(generator.vm(), lhs, rhs))); + return generator.add_constant(Value { TRY(less_than_equals(generator.vm(), lhs, rhs)) }); case BinaryOp::LooselyInequals: return generator.add_constant(Value(!TRY(is_loosely_equal(generator.vm(), lhs, rhs)))); case BinaryOp::LooselyEquals: diff --git a/Libraries/LibJS/Bytecode/Interpreter.cpp b/Libraries/LibJS/Bytecode/Interpreter.cpp index 84009b9dc91..23ee67ce3dc 100644 --- a/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -142,40 +142,40 @@ static ByteString format_value_list(StringView name, ReadonlySpan values) return builder.to_byte_string(); } -ALWAYS_INLINE static ThrowCompletionOr loosely_inequals(VM& vm, Value src1, Value src2) +ALWAYS_INLINE static ThrowCompletionOr loosely_inequals(VM& vm, Value src1, Value src2) { if (src1.tag() == src2.tag()) { if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish()) - return Value(src1.encoded() != src2.encoded()); + return src1.encoded() != src2.encoded(); } - return Value(!TRY(is_loosely_equal(vm, src1, src2))); + return !TRY(is_loosely_equal(vm, src1, src2)); } -ALWAYS_INLINE static ThrowCompletionOr loosely_equals(VM& vm, Value src1, Value src2) +ALWAYS_INLINE static ThrowCompletionOr loosely_equals(VM& vm, Value src1, Value src2) { if (src1.tag() == src2.tag()) { if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish()) - return Value(src1.encoded() == src2.encoded()); + return src1.encoded() == src2.encoded(); } - return Value(TRY(is_loosely_equal(vm, src1, src2))); + return TRY(is_loosely_equal(vm, src1, src2)); } -ALWAYS_INLINE static ThrowCompletionOr strict_inequals(VM&, Value src1, Value src2) +ALWAYS_INLINE static ThrowCompletionOr strict_inequals(VM&, Value src1, Value src2) { if (src1.tag() == src2.tag()) { if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish()) - return Value(src1.encoded() != src2.encoded()); + return src1.encoded() != src2.encoded(); } - return Value(!is_strictly_equal(src1, src2)); + return !is_strictly_equal(src1, src2); } -ALWAYS_INLINE static ThrowCompletionOr strict_equals(VM&, Value src1, Value src2) +ALWAYS_INLINE static ThrowCompletionOr strict_equals(VM&, Value src1, Value src2) { if (src1.tag() == src2.tag()) { if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish()) - return Value(src1.encoded() == src2.encoded()); + return src1.encoded() == src2.encoded(); } - return Value(is_strictly_equal(src1, src2)); + return is_strictly_equal(src1, src2); } Interpreter::Interpreter(VM& vm) @@ -486,7 +486,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point) return; \ goto start; \ } \ - if (result.value().to_boolean()) \ + if (result.value()) \ program_counter = instruction.true_target().address(); \ else \ program_counter = instruction.false_target().address(); \ @@ -1932,7 +1932,7 @@ void Dump::execute_impl(Bytecode::Interpreter& interpreter) const auto& vm = interpreter.vm(); \ auto lhs = interpreter.get(m_lhs); \ auto rhs = interpreter.get(m_rhs); \ - interpreter.set(m_dst, TRY(op_snake_case(vm, lhs, rhs))); \ + interpreter.set(m_dst, Value { TRY(op_snake_case(vm, lhs, rhs)) }); \ return {}; \ } @@ -2106,7 +2106,7 @@ ThrowCompletionOr LessThan::execute_impl(Bytecode::Interpreter& interprete interpreter.set(m_dst, Value(lhs.as_double() < rhs.as_double())); return {}; } - interpreter.set(m_dst, TRY(less_than(vm, lhs, rhs))); + interpreter.set(m_dst, Value { TRY(less_than(vm, lhs, rhs)) }); return {}; } @@ -2123,7 +2123,7 @@ ThrowCompletionOr LessThanEquals::execute_impl(Bytecode::Interpreter& inte interpreter.set(m_dst, Value(lhs.as_double() <= rhs.as_double())); return {}; } - interpreter.set(m_dst, TRY(less_than_equals(vm, lhs, rhs))); + interpreter.set(m_dst, Value { TRY(less_than_equals(vm, lhs, rhs)) }); return {}; } @@ -2140,7 +2140,7 @@ ThrowCompletionOr GreaterThan::execute_impl(Bytecode::Interpreter& interpr interpreter.set(m_dst, Value(lhs.as_double() > rhs.as_double())); return {}; } - interpreter.set(m_dst, TRY(greater_than(vm, lhs, rhs))); + interpreter.set(m_dst, Value { TRY(greater_than(vm, lhs, rhs)) }); return {}; } @@ -2157,7 +2157,7 @@ ThrowCompletionOr GreaterThanEquals::execute_impl(Bytecode::Interpreter& i interpreter.set(m_dst, Value(lhs.as_double() >= rhs.as_double())); return {}; } - interpreter.set(m_dst, TRY(greater_than_equals(vm, lhs, rhs))); + interpreter.set(m_dst, Value { TRY(greater_than_equals(vm, lhs, rhs)) }); return {}; } diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 918c9ccd02c..427d03ef88c 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -1261,7 +1261,7 @@ ThrowCompletionOr> Value::get_method(VM& vm, PropertyKey // 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators // RelationalExpression : RelationalExpression > ShiftExpression -ThrowCompletionOr greater_than(VM& vm, Value lhs, Value rhs) +ThrowCompletionOr greater_than(VM& vm, Value lhs, Value rhs) { // 1. Let lref be ? Evaluation of RelationalExpression. // 2. Let lval be ? GetValue(lref). @@ -1278,13 +1278,13 @@ ThrowCompletionOr greater_than(VM& vm, Value lhs, Value rhs) // 6. If r is undefined, return false. Otherwise, return r. if (relation == TriState::Unknown) - return Value(false); - return Value(relation == TriState::True); + return false; + return relation == TriState::True; } // 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators // RelationalExpression : RelationalExpression >= ShiftExpression -ThrowCompletionOr greater_than_equals(VM& vm, Value lhs, Value rhs) +ThrowCompletionOr greater_than_equals(VM& vm, Value lhs, Value rhs) { // 1. Let lref be ? Evaluation of RelationalExpression. // 2. Let lval be ? GetValue(lref). @@ -1301,13 +1301,13 @@ ThrowCompletionOr greater_than_equals(VM& vm, Value lhs, Value rhs) // 6. If r is true or undefined, return false. Otherwise, return true. if (relation == TriState::Unknown || relation == TriState::True) - return Value(false); - return Value(true); + return false; + return true; } // 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators // RelationalExpression : RelationalExpression < ShiftExpression -ThrowCompletionOr less_than(VM& vm, Value lhs, Value rhs) +ThrowCompletionOr less_than(VM& vm, Value lhs, Value rhs) { // 1. Let lref be ? Evaluation of RelationalExpression. // 2. Let lval be ? GetValue(lref). @@ -1324,13 +1324,13 @@ ThrowCompletionOr less_than(VM& vm, Value lhs, Value rhs) // 6. If r is undefined, return false. Otherwise, return r. if (relation == TriState::Unknown) - return Value(false); - return Value(relation == TriState::True); + return false; + return relation == TriState::True; } // 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators // RelationalExpression : RelationalExpression <= ShiftExpression -ThrowCompletionOr less_than_equals(VM& vm, Value lhs, Value rhs) +ThrowCompletionOr less_than_equals(VM& vm, Value lhs, Value rhs) { // 1. Let lref be ? Evaluation of RelationalExpression. // 2. Let lval be ? GetValue(lref). @@ -1347,8 +1347,8 @@ ThrowCompletionOr less_than_equals(VM& vm, Value lhs, Value rhs) // 6. If r is true or undefined, return false. Otherwise, return true. if (relation == TriState::True || relation == TriState::Unknown) - return Value(false); - return Value(true); + return false; + return true; } // 13.12 Binary Bitwise Operators, https://tc39.es/ecma262/#sec-binary-bitwise-operators diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.h index 91795c86199..7e22d96cbc3 100644 --- a/Libraries/LibJS/Runtime/Value.h +++ b/Libraries/LibJS/Runtime/Value.h @@ -461,10 +461,10 @@ private: friend constexpr Value js_undefined(); friend constexpr Value js_null(); friend constexpr Value js_special_empty_value(); - friend ThrowCompletionOr greater_than(VM&, Value lhs, Value rhs); - friend ThrowCompletionOr greater_than_equals(VM&, Value lhs, Value rhs); - friend ThrowCompletionOr less_than(VM&, Value lhs, Value rhs); - friend ThrowCompletionOr less_than_equals(VM&, Value lhs, Value rhs); + friend ThrowCompletionOr greater_than(VM&, Value lhs, Value rhs); + friend ThrowCompletionOr greater_than_equals(VM&, Value lhs, Value rhs); + friend ThrowCompletionOr less_than(VM&, Value lhs, Value rhs); + friend ThrowCompletionOr less_than_equals(VM&, Value lhs, Value rhs); friend ThrowCompletionOr add(VM&, Value lhs, Value rhs); friend bool same_value_non_number(Value lhs, Value rhs); }; @@ -499,10 +499,10 @@ inline Value js_negative_infinity() return Value(-INFINITY); } -ThrowCompletionOr greater_than(VM&, Value lhs, Value rhs); -ThrowCompletionOr greater_than_equals(VM&, Value lhs, Value rhs); -ThrowCompletionOr less_than(VM&, Value lhs, Value rhs); -ThrowCompletionOr less_than_equals(VM&, Value lhs, Value rhs); +ThrowCompletionOr greater_than(VM&, Value lhs, Value rhs); +ThrowCompletionOr greater_than_equals(VM&, Value lhs, Value rhs); +ThrowCompletionOr less_than(VM&, Value lhs, Value rhs); +ThrowCompletionOr less_than_equals(VM&, Value lhs, Value rhs); ThrowCompletionOr bitwise_and(VM&, Value lhs, Value rhs); ThrowCompletionOr bitwise_or(VM&, Value lhs, Value rhs); ThrowCompletionOr bitwise_xor(VM&, Value lhs, Value rhs);