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.
This commit is contained in:
Tim Ledbetter 2024-03-30 10:04:31 +00:00 committed by Andreas Kling
parent eebdc7bc88
commit 558fef237c
3 changed files with 15 additions and 2 deletions

View file

@ -0,0 +1 @@
PASS (didn't crash)

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
test(() => {
const divElement = document.createElement("div");
const newDocument = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html");
newDocument.documentElement.appendChild(divElement)
animation = divElement.animate({}, {});
println("PASS (didn't crash)");
});
</script>

View file

@ -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<HTML::WindowOrWorkerGlobalScopeMixin*>(&realm().global_object());
VERIFY(window_or_worker);
update_animations_and_send_events(window_or_worker->performance()->now());
}));
}