Serenity Operating System
at master 64 lines 2.5 kB view raw
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 8#pragma once 9 10#include <AK/Vector.h> 11#include <LibJS/Heap/GCPtr.h> 12#include <LibWeb/Bindings/LegacyPlatformObject.h> 13#include <LibWeb/FileAPI/File.h> 14 15namespace Web::FileAPI { 16 17class FileList : public Bindings::LegacyPlatformObject { 18 WEB_PLATFORM_OBJECT(FileList, Bindings::LegacyPlatformObject); 19 20public: 21 static WebIDL::ExceptionOr<JS::NonnullGCPtr<FileList>> create(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&); 22 virtual ~FileList() override; 23 24 // https://w3c.github.io/FileAPI/#dfn-length 25 unsigned long length() const { return m_files.size(); } 26 27 // https://w3c.github.io/FileAPI/#dfn-item 28 File* item(size_t index) 29 { 30 return index < m_files.size() ? m_files[index].ptr() : nullptr; 31 } 32 33 // https://w3c.github.io/FileAPI/#dfn-item 34 File const* item(size_t index) const 35 { 36 return index < m_files.size() ? m_files[index].ptr() : nullptr; 37 } 38 39 virtual bool is_supported_property_index(u32 index) const override; 40 virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override; 41 42private: 43 FileList(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&); 44 45 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; 46 virtual void visit_edges(Cell::Visitor&) override; 47 48 // ^Bindings::LegacyPlatformObject 49 virtual bool supports_indexed_properties() const override { return true; } 50 virtual bool supports_named_properties() const override { return false; } 51 virtual bool has_indexed_property_setter() const override { return false; } 52 virtual bool has_named_property_setter() const override { return false; } 53 virtual bool has_named_property_deleter() const override { return false; } 54 virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; } 55 virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; } 56 virtual bool has_global_interface_extended_attribute() const override { return false; } 57 virtual bool indexed_property_setter_has_identifier() const override { return false; } 58 virtual bool named_property_setter_has_identifier() const override { return false; } 59 virtual bool named_property_deleter_has_identifier() const override { return false; } 60 61 Vector<JS::NonnullGCPtr<File>> m_files; 62}; 63 64}