1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 19:05:08 +00:00

Shell: Make Node::resolve_as_list(nullptr) resolve to a 'pure' repr

'pure' as in "not requiring a shell", similar to
JS::Value::to_string_without_side_effects().
This commit is contained in:
AnotherTest 2020-09-14 19:30:20 +04:30 committed by Andreas Kling
parent 206dcd84a6
commit afe0ae586c

View file

@ -2316,6 +2316,9 @@ GlobValue::~GlobValue()
}
Vector<String> GlobValue::resolve_as_list(RefPtr<Shell> shell)
{
if (!shell)
return { m_glob };
return shell->expand_globs(m_glob, shell->cwd);
}
@ -2324,6 +2327,9 @@ SimpleVariableValue::~SimpleVariableValue()
}
Vector<String> SimpleVariableValue::resolve_as_list(RefPtr<Shell> shell)
{
if (!shell)
return {};
if (auto value = resolve_without_cast(shell); value != this)
return value->resolve_as_list(shell);
@ -2341,6 +2347,8 @@ Vector<String> SimpleVariableValue::resolve_as_list(RefPtr<Shell> shell)
NonnullRefPtr<Value> SimpleVariableValue::resolve_without_cast(RefPtr<Shell> shell)
{
ASSERT(shell);
if (auto value = shell->lookup_local_variable(m_name))
return value.release_nonnull();
return *this;
@ -2352,6 +2360,9 @@ SpecialVariableValue::~SpecialVariableValue()
Vector<String> SpecialVariableValue::resolve_as_list(RefPtr<Shell> shell)
{
if (!shell)
return {};
switch (m_name) {
case '?':
return { String::number(shell->last_return_code) };
@ -2383,6 +2394,10 @@ Vector<String> TildeValue::resolve_as_list(RefPtr<Shell> shell)
StringBuilder builder;
builder.append("~");
builder.append(m_username);
if (!shell)
return { builder.to_string() };
return { shell->expand_tilde(builder.to_string()) };
}