mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibJS: Make SharedFunctionInstanceData GC-allocated
This commit is contained in:
parent
b77f658c83
commit
3a38040c82
|
|
@ -853,14 +853,14 @@ FunctionNode::FunctionNode(RefPtr<Identifier const> name, ByteString source_text
|
|||
|
||||
FunctionNode::~FunctionNode() = default;
|
||||
|
||||
void FunctionNode::set_shared_data(RefPtr<SharedFunctionInstanceData> shared_data) const
|
||||
void FunctionNode::set_shared_data(GC::Ptr<SharedFunctionInstanceData> shared_data) const
|
||||
{
|
||||
m_shared_data = move(shared_data);
|
||||
}
|
||||
|
||||
RefPtr<SharedFunctionInstanceData> FunctionNode::shared_data() const
|
||||
GC::Ptr<SharedFunctionInstanceData> FunctionNode::shared_data() const
|
||||
{
|
||||
return m_shared_data;
|
||||
return m_shared_data.ptr();
|
||||
}
|
||||
|
||||
void FunctionNode::dump(int indent, ByteString const& class_name) const
|
||||
|
|
|
|||
|
|
@ -801,8 +801,8 @@ public:
|
|||
virtual bool has_name() const = 0;
|
||||
virtual Value instantiate_ordinary_function_expression(VM&, Utf16FlyString given_name) const = 0;
|
||||
|
||||
RefPtr<SharedFunctionInstanceData> shared_data() const;
|
||||
void set_shared_data(RefPtr<SharedFunctionInstanceData>) const;
|
||||
GC::Ptr<SharedFunctionInstanceData> shared_data() const;
|
||||
void set_shared_data(GC::Ptr<SharedFunctionInstanceData>) const;
|
||||
|
||||
virtual ~FunctionNode();
|
||||
|
||||
|
|
@ -824,7 +824,7 @@ private:
|
|||
|
||||
Vector<LocalVariable> m_local_variables_names;
|
||||
|
||||
mutable RefPtr<SharedFunctionInstanceData> m_shared_data;
|
||||
mutable GC::Root<SharedFunctionInstanceData> m_shared_data;
|
||||
};
|
||||
|
||||
class FunctionDeclaration final
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -34,8 +34,13 @@ enum class ConstructorKind : u8 {
|
|||
Derived,
|
||||
};
|
||||
|
||||
class SharedFunctionInstanceData : public RefCounted<SharedFunctionInstanceData> {
|
||||
class SharedFunctionInstanceData final : public GC::Cell {
|
||||
GC_CELL(SharedFunctionInstanceData, GC::Cell);
|
||||
GC_DECLARE_ALLOCATOR(SharedFunctionInstanceData);
|
||||
|
||||
public:
|
||||
virtual ~SharedFunctionInstanceData() override;
|
||||
|
||||
SharedFunctionInstanceData(
|
||||
VM& vm,
|
||||
FunctionKind,
|
||||
|
|
@ -96,6 +101,9 @@ public:
|
|||
Variant<PropertyKey, PrivateName, Empty> m_class_field_initializer_name; // [[ClassFieldInitializerName]]
|
||||
ConstructorKind m_constructor_kind : 1 { ConstructorKind::Base }; // [[ConstructorKind]]
|
||||
bool m_is_class_constructor : 1 { false }; // [[IsClassConstructor]]
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
};
|
||||
|
||||
// 10.2 ECMAScript Function Objects, https://tc39.es/ecma262/#sec-ecmascript-function-objects
|
||||
|
|
@ -184,7 +192,7 @@ public:
|
|||
|
||||
private:
|
||||
ECMAScriptFunctionObject(
|
||||
NonnullRefPtr<SharedFunctionInstanceData>,
|
||||
GC::Ref<SharedFunctionInstanceData>,
|
||||
Environment* parent_environment,
|
||||
PrivateEnvironment* private_environment,
|
||||
Object& prototype);
|
||||
|
|
@ -202,7 +210,7 @@ private:
|
|||
void prepare_for_ordinary_call(VM&, ExecutionContext& callee_context, Object* new_target);
|
||||
void ordinary_call_bind_this(VM&, ExecutionContext&, Value this_argument);
|
||||
|
||||
NonnullRefPtr<SharedFunctionInstanceData> m_shared_data;
|
||||
GC::Ref<SharedFunctionInstanceData> m_shared_data;
|
||||
|
||||
GC::Ptr<PrimitiveString> m_name_string;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user