summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/Storage.h
blob: 0090431d45cac92d8141c3c35cc321c73a079553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/HashMap.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/WebIDL/ExceptionOr.h>

namespace Web::HTML {

class Storage : public Bindings::PlatformObject {
    WEB_PLATFORM_OBJECT(Storage, Bindings::PlatformObject);

public:
    static JS::NonnullGCPtr<Storage> create(JS::Realm&);
    ~Storage();

    size_t length() const;
    DeprecatedString key(size_t index);
    DeprecatedString get_item(DeprecatedString const& key) const;
    WebIDL::ExceptionOr<void> set_item(DeprecatedString const& key, DeprecatedString const& value);
    void remove_item(DeprecatedString const& key);
    void clear();

    Vector<DeprecatedString> supported_property_names() const;

    auto const& map() const { return m_map; }

    void dump() const;

private:
    explicit Storage(JS::Realm&);

    void reorder();
    void broadcast(DeprecatedString const& key, DeprecatedString const& old_value, DeprecatedString const& new_value);

    OrderedHashMap<DeprecatedString, DeprecatedString> m_map;
};

}