diff --git a/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-FileList.txt b/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-FileList.txt
new file mode 100644
index 00000000000..349dfd04f19
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-FileList.txt
@@ -0,0 +1,5 @@
+Select files...4 files selected. input1:
+file1: text/plain: Contents for file1
+file2: text/plain: Contents for file2
+file3: text/plain: Contents for file3
+file4: text/plain: Contents for file4
diff --git a/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-FileList.html b/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-FileList.html
new file mode 100644
index 00000000000..125d7744530
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-FileList.html
@@ -0,0 +1,32 @@
+
+
+
diff --git a/Userland/Libraries/LibWeb/FileAPI/FileList.cpp b/Userland/Libraries/LibWeb/FileAPI/FileList.cpp
index 50f529ff377..13eac9b7f11 100644
--- a/Userland/Libraries/LibWeb/FileAPI/FileList.cpp
+++ b/Userland/Libraries/LibWeb/FileAPI/FileList.cpp
@@ -18,6 +18,11 @@ JS::NonnullGCPtr FileList::create(JS::Realm& realm, Vector(realm, realm, move(files));
}
+JS::NonnullGCPtr FileList::create(JS::Realm& realm)
+{
+ return realm.heap().allocate(realm, realm);
+}
+
FileList::FileList(JS::Realm& realm, Vector>&& files)
: Bindings::PlatformObject(realm)
, m_files(move(files))
@@ -25,6 +30,12 @@ FileList::FileList(JS::Realm& realm, Vector>&& files)
m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = 1 };
}
+FileList::FileList(JS::Realm& realm)
+ : Bindings::PlatformObject(realm)
+{
+ m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = 1 };
+}
+
FileList::~FileList() = default;
void FileList::initialize(JS::Realm& realm)
@@ -59,4 +70,34 @@ void FileList::visit_edges(Cell::Visitor& visitor)
visitor.visit(file);
}
+WebIDL::ExceptionOr FileList::serialization_steps(HTML::SerializationRecord& serialized, bool for_storage, HTML::SerializationMemory& memory)
+{
+ auto& vm = this->vm();
+
+ // 1. Set serialized.[[Files]] to an empty list.
+ // 2. For each file in value, append the sub-serialization of file to serialized.[[Files]].
+ HTML::serialize_primitive_type(serialized, m_files.size());
+ for (auto& file : m_files)
+ serialized.extend(TRY(HTML::structured_serialize_internal(vm, file, for_storage, memory)));
+
+ return {};
+}
+
+WebIDL::ExceptionOr FileList::deserialization_steps(ReadonlySpan const& serialized, size_t& position, HTML::DeserializationMemory& memory)
+{
+ auto& vm = this->vm();
+ auto& realm = *vm.current_realm();
+
+ // 1. For each file of serialized.[[Files]], add the sub-deserialization of file to value.
+ auto size = HTML::deserialize_primitive_type(serialized, position);
+ for (size_t i = 0; i < size; ++i) {
+ auto deserialized_record = TRY(HTML::structured_deserialize_internal(vm, serialized, realm, memory, position));
+ if (deserialized_record.value.has_value() && is(deserialized_record.value.value().as_object()))
+ m_files.append(dynamic_cast(deserialized_record.value.release_value().as_object()));
+ position = deserialized_record.position;
+ }
+
+ return {};
+}
+
}
diff --git a/Userland/Libraries/LibWeb/FileAPI/FileList.h b/Userland/Libraries/LibWeb/FileAPI/FileList.h
index d7b9205a021..eb4c368c123 100644
--- a/Userland/Libraries/LibWeb/FileAPI/FileList.h
+++ b/Userland/Libraries/LibWeb/FileAPI/FileList.h
@@ -15,12 +15,16 @@
namespace Web::FileAPI {
-class FileList : public Bindings::PlatformObject {
+class FileList
+ : public Bindings::PlatformObject
+ , public Bindings::Serializable {
WEB_PLATFORM_OBJECT(FileList, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(FileList);
public:
[[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, Vector>&&);
+ [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&);
+
virtual ~FileList() override;
// https://w3c.github.io/FileAPI/#dfn-length
@@ -41,8 +45,13 @@ public:
virtual bool is_supported_property_index(u32 index) const override;
virtual WebIDL::ExceptionOr item_value(size_t index) const override;
+ virtual StringView interface_name() const override { return "FileList"sv; }
+ virtual WebIDL::ExceptionOr serialization_steps(HTML::SerializationRecord& serialized, bool for_storage, HTML::SerializationMemory&) override;
+ virtual WebIDL::ExceptionOr deserialization_steps(ReadonlySpan const& serialized, size_t& position, HTML::DeserializationMemory&) override;
+
private:
FileList(JS::Realm&, Vector>&&);
+ explicit FileList(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
diff --git a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp
index ec6d096498e..3dc2d4bee19 100644
--- a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp
+++ b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp
@@ -36,6 +36,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -974,6 +975,8 @@ private:
return FileAPI::Blob::create(realm);
if (interface_name == "File"sv)
return FileAPI::File::create(realm);
+ if (interface_name == "FileList"sv)
+ return FileAPI::FileList::create(realm);
if (interface_name == "DOMMatrixReadOnly"sv)
return Geometry::DOMMatrixReadOnly::create(realm);
if (interface_name == "DOMMatrix"sv)