mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-04 17:33:04 +00:00
LibJS: Implement nullish coalescing operator (??)
This commit is contained in:
parent
1806592d58
commit
d14ddb6461
Notes:
sideshowbarker
2024-07-19 07:31:09 +09:00
Author: https://github.com/linusg
Commit: d14ddb6461
Pull-request: https://github.com/SerenityOS/serenity/pull/1832
Reviewed-by: https://github.com/awesomekling
4 changed files with 60 additions and 12 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue