LibWeb: Don't use GC::Root in FormDataEntryValue variant

This was causing reference cycles and leaking entire realms.
This commit is contained in:
Andreas Kling 2025-12-26 07:18:39 +01:00 committed by Jelle Raaijmakers
parent e2d5802942
commit 3a6782689f
Notes: github-actions[bot] 2025-12-26 10:58:05 +00:00
5 changed files with 7 additions and 8 deletions

View file

@ -447,8 +447,7 @@ MultipartParsingErrorOr<Vector<XHR::FormDataEntry>> parse_multipart_form_data(JS
auto blob = FileAPI::Blob::create(realm, MUST(ByteBuffer::copy(body.bytes())), header.content_type.release_value());
FileAPI::FilePropertyBag options {};
options.type = blob->type();
auto file = MUST(FileAPI::File::create(realm, { GC::make_root(blob) }, header.filename.release_value(), move(options)));
value = GC::make_root(file);
value = MUST(FileAPI::File::create(realm, { GC::make_root(blob) }, header.filename.release_value(), move(options)));
}
// 11. Otherwise:
else {

View file

@ -28,11 +28,11 @@ WebIDL::ExceptionOr<XHR::FormDataEntry> create_entry(JS::Realm& realm, String co
auto entry_value = TRY(value.visit(
// 2. If value is a string, then set value to the result of converting value into a scalar value string.
[&](String const& string) -> WebIDL::ExceptionOr<Variant<GC::Root<FileAPI::File>, String>> {
[&](String const& string) -> WebIDL::ExceptionOr<Variant<GC::Ref<FileAPI::File>, String>> {
return TRY_OR_THROW_OOM(vm, Infra::convert_to_scalar_value_string(string));
},
// 3. Otherwise:
[&](GC::Ref<FileAPI::Blob> blob) -> WebIDL::ExceptionOr<Variant<GC::Root<FileAPI::File>, String>> {
[&](GC::Ref<FileAPI::Blob> blob) -> WebIDL::ExceptionOr<Variant<GC::Ref<FileAPI::File>, String>> {
// 1. If value is not a File object, then set value to a new File object, representing the same bytes, whose
// name attribute value is "blob".
if (!is<FileAPI::File>(*blob)) {
@ -52,7 +52,7 @@ WebIDL::ExceptionOr<XHR::FormDataEntry> create_entry(JS::Realm& realm, String co
blob = TRY(FileAPI::File::create(realm, { GC::make_root(*blob) }, *filename, move(options)));
}
return GC::make_root(as<FileAPI::File>(*blob));
return GC::Ref { as<FileAPI::File>(*blob) };
}));
// 4. Return an entry whose name is name and whose value is value.

View file

@ -128,7 +128,7 @@ void FormData::delete_(String const& name)
}
// https://xhr.spec.whatwg.org/#dom-formdata-get
Variant<GC::Root<FileAPI::File>, String, Empty> FormData::get(String const& name)
Variant<GC::Ref<FileAPI::File>, String, Empty> FormData::get(String const& name)
{
// 1. If there is no entry whose name is name in thiss entry list, then return null.
auto entry_iterator = m_entry_list.find_if([&name](FormDataEntry const& entry) {

View file

@ -33,7 +33,7 @@ public:
WebIDL::ExceptionOr<void> append(String const& name, String const& value);
WebIDL::ExceptionOr<void> append(String const& name, GC::Ref<FileAPI::Blob> const& blob_value, Optional<String> const& filename = {});
void delete_(String const& name);
Variant<GC::Root<FileAPI::File>, String, Empty> get(String const& name);
Variant<GC::Ref<FileAPI::File>, String, Empty> get(String const& name);
WebIDL::ExceptionOr<Vector<FormDataEntryValue>> get_all(String const& name);
bool has(String const& name);
WebIDL::ExceptionOr<void> set(String const& name, String const& value);

View file

@ -14,7 +14,7 @@
namespace Web::XHR {
// https://xhr.spec.whatwg.org/#formdataentryvalue
using FormDataEntryValue = Variant<GC::Root<FileAPI::File>, String>;
using FormDataEntryValue = Variant<GC::Ref<FileAPI::File>, String>;
struct FormDataEntry {
String name;