From 558fef237cb83385b175b01329008cdc0629deef Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 30 Mar 2024 10:04:31 +0000 Subject: [PATCH] LibWeb: Use the global object to access the performance object Previously, we were accessing the performance through the current window object. Thus caused a crash when `animate()` was called on an element within a document with no associated window object. The global object is now used to access the performance object in places where a window object is not guaranteed to exist. --- .../expected/WebAnimations/misc/animate-no-window.txt | 1 + .../input/WebAnimations/misc/animate-no-window.html | 11 +++++++++++ Userland/Libraries/LibWeb/DOM/Document.cpp | 5 +++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/WebAnimations/misc/animate-no-window.txt create mode 100644 Tests/LibWeb/Text/input/WebAnimations/misc/animate-no-window.html diff --git a/Tests/LibWeb/Text/expected/WebAnimations/misc/animate-no-window.txt b/Tests/LibWeb/Text/expected/WebAnimations/misc/animate-no-window.txt new file mode 100644 index 00000000000..aaecaf93c4a --- /dev/null +++ b/Tests/LibWeb/Text/expected/WebAnimations/misc/animate-no-window.txt @@ -0,0 +1 @@ +PASS (didn't crash) diff --git a/Tests/LibWeb/Text/input/WebAnimations/misc/animate-no-window.html b/Tests/LibWeb/Text/input/WebAnimations/misc/animate-no-window.html new file mode 100644 index 00000000000..f59a135a08c --- /dev/null +++ b/Tests/LibWeb/Text/input/WebAnimations/misc/animate-no-window.html @@ -0,0 +1,11 @@ + + + diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 8c75b7cee62..257987d39d2 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -4185,8 +4185,9 @@ void Document::ensure_animation_timer() m_animation_driver_timer->stop(); return; } - - update_animations_and_send_events(window()->performance()->now()); + auto* window_or_worker = dynamic_cast(&realm().global_object()); + VERIFY(window_or_worker); + update_animations_and_send_events(window_or_worker->performance()->now()); })); }