mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08:10 +00:00
Shell: Allow builtins and functions as conditions for 'if'
This commit is contained in:
parent
2b867ff555
commit
cd0ddf27f3
2 changed files with 12 additions and 13 deletions
|
@ -1209,16 +1209,16 @@ void IfCond::dump(int level) const
|
||||||
RefPtr<Value> IfCond::run(RefPtr<Shell> shell)
|
RefPtr<Value> IfCond::run(RefPtr<Shell> shell)
|
||||||
{
|
{
|
||||||
auto cond = m_condition->run(shell)->resolve_without_cast(shell);
|
auto cond = m_condition->run(shell)->resolve_without_cast(shell);
|
||||||
ASSERT(cond->is_job());
|
// The condition could be a builtin, in which case it has already run and exited.
|
||||||
|
if (cond && cond->is_job()) {
|
||||||
|
auto cond_job_value = static_cast<const JobValue*>(cond.ptr());
|
||||||
|
auto cond_job = cond_job_value->job();
|
||||||
|
|
||||||
auto cond_job_value = static_cast<const JobValue*>(cond.ptr());
|
shell->block_on_job(cond_job);
|
||||||
auto cond_job = cond_job_value->job();
|
|
||||||
|
|
||||||
shell->block_on_job(cond_job);
|
|
||||||
|
|
||||||
if (cond_job->signaled())
|
|
||||||
return create<ListValue>({}); // Exit early.
|
|
||||||
|
|
||||||
|
if (cond_job->signaled())
|
||||||
|
return create<ListValue>({}); // Exit early.
|
||||||
|
}
|
||||||
if (shell->last_return_code == 0) {
|
if (shell->last_return_code == 0) {
|
||||||
if (m_true_branch)
|
if (m_true_branch)
|
||||||
return m_true_branch->run(shell);
|
return m_true_branch->run(shell);
|
||||||
|
|
|
@ -591,10 +591,9 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int retval = 0;
|
if (run_builtin(command, rewirings, last_return_code)) {
|
||||||
if (run_builtin(command, rewirings, retval)) {
|
|
||||||
for (auto& next_in_chain : command.next_chain)
|
for (auto& next_in_chain : command.next_chain)
|
||||||
run_tail(next_in_chain, retval);
|
run_tail(next_in_chain, last_return_code);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,9 +609,9 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invoke_function(command, retval)) {
|
if (invoke_function(command, last_return_code)) {
|
||||||
for (auto& next_in_chain : command.next_chain)
|
for (auto& next_in_chain : command.next_chain)
|
||||||
run_tail(next_in_chain, retval);
|
run_tail(next_in_chain, last_return_code);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue