Storage.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashMap.h>
  8. #include <LibWeb/Bindings/PlatformObject.h>
  9. #include <LibWeb/WebIDL/ExceptionOr.h>
  10. namespace Web::HTML {
  11. class Storage : public Bindings::PlatformObject {
  12. WEB_PLATFORM_OBJECT(Storage, Bindings::PlatformObject);
  13. public:
  14. static JS::NonnullGCPtr<Storage> create(JS::Realm&);
  15. ~Storage();
  16. size_t length() const;
  17. DeprecatedString key(size_t index);
  18. DeprecatedString get_item(DeprecatedString const& key) const;
  19. WebIDL::ExceptionOr<void> set_item(DeprecatedString const& key, DeprecatedString const& value);
  20. void remove_item(DeprecatedString const& key);
  21. void clear();
  22. Vector<DeprecatedString> supported_property_names() const;
  23. auto const& map() const { return m_map; }
  24. void dump() const;
  25. private:
  26. explicit Storage(JS::Realm&);
  27. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  28. void reorder();
  29. void broadcast(DeprecatedString const& key, DeprecatedString const& old_value, DeprecatedString const& new_value);
  30. OrderedHashMap<DeprecatedString, DeprecatedString> m_map;
  31. };
  32. }