mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 18:00:31 +00:00
LibWeb: Don't use GC::Root in FormDataEntryValue variant
This was causing reference cycles and leaking entire realms.
This commit is contained in:
parent
e2d5802942
commit
3a6782689f
Notes:
github-actions[bot]
2025-12-26 10:58:05 +00:00
Author: https://github.com/awesomekling
Commit: 3a6782689f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7236
Reviewed-by: https://github.com/gmta ✅
5 changed files with 7 additions and 8 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 this’s entry list, then return null.
|
||||
auto entry_iterator = m_entry_list.find_if([&name](FormDataEntry const& entry) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue