1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 18:55:07 +00:00

LibJS: Implement logical assignment operators (&&=, ||=, ??=)

TC39 proposal, stage 4 as of 2020-07.
https://tc39.es/proposal-logical-assignment/
This commit is contained in:
Linus Groh 2020-10-05 16:49:43 +01:00 committed by Andreas Kling
parent d8d00d3ac7
commit aa71dae03c
6 changed files with 108 additions and 6 deletions

View file

@ -1261,6 +1261,30 @@ Value AssignmentExpression::execute(Interpreter& interpreter, GlobalObject& glob
EXECUTE_LHS_AND_RHS();
rhs_result = unsigned_right_shift(global_object, lhs_result, rhs_result);
break;
case AssignmentOp::AndAssignment:
lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception())
return {};
if (!lhs_result.to_boolean())
return lhs_result;
rhs_result = m_rhs->execute(interpreter, global_object);
break;
case AssignmentOp::OrAssignment:
lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception())
return {};
if (lhs_result.to_boolean())
return lhs_result;
rhs_result = m_rhs->execute(interpreter, global_object);
break;
case AssignmentOp::NullishAssignment:
lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception())
return {};
if (!lhs_result.is_nullish())
return lhs_result;
rhs_result = m_rhs->execute(interpreter, global_object);
break;
}
if (interpreter.exception())
return {};
@ -1366,6 +1390,15 @@ void AssignmentExpression::dump(int indent) const
case AssignmentOp::UnsignedRightShiftAssignment:
op_string = ">>>=";
break;
case AssignmentOp::AndAssignment:
op_string = "&&=";
break;
case AssignmentOp::OrAssignment:
op_string = "||=";
break;
case AssignmentOp::NullishAssignment:
op_string = "\?\?=";
break;
}
ASTNode::dump(indent);