Coverage Report

Created: 2025-09-05 06:52

/src/serenity/Userland/Libraries/LibWeb/WebIDL/ObservableArray.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibJS/Runtime/Array.h>
10
#include <LibWeb/WebIDL/ExceptionOr.h>
11
12
namespace Web::WebIDL {
13
14
// https://webidl.spec.whatwg.org/#idl-observable-array
15
class ObservableArray final : public JS::Array {
16
    JS_OBJECT(ObservableArray, JS::Array);
17
    JS_DECLARE_ALLOCATOR(ObservableArray);
18
19
public:
20
    static JS::NonnullGCPtr<ObservableArray> create(JS::Realm& realm);
21
22
    virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver, JS::CacheablePropertyMetadata* metadata = nullptr) override;
23
    virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const& property_key) override;
24
25
    using SetAnIndexedValueCallbackFunction = Function<ExceptionOr<void>(JS::Value&)>;
26
    using DeleteAnIndexedValueCallbackFunction = Function<ExceptionOr<void>()>;
27
28
    void set_on_set_an_indexed_value_callback(SetAnIndexedValueCallbackFunction&& callback);
29
    void set_on_delete_an_indexed_value_callback(DeleteAnIndexedValueCallbackFunction&& callback);
30
31
    JS::ThrowCompletionOr<void> append(JS::Value value);
32
    void clear();
33
34
    template<typename T, typename Callback>
35
    void for_each(Callback callback)
36
0
    {
37
0
        for (auto& entry : indexed_properties()) {
38
0
            auto value_and_attributes = indexed_properties().storage()->get(entry.index());
39
0
            if (value_and_attributes.has_value()) {
40
0
                auto& style_sheet = verify_cast<T>(value_and_attributes->value.as_object());
41
0
                callback(style_sheet);
42
0
            }
43
0
        }
44
0
    }
Unexecuted instantiation: Document.cpp:void Web::WebIDL::ObservableArray::for_each<Web::CSS::CSSStyleSheet, Web::DOM::Document::for_each_active_css_style_sheet(AK::Function<void (Web::CSS::CSSStyleSheet&, JS::GCPtr<Web::DOM::ShadowRoot>)>&&) const::$_1>(Web::DOM::Document::for_each_active_css_style_sheet(AK::Function<void (Web::CSS::CSSStyleSheet&, JS::GCPtr<Web::DOM::ShadowRoot>)>&&) const::$_1)
Unexecuted instantiation: Document.cpp:void Web::WebIDL::ObservableArray::for_each<Web::CSS::CSSStyleSheet, Web::DOM::Document::get_style_sheet_source(Web::CSS::StyleSheetIdentifier const&) const::$_0>(Web::DOM::Document::get_style_sheet_source(Web::CSS::StyleSheetIdentifier const&) const::$_0)
Unexecuted instantiation: ShadowRoot.cpp:void Web::WebIDL::ObservableArray::for_each<Web::CSS::CSSStyleSheet, Web::DOM::ShadowRoot::for_each_css_style_sheet(AK::Function<void (Web::CSS::CSSStyleSheet&)>&&) const::$_0>(Web::DOM::ShadowRoot::for_each_css_style_sheet(AK::Function<void (Web::CSS::CSSStyleSheet&)>&&) const::$_0)
45
46
    explicit ObservableArray(Object& prototype);
47
48
    virtual void visit_edges(JS::Cell::Visitor&) override;
49
50
private:
51
    using SetAnIndexedValueCallbackHeapFunction = JS::HeapFunction<SetAnIndexedValueCallbackFunction::FunctionType>;
52
    using DeleteAnIndexedValueCallbackHeapFunction = JS::HeapFunction<DeleteAnIndexedValueCallbackFunction::FunctionType>;
53
54
    JS::GCPtr<SetAnIndexedValueCallbackHeapFunction> m_on_set_an_indexed_value;
55
    JS::GCPtr<DeleteAnIndexedValueCallbackHeapFunction> m_on_delete_an_indexed_value;
56
};
57
58
}