FileList.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. 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. // ^Bindings::LegacyPlatformObject
  38. virtual bool supports_indexed_properties() const override { return true; }
  39. virtual bool supports_named_properties() const override { return false; }
  40. virtual bool has_indexed_property_setter() const override { return false; }
  41. virtual bool has_named_property_setter() const override { return false; }
  42. virtual bool has_named_property_deleter() const override { return false; }
  43. virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
  44. virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
  45. virtual bool has_global_interface_extended_attribute() const override { return false; }
  46. virtual bool indexed_property_setter_has_identifier() const override { return false; }
  47. virtual bool named_property_setter_has_identifier() const override { return false; }
  48. virtual bool named_property_deleter_has_identifier() const override { return false; }
  49. Vector<JS::NonnullGCPtr<File>> m_files;
  50. };
  51. }