LibJS: Pre-store formal parameter runtime data

Replace the runtime uses of formal_parameters() with pre-computed data:
- m_formal_parameter_count stores the parameter count
- m_parameter_names_for_mapped_arguments stores ordered parameter names
  for simple parameter lists (used by create_mapped_arguments_object)

Change create_mapped_arguments_object to take Span<Utf16FlyString>
instead of NonnullRefPtr<FunctionParameters const>.

Remove virtual formal_parameters() from FunctionObject as it is no
longer needed.
This commit is contained in:
Andreas Kling
2026-02-11 01:13:06 +01:00
committed by Andreas Kling
parent 712d3fc54f
commit 9ea5aa93f8
Notes: github-actions[bot] 2026-02-11 23:00:44 +00:00
8 changed files with 32 additions and 61 deletions

View File

@@ -140,53 +140,14 @@ GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create_from_function
prototype);
}
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create_from_function_node(
FunctionNode const& function_node,
Utf16FlyString name,
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create_from_function_data(
GC::Ref<Realm> realm,
GC::Ref<SharedFunctionInstanceData> shared_data,
GC::Ptr<Environment> parent_environment,
GC::Ptr<PrivateEnvironment> private_environment)
{
GC::Ptr<Object> prototype = nullptr;
switch (function_node.kind()) {
case FunctionKind::Normal:
prototype = realm->intrinsics().function_prototype();
break;
case FunctionKind::Generator:
prototype = realm->intrinsics().generator_function_prototype();
break;
case FunctionKind::Async:
prototype = realm->intrinsics().async_function_prototype();
break;
case FunctionKind::AsyncGenerator:
prototype = realm->intrinsics().async_generator_function_prototype();
break;
}
auto shared_data = function_node.shared_data();
if (!shared_data) {
shared_data = realm->heap().allocate<SharedFunctionInstanceData>(
realm->vm(),
function_node.kind(),
move(name),
function_node.function_length(),
function_node.parameters(),
*function_node.body_ptr(),
function_node.source_text(),
function_node.is_strict_mode(),
function_node.is_arrow_function(),
function_node.parsing_insights(),
function_node.local_variables_names());
function_node.set_shared_data(shared_data);
}
return create_from_function_data(
realm,
*shared_data,
parent_environment,
private_environment,
*prototype);
auto prototype = prototype_for_function_kind(*realm, shared_data->m_kind);
return create_from_function_data(realm, shared_data, parent_environment, private_environment, *prototype);
}
ECMAScriptFunctionObject::ECMAScriptFunctionObject(
@@ -265,7 +226,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::get_stack_frame_size(size_t& r
}
registers_and_locals_count = executable->registers_and_locals_count;
constants_count = executable->constants.size();
argument_count = max(argument_count, formal_parameters().size());
argument_count = max(argument_count, static_cast<size_t>(formal_parameter_count()));
return {};
}