1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

LibWeb: Remove unecessary dependence on Window from DOM and WebIDL

These classes only needed Window to get at its realm. Pass a realm
directly to construct DOM and WebIDL classes.

This change importantly removes the guarantee that a Document will
always have a non-null Window object. Only Documents created by a
BrowsingContext will have a non-null Window object. Documents created by
for example, DocumentFragment, will not have a Window (soon).

This incremental commit leaves some workarounds in place to keep other
parts of the code building.
This commit is contained in:
Andrew Kaster 2022-09-25 16:15:49 -06:00 committed by Linus Groh
parent 8407bf60c5
commit 8de7e49a56
56 changed files with 364 additions and 326 deletions

View file

@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/DOM/DOMImplementation.h>
#include <LibWeb/DOM/Document.h>
@ -12,19 +13,18 @@
#include <LibWeb/DOM/ElementFactory.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/Origin.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Namespace.h>
namespace Web::DOM {
JS::NonnullGCPtr<DOMImplementation> DOMImplementation::create(Document& document)
{
auto& window = document.window();
return *window.heap().allocate<DOMImplementation>(document.realm(), document);
auto& realm = document.realm();
return *realm.heap().allocate<DOMImplementation>(realm, document);
}
DOMImplementation::DOMImplementation(Document& document)
: PlatformObject(document.window().cached_web_prototype("DOMImplementation"))
: PlatformObject(Bindings::cached_web_prototype(document.realm(), "DOMImplementation"))
, m_document(document)
{
}
@ -41,7 +41,7 @@ void DOMImplementation::visit_edges(Cell::Visitor& visitor)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_document(String const& namespace_, String const& qualified_name, JS::GCPtr<DocumentType> doctype) const
{
// FIXME: This should specifically be an XML document.
auto xml_document = Document::create(Bindings::main_thread_internal_window_object());
auto xml_document = Document::create(realm());
xml_document->set_ready_for_post_load_tasks(true);
@ -71,7 +71,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_docume
// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(String const& title) const
{
auto html_document = Document::create(Bindings::main_thread_internal_window_object());
auto html_document = Document::create(realm());
html_document->set_content_type("text/html");
html_document->set_ready_for_post_load_tasks(true);
@ -105,7 +105,7 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(String const&
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentType>> DOMImplementation::create_document_type(String const& qualified_name, String const& public_id, String const& system_id)
{
TRY(Document::validate_qualified_name(global_object(), qualified_name));
TRY(Document::validate_qualified_name(realm(), qualified_name));
auto document_type = DocumentType::create(document());
document_type->set_name(qualified_name);
document_type->set_public_id(public_id);