FileList.h 1.1 KB

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