mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Shell: Make Subshell actually create a subshell
Previously, a "subshell" would just be executed in the parent shell.
This commit is contained in:
parent
72bd672da0
commit
4668dfa7c7
Notes:
sideshowbarker
2024-07-19 00:48:24 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/4668dfa7c70 Pull-request: https://github.com/SerenityOS/serenity/pull/4415
3 changed files with 4 additions and 21 deletions
|
@ -2055,27 +2055,11 @@ void Sequence::dump(int level) const
|
|||
|
||||
RefPtr<Value> Sequence::run(RefPtr<Shell> shell)
|
||||
{
|
||||
// If we are to return a job, block on the left one then return the right one.
|
||||
if (would_execute()) {
|
||||
RefPtr<AST::Node> execute_node = create<AST::Execute>(m_left->position(), m_left);
|
||||
auto left_value = execute_node->run(shell);
|
||||
// Some nodes are inherently empty, such as Comments and For loops without bodies,
|
||||
// it is not an error for the value not to be a job.
|
||||
if (left_value && left_value->is_job())
|
||||
shell->block_on_job(static_cast<JobValue*>(left_value.ptr())->job());
|
||||
|
||||
if (m_right->would_execute())
|
||||
return m_right->run(shell);
|
||||
|
||||
execute_node = create<AST::Execute>(m_right->position(), m_right);
|
||||
return execute_node->run(shell);
|
||||
}
|
||||
|
||||
auto left = m_left->to_lazy_evaluated_commands(shell);
|
||||
// This could happen if a comment is next to a command.
|
||||
if (left.size() == 1) {
|
||||
auto& command = left.first();
|
||||
if (command.argv.is_empty() && command.redirections.is_empty())
|
||||
if (command.argv.is_empty() && command.redirections.is_empty() && command.next_chain.is_empty())
|
||||
return m_right->run(shell);
|
||||
}
|
||||
|
||||
|
@ -2139,7 +2123,7 @@ RefPtr<Value> Subshell::run(RefPtr<Shell> shell)
|
|||
if (!m_block)
|
||||
return create<ListValue>({});
|
||||
|
||||
return m_block->run(shell);
|
||||
return create<AST::CommandSequenceValue>(m_block->to_lazy_evaluated_commands(shell));
|
||||
}
|
||||
|
||||
void Subshell::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
|
|
@ -1050,7 +1050,6 @@ private:
|
|||
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
||||
virtual HitTestResult hit_test_position(size_t) override;
|
||||
virtual bool is_list() const override { return true; }
|
||||
virtual bool would_execute() const override { return m_left->would_execute() || m_right->would_execute(); }
|
||||
|
||||
NonnullRefPtr<Node> m_left;
|
||||
NonnullRefPtr<Node> m_right;
|
||||
|
@ -1071,7 +1070,7 @@ private:
|
|||
virtual RefPtr<Value> run(RefPtr<Shell>) override;
|
||||
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
||||
virtual HitTestResult hit_test_position(size_t) override;
|
||||
virtual bool would_execute() const override { return true; }
|
||||
virtual bool would_execute() const override { return false; }
|
||||
|
||||
RefPtr<AST::Node> m_block;
|
||||
};
|
||||
|
|
|
@ -693,7 +693,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto can_be_run_in_current_process = command.should_wait && !command.pipeline;
|
||||
auto can_be_run_in_current_process = command.should_wait && !command.pipeline && !command.argv.is_empty();
|
||||
if (can_be_run_in_current_process && has_function(command.argv.first())) {
|
||||
SavedFileDescriptors fds { rewirings };
|
||||
|
||||
|
|
Loading…
Reference in a new issue