FileSystemEntry.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/FileSystemEntryPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/EntriesAPI/FileSystemEntry.h>
  9. #include <LibWeb/HTML/Window.h>
  10. namespace Web::EntriesAPI {
  11. GC_DEFINE_ALLOCATOR(FileSystemEntry);
  12. GC::Ref<FileSystemEntry> FileSystemEntry::create(JS::Realm& realm, EntryType entry_type, ByteString name)
  13. {
  14. return realm.create<FileSystemEntry>(realm, entry_type, name);
  15. }
  16. FileSystemEntry::FileSystemEntry(JS::Realm& realm, EntryType entry_type, ByteString name)
  17. : PlatformObject(realm)
  18. , m_entry_type(entry_type)
  19. , m_name(name)
  20. {
  21. }
  22. void FileSystemEntry::initialize(JS::Realm& realm)
  23. {
  24. Base::initialize(realm);
  25. WEB_SET_PROTOTYPE_FOR_INTERFACE(FileSystemEntry);
  26. }
  27. // https://wicg.github.io/entries-api/#dom-filesystementry-isfile
  28. bool FileSystemEntry::is_file() const
  29. {
  30. // The isFile getter steps are to return true if this is a file entry and false otherwise.
  31. return m_entry_type == EntryType::File;
  32. }
  33. // https://wicg.github.io/entries-api/#dom-filesystementry-isdirectory
  34. bool FileSystemEntry::is_directory() const
  35. {
  36. // The isDirectory getter steps are to return true if this is a directory entry and false otherwise.
  37. return m_entry_type == EntryType::Directory;
  38. }
  39. // https://wicg.github.io/entries-api/#dom-filesystementry-name
  40. ByteString FileSystemEntry::name() const
  41. {
  42. // The name getter steps are to return this's name.
  43. return m_name;
  44. }
  45. }