Coverage Report

Created: 2025-08-28 06:26

/src/serenity/Userland/Libraries/LibWeb/UserTiming/PerformanceMark.h
Line
Count
Source (jump to first uncovered line)
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/#ref-for-dom-performancemarkoptions-1
14
struct PerformanceMarkOptions {
15
    JS::Value detail { JS::js_null() };
16
    Optional<HighResolutionTime::DOMHighResTimeStamp> start_time;
17
};
18
19
// https://w3c.github.io/user-timing/#dom-performancemark
20
class PerformanceMark final : public PerformanceTimeline::PerformanceEntry {
21
    WEB_PLATFORM_OBJECT(PerformanceMark, PerformanceTimeline::PerformanceEntry);
22
    JS_DECLARE_ALLOCATOR(PerformanceMark);
23
24
public:
25
    virtual ~PerformanceMark();
26
27
    static WebIDL::ExceptionOr<JS::NonnullGCPtr<PerformanceMark>> construct_impl(JS::Realm&, String const& mark_name, PerformanceMarkOptions const& mark_options = {});
28
29
    // NOTE: These three functions are answered by the registry for the given entry type.
30
    // https://w3c.github.io/timing-entrytypes-registry/#registry
31
32
    // https://w3c.github.io/timing-entrytypes-registry/#dfn-availablefromtimeline
33
0
    static PerformanceTimeline::AvailableFromTimeline available_from_timeline() { return PerformanceTimeline::AvailableFromTimeline::Yes; }
34
35
    // https://w3c.github.io/timing-entrytypes-registry/#dfn-maxbuffersize
36
    // NOTE: The empty state represents Infinite size.
37
0
    static Optional<u64> max_buffer_size() { return OptionalNone {}; }
38
39
    // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
40
0
    virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
41
42
    virtual FlyString const& entry_type() const override;
43
44
0
    JS::Value detail() const { return m_detail; }
45
46
private:
47
    PerformanceMark(JS::Realm&, String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail);
48
49
    virtual void initialize(JS::Realm&) override;
50
    virtual void visit_edges(JS::Cell::Visitor&) override;
51
52
    // https://w3c.github.io/user-timing/#dom-performancemark-detail
53
    JS::Value m_detail { JS::js_null() };
54
};
55
56
}