LibJs: Use the new instantiate_function_object

Use the more spec compliant instantiate_function_object instead of
ECMAScriptFunctionObject::create() where applicable.
This commit is contained in:
Mohamed amine Bounya 2024-09-27 16:06:46 +01:00
parent a104cd4d3e
commit 89baaa40d9
3 changed files with 4 additions and 13 deletions

View File

@ -1630,8 +1630,7 @@ void ScopeNode::block_declaration_instantiation(VM& vm, Environment* environment
auto& function_declaration = static_cast<FunctionDeclaration const&>(declaration);
// ii. Let fo be InstantiateFunctionObject of d with arguments env and privateEnv.
auto function = ECMAScriptFunctionObject::create(realm, function_declaration.name(), function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), function_declaration.local_variables_names(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(),
function_declaration.parsing_insights());
auto function = ECMAScriptFunctionObject::instantiate_function_object(realm, environment, private_environment, function_declaration);
// iii. Perform ! env.InitializeBinding(fn, fo). NOTE: This step is replaced in section B.3.2.6.
if (function_declaration.name_identifier()->is_local()) {
@ -1838,8 +1837,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(VM& vm, Global
for (auto& declaration : functions_to_initialize.in_reverse()) {
// a. Let fn be the sole element of the BoundNames of f.
// b. Let fo be InstantiateFunctionObject of f with arguments env and privateEnv.
auto function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), declaration.local_variables_names(), &global_environment, private_environment, declaration.kind(), declaration.is_strict_mode(),
declaration.parsing_insights());
auto function = ECMAScriptFunctionObject::instantiate_function_object(realm, &global_environment, private_environment, declaration);
// c. Perform ? env.CreateGlobalFunctionBinding(fn, fo, false).
TRY(global_environment.create_global_function_binding(declaration.name(), function, false));

View File

@ -972,8 +972,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, Program const& pr
for (auto& declaration : functions_to_initialize.in_reverse()) {
// a. Let fn be the sole element of the BoundNames of f.
// b. Let fo be InstantiateFunctionObject of f with arguments lexEnv and privateEnv.
auto function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), declaration.local_variables_names(), lexical_environment, private_environment, declaration.kind(), declaration.is_strict_mode(),
declaration.parsing_insights());
auto function = ECMAScriptFunctionObject::instantiate_function_object(realm, lexical_environment, private_environment, declaration);
// c. If varEnv is a global Environment Record, then
if (global_var_environment) {

View File

@ -495,13 +495,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
auto const& function_declaration = static_cast<FunctionDeclaration const&>(declaration);
// 1. Let fo be InstantiateFunctionObject of d with arguments env and privateEnv.
// NOTE: Special case if the function is a default export of an anonymous function
// it has name "*default*" but internally should have name "default".
DeprecatedFlyString function_name = function_declaration.name();
if (function_name == ExportStatement::local_name_for_default)
function_name = "default"sv;
auto function = ECMAScriptFunctionObject::create(realm(), function_name, function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), function_declaration.local_variables_names(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(),
function_declaration.parsing_insights());
auto function = ECMAScriptFunctionObject::instantiate_function_object(realm(), environment, private_environment, function_declaration);
// 2. Perform ! env.InitializeBinding(dn, fo, normal).
MUST(environment->initialize_binding(vm, name, function, Environment::InitializeBindingHint::Normal));