mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
LibWeb: Implement performance.mark and performance.clearMarks
This commit is contained in:
parent
89ebef9730
commit
cbe0901706
13 changed files with 341 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/HighResolutionTime/Performance.h>
|
||||
#include <LibWeb/NavigationTiming/PerformanceTiming.h>
|
||||
#include <LibWeb/PerformanceTimeline/EntryTypes.h>
|
||||
|
||||
namespace Web::HighResolutionTime {
|
||||
|
||||
|
@ -50,6 +51,44 @@ double Performance::time_origin() const
|
|||
return static_cast<double>(m_timer.origin_time().to_milliseconds());
|
||||
}
|
||||
|
||||
// https://w3c.github.io/user-timing/#mark-method
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<UserTiming::PerformanceMark>> Performance::mark(String const& mark_name, UserTiming::PerformanceMarkOptions const& mark_options)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 1. Run the PerformanceMark constructor and let entry be the newly created object.
|
||||
auto entry = TRY(UserTiming::PerformanceMark::construct_impl(realm, mark_name, mark_options));
|
||||
|
||||
// 2. Queue entry.
|
||||
auto* window_or_worker = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&realm.global_object());
|
||||
VERIFY(window_or_worker);
|
||||
TRY(window_or_worker->queue_performance_entry(entry));
|
||||
|
||||
// 3. Add entry to the performance entry buffer.
|
||||
// FIXME: This seems to be a holdover from moving to the `queue` structure for PerformanceObserver, as this would cause a double append.
|
||||
|
||||
// 4. Return entry.
|
||||
return entry;
|
||||
}
|
||||
|
||||
void Performance::clear_marks(Optional<String> mark_name)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
auto* window_or_worker = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&realm.global_object());
|
||||
VERIFY(window_or_worker);
|
||||
|
||||
// 1. If markName is omitted, remove all PerformanceMark objects from the performance entry buffer.
|
||||
if (!mark_name.has_value()) {
|
||||
window_or_worker->clear_performance_entry_buffer({}, PerformanceTimeline::EntryTypes::mark);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Otherwise, remove all PerformanceMark objects listed in the performance entry buffer whose name is markName.
|
||||
window_or_worker->remove_entries_from_performance_entry_buffer({}, PerformanceTimeline::EntryTypes::mark, mark_name.value());
|
||||
|
||||
// 3. Return undefined.
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/performance-timeline/#getentries-method
|
||||
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> Performance::get_entries() const
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <LibCore/ElapsedTimer.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/UserTiming/PerformanceMark.h>
|
||||
|
||||
namespace Web::HighResolutionTime {
|
||||
|
||||
|
@ -23,6 +24,9 @@ public:
|
|||
|
||||
JS::GCPtr<NavigationTiming::PerformanceTiming> timing();
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<UserTiming::PerformanceMark>> mark(String const& mark_name, UserTiming::PerformanceMarkOptions const& mark_options = {});
|
||||
void clear_marks(Optional<String> mark_name);
|
||||
|
||||
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries() const;
|
||||
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_type(String const& type) const;
|
||||
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_name(String const& name, Optional<String> type) const;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#import <HighResolutionTime/DOMHighResTimeStamp.idl>
|
||||
#import <NavigationTiming/PerformanceTiming.idl>
|
||||
#import <PerformanceTimeline/PerformanceEntry.idl>
|
||||
#import <UserTiming/PerformanceMark.idl>
|
||||
|
||||
// https://www.w3.org/TR/performance-timeline/#dom-performanceentrylist
|
||||
typedef sequence<PerformanceEntry> PerformanceEntryList;
|
||||
|
@ -13,6 +14,14 @@ interface Performance : EventTarget {
|
|||
readonly attribute DOMHighResTimeStamp timeOrigin;
|
||||
|
||||
readonly attribute PerformanceTiming timing;
|
||||
|
||||
// https://w3c.github.io/user-timing/#extensions-performance-interface
|
||||
// "User Timing" extensions to the Performance interface
|
||||
PerformanceMark mark(DOMString markName, optional PerformanceMarkOptions markOptions = {});
|
||||
undefined clearMarks(optional DOMString markName);
|
||||
// FIXME: PerformanceMeasure measure(DOMString measureName, optional (DOMString or PerformanceMeasureOptions) startOrMeasureOptions = {}, optional DOMString endMark);
|
||||
// FIXME: undefined clearMeasures(optional DOMString measureName);
|
||||
|
||||
// https://www.w3.org/TR/performance-timeline/#extensions-to-the-performance-interface
|
||||
// "Performance Timeline" extensions to the Performance interface
|
||||
PerformanceEntryList getEntries();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue