Coverage Report

Created: 2026-09-26 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2021-2024, Andreas Kling <kling@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/DistinctNumeric.h>
10
#include <LibJS/Heap/Cell.h>
11
#include <LibJS/Heap/CellAllocator.h>
12
#include <LibJS/SafeFunction.h>
13
#include <LibWeb/Forward.h>
14
15
namespace Web::HTML {
16
17
struct UniqueTaskSource;
18
19
AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, TaskID, Comparison);
20
21
class Task final : public JS::Cell {
22
    JS_CELL(Task, JS::Cell);
23
    JS_DECLARE_ALLOCATOR(Task);
24
25
public:
26
    // https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources
27
    enum class Source {
28
        Unspecified,
29
        DOMManipulation,
30
        UserInteraction,
31
        Networking,
32
        HistoryTraversal,
33
        IdleTask,
34
        PostedMessage,
35
        Microtask,
36
        TimerTask,
37
        JavaScriptEngine,
38
39
        // https://html.spec.whatwg.org/multipage/webappapis.html#navigation-and-traversal-task-source
40
        NavigationAndTraversal,
41
42
        // https://w3c.github.io/FileAPI/#fileReadingTaskSource
43
        FileReading,
44
45
        // https://www.w3.org/TR/intersection-observer/#intersectionobserver-task-source
46
        IntersectionObserver,
47
48
        // https://w3c.github.io/performance-timeline/#dfn-performance-timeline-task-source
49
        PerformanceTimeline,
50
51
        // https://html.spec.whatwg.org/multipage/canvas.html#canvas-blob-serialisation-task-source
52
        CanvasBlobSerializationTask,
53
54
        // https://w3c.github.io/clipboard-apis/#clipboard-task-source
55
        Clipboard,
56
57
        // https://w3c.github.io/permissions/#permissions-task-source
58
        Permissions,
59
60
        // https://drafts.csswg.org/css-font-loading/#task-source
61
        FontLoading,
62
63
        // https://html.spec.whatwg.org/multipage/server-sent-events.html#remote-event-task-source
64
        RemoteEvent,
65
66
        // !!! IMPORTANT: Keep this field last!
67
        // This serves as the base value of all unique task sources.
68
        // Some elements, such as the HTMLMediaElement, must have a unique task source per instance.
69
        UniqueTaskSourceStart
70
    };
71
72
    static JS::NonnullGCPtr<Task> create(JS::VM&, Source, JS::GCPtr<DOM::Document const>, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps);
73
74
    virtual ~Task() override;
75
76
0
    [[nodiscard]] TaskID id() const { return m_id; }
77
0
    Source source() const { return m_source; }
78
    void execute();
79
80
    DOM::Document const* document() const;
81
82
    bool is_runnable() const;
83
84
private:
85
    Task(Source, JS::GCPtr<DOM::Document const>, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps);
86
87
    virtual void visit_edges(Visitor&) override;
88
89
    TaskID m_id {};
90
    Source m_source { Source::Unspecified };
91
    JS::NonnullGCPtr<JS::HeapFunction<void()>> m_steps;
92
    JS::GCPtr<DOM::Document const> m_document;
93
};
94
95
struct UniqueTaskSource {
96
    UniqueTaskSource();
97
    ~UniqueTaskSource();
98
99
    Task::Source const source;
100
};
101
102
}