From 46ec3681a43f92f45c30d4b274823eaf50073078 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 25 Apr 2024 14:49:56 +1200 Subject: [PATCH] LibWeb: Verify document is fully ready in AudioContext This was just a trival FIXME to resolve as I was in the area. --- .../Libraries/LibWeb/WebAudio/AudioContext.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp b/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp index 6551a41507c..59c67f0ed04 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -107,7 +108,10 @@ WebIDL::ExceptionOr> AudioContext::resume() auto& realm = this->realm(); auto& vm = realm.vm(); - // FIXME: 1. If this's relevant global object's associated Document is not fully active then return a promise rejected with "InvalidStateError" DOMException. + // 1. If this's relevant global object's associated Document is not fully active then return a promise rejected with "InvalidStateError" DOMException. + auto const& associated_document = verify_cast(HTML::relevant_global_object(*this)).associated_document(); + if (!associated_document.is_fully_active()) + return WebIDL::InvalidStateError::create(realm, "Document is not fully active"_fly_string); // 2. Let promise be a new Promise. auto promise = WebIDL::create_promise(realm); @@ -189,7 +193,10 @@ WebIDL::ExceptionOr> AudioContext::suspend() auto& realm = this->realm(); auto& vm = realm.vm(); - // FIXME: 1. If this's relevant global object's associated Document is not fully active then return a promise rejected with "InvalidStateError" DOMException. + // 1. If this's relevant global object's associated Document is not fully active then return a promise rejected with "InvalidStateError" DOMException. + auto const& associated_document = verify_cast(HTML::relevant_global_object(*this)).associated_document(); + if (!associated_document.is_fully_active()) + return WebIDL::InvalidStateError::create(realm, "Document is not fully active"_fly_string); // 2. Let promise be a new Promise. auto promise = WebIDL::create_promise(realm); @@ -243,7 +250,10 @@ WebIDL::ExceptionOr> AudioContext::close() { auto& realm = this->realm(); - // FIXME: 1. If this's relevant global object's associated Document is not fully active then return a promise rejected with "InvalidStateError" DOMException. + // 1. If this's relevant global object's associated Document is not fully active then return a promise rejected with "InvalidStateError" DOMException. + auto const& associated_document = verify_cast(HTML::relevant_global_object(*this)).associated_document(); + if (!associated_document.is_fully_active()) + return WebIDL::InvalidStateError::create(realm, "Document is not fully active"_fly_string); // 2. Let promise be a new Promise. auto promise = WebIDL::create_promise(realm);