diff options
author | Andreas Kling <kling@serenityos.org> | 2021-12-09 12:51:05 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-09 21:28:52 +0100 |
commit | d368b0869822cb554238ed66d6e4cd9e8659f949 (patch) | |
tree | 2f200588c45f3ec3646124839d3394297304e4b1 /Userland/Libraries/LibWeb/DOM/DOMImplementation.h | |
parent | e1287a9a45f3b7faaa34dde0bf9357bd05d99679 (diff) | |
download | serenity-d368b0869822cb554238ed66d6e4cd9e8659f949.zip |
LibWeb: Make DOMImplementation forward its ref count to DOM::Document
This allows document.implementation to keep the underlying document
alive for as long as we need it (for example, if someone holds on to a
DOMImplementation JS wrapper after the document is GC'd.)
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/DOMImplementation.h')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/DOMImplementation.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.h b/Userland/Libraries/LibWeb/DOM/DOMImplementation.h index 34762c3dd9..e35ae20ead 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.h +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.h @@ -7,28 +7,30 @@ #pragma once #include <AK/NonnullRefPtr.h> +#include <AK/RefCountForwarder.h> #include <AK/RefCounted.h> #include <AK/Weakable.h> #include <LibWeb/Bindings/Wrappable.h> +#include <LibWeb/DOM/Document.h> namespace Web::DOM { class DOMImplementation final - : public RefCounted<DOMImplementation> + : public RefCountForwarder<Document> , public Weakable<DOMImplementation> , public Bindings::Wrappable { public: using WrapperType = Bindings::DOMImplementationWrapper; - static NonnullRefPtr<DOMImplementation> create(Document& document) + static NonnullOwnPtr<DOMImplementation> create(Badge<Document>, Document& document) { - return adopt_ref(*new DOMImplementation(document)); + return adopt_own(*new DOMImplementation(document)); } // FIXME: Add optional DocumentType once supported by IDL NonnullRefPtr<Document> create_document(const String&, const String&) const; NonnullRefPtr<Document> create_html_document(const String& title) const; - NonnullRefPtr<DocumentType> create_document_type(const String&, const String&, const String&) const; + NonnullRefPtr<DocumentType> create_document_type(String const& qualified_name, String const& public_id, String const& system_id); // https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature bool has_feature() const { return true; } @@ -36,7 +38,8 @@ public: private: explicit DOMImplementation(Document&); - Document& m_document; + Document& document() { return ref_count_target(); } + Document const& document() const { return ref_count_target(); } }; } |