From 63d9ed9d8c4fafd569e042e0698bd5dc844a1b29 Mon Sep 17 00:00:00 2001 From: Benjamin Bjerken Date: Tue, 15 Oct 2024 12:39:47 +0200 Subject: [PATCH] LibWeb: Fix CloseWatcher constructor for detached iframes This fixes the last subtest in /close-watcher/frame-removal.html :) --- .../HTML/CloseWatcher-detached-iframe.txt | 1 + .../HTML/CloseWatcher-detached-iframe.html | 25 +++++++++++++++++++ .../Libraries/LibWeb/HTML/CloseWatcher.cpp | 10 ++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/CloseWatcher-detached-iframe.txt create mode 100644 Tests/LibWeb/Text/input/HTML/CloseWatcher-detached-iframe.html diff --git a/Tests/LibWeb/Text/expected/HTML/CloseWatcher-detached-iframe.txt b/Tests/LibWeb/Text/expected/HTML/CloseWatcher-detached-iframe.txt new file mode 100644 index 00000000000..7ef22e9a431 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/CloseWatcher-detached-iframe.txt @@ -0,0 +1 @@ +PASS diff --git a/Tests/LibWeb/Text/input/HTML/CloseWatcher-detached-iframe.html b/Tests/LibWeb/Text/input/HTML/CloseWatcher-detached-iframe.html new file mode 100644 index 00000000000..f38db99981c --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/CloseWatcher-detached-iframe.html @@ -0,0 +1,25 @@ + + diff --git a/Userland/Libraries/LibWeb/HTML/CloseWatcher.cpp b/Userland/Libraries/LibWeb/HTML/CloseWatcher.cpp index 8e226f4ce83..d1a5f2d8062 100644 --- a/Userland/Libraries/LibWeb/HTML/CloseWatcher.cpp +++ b/Userland/Libraries/LibWeb/HTML/CloseWatcher.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace Web::HTML { @@ -41,9 +42,14 @@ JS::NonnullGCPtr CloseWatcher::establish(HTML::Window& window) // https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher WebIDL::ExceptionOr> CloseWatcher::construct_impl(JS::Realm& realm, CloseWatcherOptions const& options) { - // 1. If this's relevant global object's associated Document is not fully active, then return an "InvalidStateError" DOMException. - // FIXME: Not in spec explicitly, but this should account for detached iframes too. See /close-watcher/frame-removal.html WPT. auto& window = verify_cast(realm.global_object()); + + // NOTE: Not in spec explicitly, but this should account for detached iframes too. See /close-watcher/frame-removal.html WPT. + auto navigable = window.navigable(); + if (navigable && navigable->has_been_destroyed()) + return WebIDL::InvalidStateError::create(realm, "The iframe has been detached"_string); + + // 1. If this's relevant global object's associated Document is not fully active, then return an "InvalidStateError" DOMException. if (!window.associated_document().is_fully_active()) return WebIDL::InvalidStateError::create(realm, "The document is not fully active."_string);