summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Fetch/HeadersIterator.h
blob: a678abacb0b49cea0c0f5a3223ff01e120a1fd20 (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
45
46
47
/*
 * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Fetch/Headers.h>

namespace Web::Fetch {

class HeadersIterator
    : public Bindings::Wrappable
    , public RefCounted<HeadersIterator> {
public:
    using WrapperType = Bindings::HeadersIteratorWrapper;

    static NonnullRefPtr<HeadersIterator> create(Headers const& headers, JS::Object::PropertyKind iteration_kind)
    {
        return adopt_ref(*new HeadersIterator(headers, iteration_kind));
    }

    JS::ThrowCompletionOr<JS::Object*> next();

    void visit_edges(JS::Cell::Visitor&);

private:
    HeadersIterator(Headers const& headers, JS::Object::PropertyKind iteration_kind)
        : m_headers(headers)
        , m_iteration_kind(iteration_kind)
    {
    }

    Headers const& m_headers;
    JS::Object::PropertyKind m_iteration_kind;
    size_t m_index { 0 };
};

}

namespace Web::Bindings {

HeadersIteratorWrapper* wrap(JS::GlobalObject&, Fetch::HeadersIterator&);

}