mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibJS: Use local variables for function declarations when possible
Previously, the usage of local variables was limited for all function declarations. This change relaxes the restriction and only prohibits locals for hoistable annexB declarations.
This commit is contained in:
parent
167495b87b
commit
8b6450842e
Notes:
sideshowbarker
2024-07-16 23:57:20 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 8b6450842e
Pull-request: https://github.com/SerenityOS/serenity/pull/19889
Reviewed-by: https://github.com/awesomekling
4 changed files with 36 additions and 26 deletions
|
@ -616,7 +616,11 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
|||
auto private_environment = callee_context.private_environment;
|
||||
for (auto& declaration : functions_to_initialize) {
|
||||
auto function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), declaration.local_variables_names(), lex_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object(), declaration.contains_direct_call_to_eval());
|
||||
MUST(var_environment->set_mutable_binding(vm, declaration.name(), function, false));
|
||||
if ((vm.bytecode_interpreter_if_exists() || kind() == FunctionKind::Generator) && declaration.name_identifier()->is_local()) {
|
||||
callee_context.local_variables[declaration.name_identifier()->local_variable_index()] = function;
|
||||
} else {
|
||||
MUST(var_environment->set_mutable_binding(vm, declaration.name(), function, false));
|
||||
}
|
||||
}
|
||||
|
||||
if (is<DeclarativeEnvironment>(*lex_environment))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue