LibJS: Make SharedFunctionInstanceData GC-allocated

This commit is contained in:
Andreas Kling 2025-10-26 11:09:09 +01:00 committed by Andreas Kling
parent b77f658c83
commit 3a38040c82
Notes: github-actions[bot] 2025-10-27 20:15:53 +00:00
4 changed files with 38 additions and 20 deletions

View file

@ -52,7 +52,7 @@ GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm,
break;
}
auto shared_data = adopt_ref(*new SharedFunctionInstanceData(
auto shared_data = realm.heap().allocate<SharedFunctionInstanceData>(
realm.vm(),
kind,
move(name),
@ -63,7 +63,7 @@ GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm,
is_strict,
is_arrow_function,
parsing_insights,
move(local_variables_names)));
move(local_variables_names));
shared_data->m_class_field_initializer_name = move(class_field_initializer_name);
@ -76,7 +76,7 @@ GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm,
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, Utf16FlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, NonnullRefPtr<FunctionParameters const> parameters, i32 function_length, Vector<LocalVariable> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
auto shared_data = adopt_ref(*new SharedFunctionInstanceData(
auto shared_data = realm.heap().allocate<SharedFunctionInstanceData>(
realm.vm(),
kind,
move(name),
@ -87,7 +87,7 @@ GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm,
is_strict,
is_arrow_function,
parsing_insights,
move(local_variables_names)));
move(local_variables_names));
shared_data->m_class_field_initializer_name = move(class_field_initializer_name);
return realm.create<ECMAScriptFunctionObject>(
move(shared_data),
@ -119,10 +119,11 @@ GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create_from_function
break;
}
RefPtr<SharedFunctionInstanceData> shared_data = function_node.shared_data();
auto shared_data = function_node.shared_data();
if (!shared_data) {
shared_data = adopt_ref(*new SharedFunctionInstanceData(realm->vm(),
shared_data = realm->heap().allocate<SharedFunctionInstanceData>(
realm->vm(),
function_node.kind(),
move(name),
function_node.function_length(),
@ -132,12 +133,12 @@ GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create_from_function
function_node.is_strict_mode(),
function_node.is_arrow_function(),
function_node.parsing_insights(),
function_node.local_variables_names()));
function_node.local_variables_names());
function_node.set_shared_data(shared_data);
}
return realm->create<ECMAScriptFunctionObject>(
shared_data.release_nonnull(),
*shared_data,
parent_environment,
private_environment,
*prototype);
@ -420,13 +421,22 @@ SharedFunctionInstanceData::SharedFunctionInstanceData(
m_function_environment_needed = arguments_object_needs_binding || m_function_environment_bindings_count > 0 || m_var_environment_bindings_count > 0 || m_lex_environment_bindings_count > 0 || parsing_insights.uses_this_from_environment || m_contains_direct_call_to_eval;
}
GC_DEFINE_ALLOCATOR(SharedFunctionInstanceData);
void SharedFunctionInstanceData::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
}
SharedFunctionInstanceData::~SharedFunctionInstanceData() = default;
ECMAScriptFunctionObject::ECMAScriptFunctionObject(
NonnullRefPtr<SharedFunctionInstanceData> shared_data,
GC::Ref<SharedFunctionInstanceData> shared_data,
Environment* parent_environment,
PrivateEnvironment* private_environment,
Object& prototype)
: FunctionObject(prototype)
, m_shared_data(move(shared_data))
, m_shared_data(shared_data)
, m_environment(parent_environment)
, m_private_environment(private_environment)
{
@ -641,7 +651,7 @@ void ECMAScriptFunctionObject::visit_edges(Visitor& visitor)
visitor.visit(m_private_environment);
visitor.visit(m_home_object);
visitor.visit(m_name_string);
visitor.visit(m_shared_data);
visitor.visit(m_bytecode_executable);
if (m_class_data) {