1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
ladybird/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cpp
Andreas Kling a6dfc74e93 LibWeb: Only set prototype once for object with IDL interface
Before this change, we were going through the chain of base classes for
each IDL interface object and having them set the prototype to their
prototype.

Instead of doing that, reorder things so that we set the right prototype
immediately in Foo::initialize(), and then don't bother in all the base
class overrides.

This knocks off a ~1% profile item on Speedometer 3.
2025-04-20 18:43:11 +02:00

125 lines
4.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2024, Noah Bright <noah.bright.1@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/PerformanceEventTimingPrototype.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/EventTiming/PerformanceEventTiming.h>
#include <LibWeb/PerformanceTimeline/EntryTypes.h>
namespace Web::EventTiming {
GC_DEFINE_ALLOCATOR(PerformanceEventTiming);
// https://www.w3.org/TR/event-timing/#sec-init-event-timing
PerformanceEventTiming::PerformanceEventTiming(JS::Realm& realm, String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration,
DOM::Event const& event, HighResolutionTime::DOMHighResTimeStamp processing_start, unsigned long long interaction_id)
: PerformanceTimeline::PerformanceEntry(realm, name, start_time, duration)
, m_entry_type(PerformanceTimeline::EntryTypes::event)
, m_start_time(event.time_stamp())
, m_processing_start(processing_start)
, m_cancelable(event.cancelable())
, m_interaction_id(interaction_id)
{
}
PerformanceEventTiming::~PerformanceEventTiming() = default;
FlyString const& PerformanceEventTiming::entry_type() const
{
return m_entry_type;
}
HighResolutionTime::DOMHighResTimeStamp PerformanceEventTiming::processing_end() const
{
dbgln("FIXME: Implement PerformanceEventTiming processing_end()");
return 0;
}
HighResolutionTime::DOMHighResTimeStamp PerformanceEventTiming::processing_start() const
{
dbgln("FIXME: Implement PerformanceEventTiming processing_start()");
return 0;
}
bool PerformanceEventTiming::cancelable() const
{
return m_cancelable;
}
JS::ThrowCompletionOr<GC::Ptr<DOM::Node>> PerformanceEventTiming::target()
{
dbgln("FIXME: Implement PerformanceEventTiming::PerformanceEventTiming target()");
return nullptr;
}
unsigned long long PerformanceEventTiming::interaction_id()
{
dbgln("FIXME: Implement PerformanceEventTiming interaction_id()");
return 0;
}
// https://www.w3.org/TR/event-timing/#sec-should-add-performanceeventtiming
PerformanceTimeline::ShouldAddEntry PerformanceEventTiming::should_add_performance_event_timing() const
{
dbgln("FIXME: Implement PerformanceEventTiming should_add_performance_event_timing()");
// 1. If entrys entryType attribute value equals to "first-input", return true.
if (entry_type() == "first-input")
return PerformanceTimeline::ShouldAddEntry::Yes;
// 2. Assert that entrys entryType attribute value equals "event".
VERIFY(entry_type() == "event");
// FIXME: 3. Let minDuration be computed as follows:
// FIXME: 3.1. If options is not present or if optionss durationThreshold is not present, let minDuration be 104.
// FIXME: 3.2. Otherwise, let minDuration be the maximum between 16 and optionss durationThreshold value.
// FIXME: 4. If entrys duration attribute value is greater than or equal to minDuration, return true.
// 5. Otherwise, return false.
return PerformanceTimeline::ShouldAddEntry::No;
}
// https://w3c.github.io/timing-entrytypes-registry/#dfn-availablefromtimeline
// FIXME: the output here depends on the type of the object instance, but this function is static
// the commented out if statement won't compile
PerformanceTimeline::AvailableFromTimeline PerformanceEventTiming::available_from_timeline()
{
dbgln("FIXME: Implement PerformanceEventTiming available_from_timeline()");
// if (entry_type() == "first-input")
return PerformanceTimeline::AvailableFromTimeline::Yes;
}
// https://w3c.github.io/timing-entrytypes-registry/#dfn-maxbuffersize
// FIXME: Same issue as available_from_timeline() above
Optional<u64> PerformanceEventTiming::max_buffer_size()
{
dbgln("FIXME: Implement PerformanceEventTiming max_buffer_size()");
if (true) //(entry_type() == "first-input")
return 1;
// else return 150;
}
// https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
PerformanceTimeline::ShouldAddEntry PerformanceEventTiming::should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&>) const
{
return should_add_performance_event_timing();
}
void PerformanceEventTiming::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(PerformanceEventTiming);
Base::initialize(realm);
}
void PerformanceEventTiming::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_event_target);
}
}