mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 19:04:58 +00:00
LibJS: Implement nullish coalescing operator (??)
This commit is contained in:
committed by
Andreas Kling
parent
1806592d58
commit
d14ddb6461
@@ -338,20 +338,25 @@ Value LogicalExpression::execute(Interpreter& interpreter) const
|
||||
auto rhs_result = m_rhs->execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
||||
return Value(rhs_result);
|
||||
return rhs_result;
|
||||
}
|
||||
|
||||
return Value(lhs_result);
|
||||
case LogicalOp::Or:
|
||||
return lhs_result;
|
||||
case LogicalOp::Or: {
|
||||
if (lhs_result.to_boolean())
|
||||
return Value(lhs_result);
|
||||
|
||||
return lhs_result;
|
||||
auto rhs_result = m_rhs->execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
||||
return Value(rhs_result);
|
||||
return rhs_result;
|
||||
}
|
||||
case LogicalOp::NullishCoalescing:
|
||||
if (lhs_result.is_null() || lhs_result.is_undefined()) {
|
||||
auto rhs_result = m_rhs->execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
return rhs_result;
|
||||
}
|
||||
return lhs_result;
|
||||
}
|
||||
|
||||
ASSERT_NOT_REACHED();
|
||||
@@ -515,6 +520,9 @@ void LogicalExpression::dump(int indent) const
|
||||
case LogicalOp::Or:
|
||||
op_string = "||";
|
||||
break;
|
||||
case LogicalOp::NullishCoalescing:
|
||||
op_string = "??";
|
||||
break;
|
||||
}
|
||||
|
||||
print_indent(indent);
|
||||
|
||||
Reference in New Issue
Block a user