FileList.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/LegacyPlatformObject.h>
  11. #include <LibWeb/FileAPI/File.h>
  12. namespace Web::FileAPI {
  13. class FileList : public Bindings::LegacyPlatformObject {
  14. WEB_PLATFORM_OBJECT(FileList, Bindings::LegacyPlatformObject);
  15. public:
  16. static WebIDL::ExceptionOr<JS::NonnullGCPtr<FileList>> create(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&);
  17. virtual ~FileList() override;
  18. // https://w3c.github.io/FileAPI/#dfn-length
  19. unsigned long length() const { return m_files.size(); }
  20. // https://w3c.github.io/FileAPI/#dfn-item
  21. File* item(size_t index)
  22. {
  23. return index < m_files.size() ? m_files[index].ptr() : nullptr;
  24. }
  25. // https://w3c.github.io/FileAPI/#dfn-item
  26. File const* item(size_t index) const
  27. {
  28. return index < m_files.size() ? m_files[index].ptr() : nullptr;
  29. }
  30. virtual bool is_supported_property_index(u32 index) const override;
  31. virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
  32. private:
  33. FileList(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&);
  34. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  35. virtual void visit_edges(Cell::Visitor&) override;
  36. // ^Bindings::LegacyPlatformObject
  37. virtual bool supports_indexed_properties() const override { return true; }
  38. virtual bool supports_named_properties() const override { return false; }
  39. virtual bool has_indexed_property_setter() const override { return false; }
  40. virtual bool has_named_property_setter() const override { return false; }
  41. virtual bool has_named_property_deleter() const override { return false; }
  42. virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
  43. virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
  44. virtual bool has_global_interface_extended_attribute() const override { return false; }
  45. virtual bool indexed_property_setter_has_identifier() const override { return false; }
  46. virtual bool named_property_setter_has_identifier() const override { return false; }
  47. virtual bool named_property_deleter_has_identifier() const override { return false; }
  48. Vector<JS::NonnullGCPtr<File>> m_files;
  49. };
  50. }