mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 08:10:02 +00:00
LibJS: Don't leak class field initializers
We were storing these in Handle (strong GC roots) hanging off of ECMAScriptFunctionObject which effectively turned into world leaks.
This commit is contained in:
parent
8c809fa5ee
commit
5aa1d7837f
Notes:
github-actions[bot]
2024-11-10 18:13:56 +00:00
Author: https://github.com/awesomekling
Commit: 5aa1d7837f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2268
4 changed files with 7 additions and 6 deletions
|
@ -227,7 +227,7 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
|
||||||
auto& realm = *vm.current_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto property_key_or_private_name = TRY(class_key_to_property_name(vm, *m_key, property_key));
|
auto property_key_or_private_name = TRY(class_key_to_property_name(vm, *m_key, property_key));
|
||||||
Handle<ECMAScriptFunctionObject> initializer {};
|
GCPtr<ECMAScriptFunctionObject> initializer;
|
||||||
if (m_initializer) {
|
if (m_initializer) {
|
||||||
auto copy_initializer = m_initializer;
|
auto copy_initializer = m_initializer;
|
||||||
auto name = property_key_or_private_name.visit(
|
auto name = property_key_or_private_name.visit(
|
||||||
|
@ -370,7 +370,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_const
|
||||||
|
|
||||||
ConservativeVector<PrivateElement> static_private_methods(vm.heap());
|
ConservativeVector<PrivateElement> static_private_methods(vm.heap());
|
||||||
ConservativeVector<PrivateElement> instance_private_methods(vm.heap());
|
ConservativeVector<PrivateElement> instance_private_methods(vm.heap());
|
||||||
Vector<ClassFieldDefinition> instance_fields;
|
ConservativeVector<ClassFieldDefinition> instance_fields(vm.heap());
|
||||||
Vector<StaticElement> static_elements;
|
Vector<StaticElement> static_elements;
|
||||||
|
|
||||||
for (size_t element_index = 0; element_index < m_elements.size(); element_index++) {
|
for (size_t element_index = 0; element_index < m_elements.size(); element_index++) {
|
||||||
|
|
|
@ -17,8 +17,8 @@ using ClassElementName = Variant<PropertyKey, PrivateName>;
|
||||||
|
|
||||||
// 6.2.10 The ClassFieldDefinition Record Specification Type, https://tc39.es/ecma262/#sec-classfielddefinition-record-specification-type
|
// 6.2.10 The ClassFieldDefinition Record Specification Type, https://tc39.es/ecma262/#sec-classfielddefinition-record-specification-type
|
||||||
struct ClassFieldDefinition {
|
struct ClassFieldDefinition {
|
||||||
ClassElementName name; // [[Name]]
|
ClassElementName name; // [[Name]]
|
||||||
Handle<ECMAScriptFunctionObject> initializer; // [[Initializer]]
|
GCPtr<ECMAScriptFunctionObject> initializer; // [[Initializer]]
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -544,6 +544,7 @@ void ECMAScriptFunctionObject::visit_edges(Visitor& visitor)
|
||||||
visitor.visit(m_bytecode_executable);
|
visitor.visit(m_bytecode_executable);
|
||||||
|
|
||||||
for (auto& field : m_fields) {
|
for (auto& field : m_fields) {
|
||||||
|
visitor.visit(field.initializer);
|
||||||
if (auto* property_key_ptr = field.name.get_pointer<PropertyKey>(); property_key_ptr && property_key_ptr->is_symbol())
|
if (auto* property_key_ptr = field.name.get_pointer<PropertyKey>(); property_key_ptr && property_key_ptr->is_symbol())
|
||||||
visitor.visit(property_key_ptr->as_symbol());
|
visitor.visit(property_key_ptr->as_symbol());
|
||||||
}
|
}
|
||||||
|
|
|
@ -663,9 +663,9 @@ ThrowCompletionOr<void> Object::define_field(ClassFieldDefinition const& field)
|
||||||
auto init_value = js_undefined();
|
auto init_value = js_undefined();
|
||||||
|
|
||||||
// 3. If initializer is not empty, then
|
// 3. If initializer is not empty, then
|
||||||
if (!initializer.is_null()) {
|
if (initializer) {
|
||||||
// a. Let initValue be ? Call(initializer, receiver).
|
// a. Let initValue be ? Call(initializer, receiver).
|
||||||
init_value = TRY(call(vm, initializer.cell(), this));
|
init_value = TRY(call(vm, initializer, this));
|
||||||
}
|
}
|
||||||
// 4. Else, let initValue be undefined.
|
// 4. Else, let initValue be undefined.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue