Coverage Report

Created: 2025-11-16 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/UserTiming/PerformanceMeasure.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
10
11
namespace Web::UserTiming {
12
13
// https://w3c.github.io/user-timing/#dom-performancemeasureoptions
14
struct PerformanceMeasureOptions {
15
    JS::Value detail { JS::js_undefined() };
16
    Optional<Variant<String, HighResolutionTime::DOMHighResTimeStamp>> start;
17
    Optional<HighResolutionTime::DOMHighResTimeStamp> duration;
18
    Optional<Variant<String, HighResolutionTime::DOMHighResTimeStamp>> end;
19
};
20
21
// https://w3c.github.io/user-timing/#dom-performancemeasure
22
class PerformanceMeasure final : public PerformanceTimeline::PerformanceEntry {
23
    WEB_PLATFORM_OBJECT(PerformanceMeasure, PerformanceTimeline::PerformanceEntry);
24
    JS_DECLARE_ALLOCATOR(PerformanceMeasure);
25
26
public:
27
    virtual ~PerformanceMeasure();
28
29
    [[nodiscard]] static JS::NonnullGCPtr<PerformanceMeasure> create(JS::Realm&, String const& measure_name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail);
30
31
    // NOTE: These three functions are answered by the registry for the given entry type.
32
    // https://w3c.github.io/timing-entrytypes-registry/#registry
33
34
    // https://w3c.github.io/timing-entrytypes-registry/#dfn-availablefromtimeline
35
0
    static PerformanceTimeline::AvailableFromTimeline available_from_timeline() { return PerformanceTimeline::AvailableFromTimeline::Yes; }
36
37
    // https://w3c.github.io/timing-entrytypes-registry/#dfn-maxbuffersize
38
    // NOTE: The empty state represents Infinite size.
39
0
    static Optional<u64> max_buffer_size() { return OptionalNone {}; }
40
41
    // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
42
0
    virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
43
44
    virtual FlyString const& entry_type() const override;
45
46
0
    JS::Value detail() const { return m_detail; }
47
48
private:
49
    PerformanceMeasure(JS::Realm&, String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail);
50
51
    virtual void initialize(JS::Realm&) override;
52
    virtual void visit_edges(JS::Cell::Visitor&) override;
53
54
    // https://w3c.github.io/user-timing/#dom-performancemeasure-detail
55
    JS::Value m_detail { JS::js_null() };
56
};
57
58
}