Skip to content

Truly independent web browser

LibWeb: Add internals.isInRealmOfDestroyedDocument()

Andreas Kling42dd74e78f07
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index f3e60c79b5d..6d136c11f9e 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -2384,6 +2384,14 @@ Vector<String> Internals::documents_in_this_process()
return urls;
}
+bool Internals::is_in_realm_of_destroyed_document(JS::Object& object)
+{
+ auto* window = HTML::window_from_global_object(HTML::relevant_global_object(object));
+ if (!window)
+ return false;
+ return window->associated_document().has_been_destroyed();
+}
+
void Internals::close_tab_through_ui_process()
{
window().associated_document().page().client().close_tab_for_testing();
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index bc06188ecf8..6835db1a3ef 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -255,6 +255,7 @@ public:
void crash_remote_frame_processes();
i32 web_content_process_id();
Vector<String> documents_in_this_process();
+ bool is_in_realm_of_destroyed_document(JS::Object&);
void close_tab_through_ui_process();
void stop_loading_through_ui_process();
void reload_through_ui_process();
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index c71f3e8f62b..cabe5b1728c 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -285,6 +285,8 @@ interface Internals {
long webContentProcessId();
// The URLs of the documents this process has not collected yet, whether or not they are still displayed.
sequence<USVString> documentsInThisProcess();
+ // Whether the object lives in the realm of a window whose document has been destroyed, which the object keeps alive.
+ boolean isInRealmOfDestroyedDocument(object object);
// Closes this tab as the browser's close button does when it has no beforeunload check to run.
undefined closeTabThroughUIProcess();
// Stops loading and reloads as the browser's Stop and Reload buttons do.