1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibJS: Move logical not operator to new unary expression class

This commit is contained in:
0xtechnobabble 2020-03-09 19:04:44 +02:00 committed by Andreas Kling
parent 65343388b8
commit 5e817ee678
2 changed files with 7 additions and 22 deletions

View file

@ -210,17 +210,12 @@ Value LogicalExpression::execute(Interpreter& interpreter) const
{
auto lhs_result = m_lhs->execute(interpreter).as_bool();
if (m_op == LogicalOp::Not)
return Value(!lhs_result);
auto rhs_result = m_rhs->execute(interpreter).as_bool();
switch (m_op) {
case LogicalOp::And:
return Value(lhs_result && rhs_result);
case LogicalOp::Or:
return Value(lhs_result || rhs_result);
case LogicalOp::Not:
ASSERT_NOT_REACHED();
}
ASSERT_NOT_REACHED();
@ -232,6 +227,8 @@ Value UnaryExpression::execute(Interpreter& interpreter) const
switch (m_op) {
case UnaryOp::BitNot:
return bit_not(lhs_result);
case UnaryOp::Not:
return Value(!lhs_result.as_bool());
}
ASSERT_NOT_REACHED();
@ -313,14 +310,6 @@ void LogicalExpression::dump(int indent) const
case LogicalOp::Or:
op_string = "||";
break;
case LogicalOp::Not:
op_string = "!";
print_indent(indent);
printf("%s\n", class_name());
print_indent(indent + 1);
printf("%s\n", op_string);
m_lhs->dump(indent + 1);
return;
}
print_indent(indent);
@ -338,6 +327,9 @@ void UnaryExpression::dump(int indent) const
case UnaryOp::BitNot:
op_string = "~";
break;
case UnaryOp::Not:
op_string = "!";
break;
}
print_indent(indent);