diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-01-06 16:23:28 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-06 15:40:45 +0100 |
commit | 335221d830d158620fd8212ef48281e488169d67 (patch) | |
tree | 0f505e05f54b858cb450344510ef7daa1017bef8 | |
parent | 81c5b35dce06313766162ec6a5dc02ec44528f9f (diff) | |
download | serenity-335221d830d158620fd8212ef48281e488169d67.zip |
Shell: Run function declarations in the current process
Fixes #4817
-rw-r--r-- | Shell/AST.h | 2 | ||||
-rw-r--r-- | Shell/Shell.cpp | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Shell/AST.h b/Shell/AST.h index 21eff815a3..713f604340 100644 --- a/Shell/AST.h +++ b/Shell/AST.h @@ -429,6 +429,7 @@ public: virtual bool is_list() const { return false; } virtual bool would_execute() const { return false; } + virtual bool should_override_execution_in_current_process() const { return false; } const Position& position() const { return m_position; } void set_is_syntax_error(const SyntaxError& error_node) @@ -829,6 +830,7 @@ private: virtual HitTestResult hit_test_position(size_t) override; virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, const HitTestResult&) override; virtual bool would_execute() const override { return true; } + virtual bool should_override_execution_in_current_process() const override { return true; } NameWithPosition m_name; Vector<NameWithPosition> m_arguments; diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index c70b982413..0bc877ce58 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -729,6 +729,12 @@ RefPtr<Job> Shell::run_command(const AST::Command& command) } } + if (command.argv.is_empty() && !command.next_chain.is_empty() && command.should_immediately_execute_next && command.next_chain.first().node->should_override_execution_in_current_process()) { + for (auto& next_in_chain : command.next_chain) + run_tail(command, next_in_chain, last_return_code); + return nullptr; + } + Vector<const char*> argv; Vector<String> copy_argv = command.argv; argv.ensure_capacity(command.argv.size() + 1); |