1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

LibWeb: Introduce Performance Timeline and its Performance functions

This commit is contained in:
Luke Wilde 2023-03-22 19:12:57 +00:00 committed by Linus Groh
parent 4c3f1481ea
commit 31b507afbf
16 changed files with 381 additions and 1 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -49,4 +50,44 @@ double Performance::time_origin() const
return static_cast<double>(m_timer.origin_time().to_milliseconds());
}
// https://www.w3.org/TR/performance-timeline/#getentries-method
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> Performance::get_entries() const
{
auto& realm = this->realm();
auto& vm = this->vm();
auto* window_or_worker = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&realm.global_object());
VERIFY(window_or_worker);
// Returns a PerformanceEntryList object returned by the filter buffer map by name and type algorithm with name and
// type set to null.
return TRY_OR_THROW_OOM(vm, window_or_worker->filter_buffer_map_by_name_and_type(/* name= */ Optional<String> {}, /* type= */ Optional<String> {}));
}
// https://www.w3.org/TR/performance-timeline/#dom-performance-getentriesbytype
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> Performance::get_entries_by_type(String const& type) const
{
auto& realm = this->realm();
auto& vm = this->vm();
auto* window_or_worker = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&realm.global_object());
VERIFY(window_or_worker);
// Returns a PerformanceEntryList object returned by filter buffer map by name and type algorithm with name set to null,
// and type set to the method's input type parameter.
return TRY_OR_THROW_OOM(vm, window_or_worker->filter_buffer_map_by_name_and_type(/* name= */ Optional<String> {}, type));
}
// https://www.w3.org/TR/performance-timeline/#dom-performance-getentriesbyname
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> Performance::get_entries_by_name(String const& name, Optional<String> type) const
{
auto& realm = this->realm();
auto& vm = this->vm();
auto* window_or_worker = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&realm.global_object());
VERIFY(window_or_worker);
// Returns a PerformanceEntryList object returned by filter buffer map by name and type algorithm with name set to the
// method input name parameter, and type set to null if optional entryType is omitted, or set to the method's input type
// parameter otherwise.
return TRY_OR_THROW_OOM(vm, window_or_worker->filter_buffer_map_by_name_and_type(name, type));
}
}