mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-28 04:08:08 +00:00
LibWeb: Add {,de}serialization steps for FileList
This commit is contained in:
committed by
Andreas Kling
parent
5397340724
commit
c92f556aa5
@@ -18,6 +18,11 @@ JS::NonnullGCPtr<FileList> FileList::create(JS::Realm& realm, Vector<JS::Nonnull
|
||||
return realm.heap().allocate<FileList>(realm, realm, move(files));
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<FileList> FileList::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<FileList>(realm, realm);
|
||||
}
|
||||
|
||||
FileList::FileList(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& files)
|
||||
: Bindings::PlatformObject(realm)
|
||||
, m_files(move(files))
|
||||
@@ -25,6 +30,12 @@ FileList::FileList(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& 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<void> 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<void> FileList::deserialization_steps(ReadonlySpan<u32> 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<size_t>(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<File>(deserialized_record.value.value().as_object()))
|
||||
m_files.append(dynamic_cast<File&>(deserialized_record.value.release_value().as_object()));
|
||||
position = deserialized_record.position;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user