LibWeb: Allow the Performance object to be used by workers

This commit is contained in:
Tim Ledbetter 2024-03-30 10:04:31 +00:00 committed by Andreas Kling
commit eebdc7bc88
Notes: sideshowbarker 2024-07-17 16:42:19 +09:00
15 changed files with 49 additions and 32 deletions

View file

@ -20,9 +20,9 @@ namespace Web::HighResolutionTime {
JS_DEFINE_ALLOCATOR(Performance);
Performance::Performance(HTML::Window& window)
: DOM::EventTarget(window.realm())
, m_window(window)
Performance::Performance(HTML::WindowOrWorkerGlobalScopeMixin& window_or_worker)
: DOM::EventTarget(window_or_worker.this_impl().realm())
, m_window_or_worker(window_or_worker)
, m_timer(Core::TimerType::Precise)
{
m_timer.start();
@ -39,14 +39,14 @@ void Performance::initialize(JS::Realm& realm)
void Performance::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_window);
visitor.visit(m_timing);
visitor.visit(m_window_or_worker->this_impl());
}
JS::GCPtr<NavigationTiming::PerformanceTiming> Performance::timing()
{
if (!m_timing)
m_timing = heap().allocate<NavigationTiming::PerformanceTiming>(realm(), *m_window);
m_timing = heap().allocate<NavigationTiming::PerformanceTiming>(realm(), *m_window_or_worker);
return m_timing;
}

View file

@ -9,6 +9,7 @@
#include <LibCore/ElapsedTimer.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
#include <LibWeb/UserTiming/PerformanceMark.h>
#include <LibWeb/UserTiming/PerformanceMeasure.h>
@ -36,7 +37,7 @@ public:
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_name(String const& name, Optional<String> type) const;
private:
explicit Performance(HTML::Window&);
explicit Performance(HTML::WindowOrWorkerGlobalScopeMixin&);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
@ -44,7 +45,7 @@ private:
WebIDL::ExceptionOr<HighResolutionTime::DOMHighResTimeStamp> convert_name_to_timestamp(JS::Realm& realm, String const& name);
WebIDL::ExceptionOr<HighResolutionTime::DOMHighResTimeStamp> convert_mark_to_timestamp(JS::Realm& realm, Variant<String, HighResolutionTime::DOMHighResTimeStamp> mark);
JS::NonnullGCPtr<HTML::Window> m_window;
JS::NonnullGCPtr<HTML::WindowOrWorkerGlobalScopeMixin> m_window_or_worker;
JS::GCPtr<NavigationTiming::PerformanceTiming> m_timing;
Core::ElapsedTimer m_timer;