LibJS: Use a local variable for arguments object when possible

This allows us to skip allocating a function environment in cases where
it was previously impossible because the arguments object needed a
binding.

This change does not bring visible improvement in Kraken or Octane
benchmarks but seems useful to have anyway.
This commit is contained in:
Aliaksandr Kalenik 2024-05-21 09:32:51 +01:00 committed by Andreas Kling
commit 210a5d77dc
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00
5 changed files with 39 additions and 11 deletions

View file

@ -295,17 +295,15 @@ public:
continue;
}
if (identifier_group_name == "arguments"sv) {
// NOTE: arguments is a special variable that should not be treated as a candidate to become local
continue;
}
bool scope_has_declaration = false;
if (is_top_level() && m_var_names.contains(identifier_group_name))
scope_has_declaration = true;
else if (m_lexical_names.contains(identifier_group_name) || m_function_names.contains(identifier_group_name))
scope_has_declaration = true;
if (m_type == ScopeType::Function && !m_is_arrow_function && identifier_group_name == "arguments"sv)
scope_has_declaration = true;
bool hoistable_function_declaration = false;
for (auto const& function_declaration : m_functions_to_hoist) {
if (function_declaration->name() == identifier_group_name)
@ -448,6 +446,11 @@ public:
}
}
void set_is_arrow_function()
{
m_is_arrow_function = true;
}
private:
void throw_identifier_declared(DeprecatedFlyString const& name, NonnullRefPtr<Declaration const> const& declaration)
{
@ -489,6 +492,7 @@ private:
bool m_contains_await_expression { false };
bool m_screwed_by_eval_in_scope_chain { false };
bool m_uses_this { false };
bool m_is_arrow_function { false };
};
class OperatorPrecedenceTable {
@ -995,6 +999,7 @@ RefPtr<FunctionExpression const> Parser::try_parse_arrow_function_expression(boo
bool uses_this = false;
auto function_body_result = [&]() -> RefPtr<FunctionBody const> {
ScopePusher function_scope = ScopePusher::function_scope(*this);
function_scope.set_is_arrow_function();
if (expect_parens) {
// We have parens around the function parameters and can re-use the same parsing