diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
index 3fc9b9e2f71..35094f3f9d6 100644
--- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
@@ -592,8 +592,9 @@ void WindowOrWorkerGlobalScopeMixin::run_steps_after_a_timeout_impl(i32 timeout,
// https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance
JS::NonnullGCPtr WindowOrWorkerGlobalScopeMixin::performance()
{
+ auto& realm = this_impl().realm();
if (!m_performance)
- m_performance = this_impl().heap().allocate(this_impl().realm(), *this);
+ m_performance = this_impl().heap().allocate(realm, realm);
return JS::NonnullGCPtr { *m_performance };
}
diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp
index 9e54cd96a18..bb79f6a3f06 100644
--- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp
+++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp
@@ -20,9 +20,8 @@ namespace Web::HighResolutionTime {
JS_DEFINE_ALLOCATOR(Performance);
-Performance::Performance(HTML::WindowOrWorkerGlobalScopeMixin& window_or_worker)
- : DOM::EventTarget(window_or_worker.this_impl().realm())
- , m_window_or_worker(window_or_worker)
+Performance::Performance(JS::Realm& realm)
+ : DOM::EventTarget(realm)
, m_timer(Core::TimerType::Precise)
{
m_timer.start();
@@ -40,13 +39,13 @@ void Performance::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_timing);
- visitor.visit(m_window_or_worker->this_impl());
}
JS::GCPtr Performance::timing()
{
+ auto& realm = this->realm();
if (!m_timing)
- m_timing = heap().allocate(realm(), *m_window_or_worker);
+ m_timing = heap().allocate(realm, realm);
return m_timing;
}
@@ -64,9 +63,7 @@ WebIDL::ExceptionOr> Performance::
auto entry = TRY(UserTiming::PerformanceMark::construct_impl(realm, mark_name, mark_options));
// 2. Queue entry.
- auto* window_or_worker = dynamic_cast(&realm.global_object());
- VERIFY(window_or_worker);
- window_or_worker->queue_performance_entry(entry);
+ 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.
@@ -77,18 +74,14 @@ WebIDL::ExceptionOr> Performance::
void Performance::clear_marks(Optional mark_name)
{
- auto& realm = this->realm();
- auto* window_or_worker = dynamic_cast(&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);
+ 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());
+ window_or_worker().remove_entries_from_performance_entry_buffer({}, PerformanceTimeline::EntryTypes::mark, mark_name.value());
// 3. Return undefined.
}
@@ -145,10 +138,7 @@ WebIDL::ExceptionOr Performance::conver
// 2. Otherwise, if mark is a DOMString, let end time be the value of the startTime attribute from the most recent occurrence
// of a PerformanceMark object in the performance entry buffer whose name is mark. If no matching entry is found, throw a
// SyntaxError.
- auto* window_or_worker = dynamic_cast(&realm.global_object());
- VERIFY(window_or_worker);
-
- auto& tuple = window_or_worker->relevant_performance_entry_tuple(PerformanceTimeline::EntryTypes::mark);
+ auto& tuple = window_or_worker().relevant_performance_entry_tuple(PerformanceTimeline::EntryTypes::mark);
auto& performance_entry_buffer = tuple.performance_entry_buffer;
auto maybe_entry = performance_entry_buffer.last_matching([&mark_string](JS::Handle const& entry) {
@@ -176,8 +166,6 @@ WebIDL::ExceptionOr Performance::conver
WebIDL::ExceptionOr> Performance::measure(String const& measure_name, Variant const& start_or_measure_options, Optional end_mark)
{
auto& realm = this->realm();
- auto* window_or_worker = dynamic_cast(&realm.global_object());
- VERIFY(window_or_worker);
auto& vm = this->vm();
// 1. If startOrMeasureOptions is a PerformanceMeasureOptions object and at least one of start, end, duration, and detail
@@ -296,7 +284,7 @@ WebIDL::ExceptionOr> Performanc
auto entry = realm.heap().allocate(realm, realm, measure_name, start_time, duration, detail);
// 10. Queue entry.
- window_or_worker->queue_performance_entry(entry);
+ window_or_worker().queue_performance_entry(entry);
// 11. 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.
@@ -308,18 +296,14 @@ WebIDL::ExceptionOr> Performanc
// https://w3c.github.io/user-timing/#dom-performance-clearmeasures
void Performance::clear_measures(Optional measure_name)
{
- auto& realm = this->realm();
- auto* window_or_worker = dynamic_cast(&realm.global_object());
- VERIFY(window_or_worker);
-
// 1. If measureName is omitted, remove all PerformanceMeasure objects in the performance entry buffer.
if (!measure_name.has_value()) {
- window_or_worker->clear_performance_entry_buffer({}, PerformanceTimeline::EntryTypes::measure);
+ window_or_worker().clear_performance_entry_buffer({}, PerformanceTimeline::EntryTypes::measure);
return;
}
// 2. Otherwise remove all PerformanceMeasure objects listed in the performance entry buffer whose name is measureName.
- window_or_worker->remove_entries_from_performance_entry_buffer({}, PerformanceTimeline::EntryTypes::measure, measure_name.value());
+ window_or_worker().remove_entries_from_performance_entry_buffer({}, PerformanceTimeline::EntryTypes::measure, measure_name.value());
// 3. Return undefined.
}
@@ -327,41 +311,44 @@ void Performance::clear_measures(Optional measure_name)
// https://www.w3.org/TR/performance-timeline/#getentries-method
WebIDL::ExceptionOr>> Performance::get_entries() const
{
- auto& realm = this->realm();
auto& vm = this->vm();
- auto* window_or_worker = dynamic_cast(&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 {}, /* type= */ Optional {}));
+ return TRY_OR_THROW_OOM(vm, window_or_worker().filter_buffer_map_by_name_and_type(/* name= */ Optional {}, /* type= */ Optional {}));
}
// https://www.w3.org/TR/performance-timeline/#dom-performance-getentriesbytype
WebIDL::ExceptionOr>> Performance::get_entries_by_type(String const& type) const
{
- auto& realm = this->realm();
auto& vm = this->vm();
- auto* window_or_worker = dynamic_cast(&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 {}, type));
+ return TRY_OR_THROW_OOM(vm, window_or_worker().filter_buffer_map_by_name_and_type(/* name= */ Optional {}, type));
}
// https://www.w3.org/TR/performance-timeline/#dom-performance-getentriesbyname
WebIDL::ExceptionOr>> Performance::get_entries_by_name(String const& name, Optional type) const
{
- auto& realm = this->realm();
auto& vm = this->vm();
- auto* window_or_worker = dynamic_cast(&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));
+ return TRY_OR_THROW_OOM(vm, window_or_worker().filter_buffer_map_by_name_and_type(name, type));
+}
+
+HTML::WindowOrWorkerGlobalScopeMixin& Performance::window_or_worker()
+{
+ auto* window_or_worker = dynamic_cast(&realm().global_object());
+ VERIFY(window_or_worker);
+ return *window_or_worker;
+}
+
+HTML::WindowOrWorkerGlobalScopeMixin const& Performance::window_or_worker() const
+{
+ return const_cast(this)->window_or_worker();
}
}
diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h
index df748126837..d301bbee98a 100644
--- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h
+++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h
@@ -37,7 +37,10 @@ public:
WebIDL::ExceptionOr>> get_entries_by_name(String const& name, Optional type) const;
private:
- explicit Performance(HTML::WindowOrWorkerGlobalScopeMixin&);
+ explicit Performance(JS::Realm&);
+
+ HTML::WindowOrWorkerGlobalScopeMixin& window_or_worker();
+ HTML::WindowOrWorkerGlobalScopeMixin const& window_or_worker() const;
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
@@ -45,7 +48,6 @@ private:
WebIDL::ExceptionOr convert_name_to_timestamp(JS::Realm& realm, String const& name);
WebIDL::ExceptionOr convert_mark_to_timestamp(JS::Realm& realm, Variant mark);
- JS::NonnullGCPtr m_window_or_worker;
JS::GCPtr m_timing;
Core::ElapsedTimer m_timer;
diff --git a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp
index 705be16612e..b21d8c73cf9 100644
--- a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp
+++ b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp
@@ -10,9 +10,8 @@ namespace Web::NavigationTiming {
JS_DEFINE_ALLOCATOR(PerformanceTiming);
-PerformanceTiming::PerformanceTiming(HTML::WindowOrWorkerGlobalScopeMixin& window_or_worker)
- : PlatformObject(window_or_worker.this_impl().realm())
- , m_window_or_worker(window_or_worker)
+PerformanceTiming::PerformanceTiming(JS::Realm& realm)
+ : PlatformObject(realm)
{
}
@@ -24,11 +23,4 @@ void PerformanceTiming::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(PerformanceTiming);
}
-void PerformanceTiming::visit_edges(Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- if (m_window_or_worker)
- visitor.visit(m_window_or_worker->this_impl());
-}
-
}
diff --git a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h
index c92db2e8d2f..0d9c9bb3a91 100644
--- a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h
+++ b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h
@@ -42,12 +42,9 @@ public:
u64 load_event_end() { return 0; }
private:
- explicit PerformanceTiming(HTML::WindowOrWorkerGlobalScopeMixin&);
+ explicit PerformanceTiming(JS::Realm&);
virtual void initialize(JS::Realm&) override;
- virtual void visit_edges(Cell::Visitor&) override;
-
- JS::GCPtr m_window_or_worker;
};
}