FileList.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
  3. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Vector.h>
  9. #include <LibJS/Heap/GCPtr.h>
  10. #include <LibWeb/Bindings/PlatformObject.h>
  11. #include <LibWeb/FileAPI/File.h>
  12. namespace Web::FileAPI {
  13. class FileList : public Bindings::PlatformObject {
  14. WEB_PLATFORM_OBJECT(FileList, Bindings::PlatformObject);
  15. JS_DECLARE_ALLOCATOR(FileList);
  16. public:
  17. [[nodiscard]] static JS::NonnullGCPtr<FileList> create(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&);
  18. virtual ~FileList() override;
  19. // https://w3c.github.io/FileAPI/#dfn-length
  20. unsigned long length() const { return m_files.size(); }
  21. // https://w3c.github.io/FileAPI/#dfn-item
  22. File* item(size_t index)
  23. {
  24. return index < m_files.size() ? m_files[index].ptr() : nullptr;
  25. }
  26. // https://w3c.github.io/FileAPI/#dfn-item
  27. File const* item(size_t index) const
  28. {
  29. return index < m_files.size() ? m_files[index].ptr() : nullptr;
  30. }
  31. virtual bool is_supported_property_index(u32 index) const override;
  32. virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
  33. private:
  34. FileList(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&);
  35. virtual void initialize(JS::Realm&) override;
  36. virtual void visit_edges(Cell::Visitor&) override;
  37. Vector<JS::NonnullGCPtr<File>> m_files;
  38. };
  39. }