mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWeb: Make DOMImplementation GC-allocated
This commit is contained in:
parent
cfdb8f2a8e
commit
967a3e5a45
Notes:
sideshowbarker
2024-07-17 07:28:39 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/967a3e5a45 Pull-request: https://github.com/SerenityOS/serenity/pull/14816 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg ✅
6 changed files with 47 additions and 26 deletions
|
@ -1,9 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/DOMImplementationPrototype.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/DOM/DOMImplementation.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/DocumentType.h>
|
||||
|
@ -14,9 +17,24 @@
|
|||
|
||||
namespace Web::DOM {
|
||||
|
||||
DOMImplementation::DOMImplementation(Document& document)
|
||||
: RefCountForwarder(document)
|
||||
JS::NonnullGCPtr<DOMImplementation> DOMImplementation::create(Document& document)
|
||||
{
|
||||
auto& window_object = document.preferred_window_object();
|
||||
return *window_object.heap().allocate<DOMImplementation>(window_object.realm(), document);
|
||||
}
|
||||
|
||||
DOMImplementation::DOMImplementation(Document& document)
|
||||
: PlatformObject(document.preferred_window_object().ensure_web_prototype<Bindings::DOMImplementationPrototype>("DOMImplementation"))
|
||||
, m_document(document)
|
||||
{
|
||||
}
|
||||
|
||||
DOMImplementation::~DOMImplementation() = default;
|
||||
|
||||
void DOMImplementation::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_document);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocument
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -7,25 +8,20 @@
|
|||
#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/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
class DOMImplementation final
|
||||
: public RefCountForwarder<Document>
|
||||
, public Weakable<DOMImplementation>
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
using WrapperType = Bindings::DOMImplementationWrapper;
|
||||
class DOMImplementation final : public Bindings::PlatformObject {
|
||||
JS_OBJECT(DOMImplementation, Bindings::PlatformObject);
|
||||
|
||||
static NonnullOwnPtr<DOMImplementation> create(Badge<Document>, Document& document)
|
||||
{
|
||||
return adopt_own(*new DOMImplementation(document));
|
||||
}
|
||||
public:
|
||||
static JS::NonnullGCPtr<DOMImplementation> create(Document&);
|
||||
explicit DOMImplementation(Document&);
|
||||
virtual ~DOMImplementation();
|
||||
|
||||
DOMImplementation& impl() { return *this; }
|
||||
|
||||
ExceptionOr<NonnullRefPtr<Document>> create_document(String const&, String const&, RefPtr<DocumentType>) const;
|
||||
NonnullRefPtr<Document> create_html_document(String const& title) const;
|
||||
|
@ -35,10 +31,17 @@ public:
|
|||
bool has_feature() const { return true; }
|
||||
|
||||
private:
|
||||
explicit DOMImplementation(Document&);
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Document& document() { return ref_count_target(); }
|
||||
Document const& document() const { return ref_count_target(); }
|
||||
Document& document() { return m_document; }
|
||||
Document const& document() const { return m_document; }
|
||||
|
||||
Document& m_document;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace Web::Bindings {
|
||||
inline JS::Object* wrap(JS::Realm&, Web::DOM::DOMImplementation& object) { return &object; }
|
||||
using DOMImplementationWrapper = Web::DOM::DOMImplementation;
|
||||
}
|
||||
|
|
|
@ -281,7 +281,6 @@ Document::Document(const AK::URL& url)
|
|||
, m_style_computer(make<CSS::StyleComputer>(*this))
|
||||
, m_url(url)
|
||||
, m_window(HTML::Window::create_with_document(*this))
|
||||
, m_implementation(DOMImplementation::create({}, *this))
|
||||
, m_history(HTML::History::create(*this))
|
||||
{
|
||||
m_style_sheets = JS::make_handle(CSS::StyleSheetList::create(*this));
|
||||
|
@ -1621,9 +1620,11 @@ void Document::evaluate_media_rules()
|
|||
}
|
||||
}
|
||||
|
||||
NonnullRefPtr<DOMImplementation> Document::implementation() const
|
||||
DOMImplementation* Document::implementation()
|
||||
{
|
||||
return *m_implementation;
|
||||
if (!m_implementation.cell())
|
||||
m_implementation = JS::make_handle(*DOMImplementation::create(*this));
|
||||
return m_implementation.cell();
|
||||
}
|
||||
|
||||
bool Document::has_focus() const
|
||||
|
|
|
@ -300,7 +300,7 @@ public:
|
|||
|
||||
void completely_finish_loading();
|
||||
|
||||
NonnullRefPtr<DOMImplementation> implementation() const;
|
||||
DOMImplementation* implementation();
|
||||
|
||||
RefPtr<HTML::HTMLScriptElement> current_script() const { return m_current_script; }
|
||||
void set_current_script(Badge<HTML::HTMLScriptElement>, RefPtr<HTML::HTMLScriptElement> script) { m_current_script = move(script); }
|
||||
|
@ -457,7 +457,7 @@ private:
|
|||
|
||||
bool m_ready_for_post_load_tasks { false };
|
||||
|
||||
NonnullOwnPtr<DOMImplementation> m_implementation;
|
||||
JS::Handle<DOMImplementation> m_implementation;
|
||||
RefPtr<HTML::HTMLScriptElement> m_current_script;
|
||||
|
||||
bool m_should_invalidate_styles_on_attribute_changes { true };
|
||||
|
|
|
@ -464,7 +464,6 @@ class DocumentFragmentWrapper;
|
|||
class DocumentTypeWrapper;
|
||||
class DocumentWrapper;
|
||||
class DOMExceptionWrapper;
|
||||
class DOMImplementationWrapper;
|
||||
class DOMParserWrapper;
|
||||
class DOMPointWrapper;
|
||||
class DOMPointReadOnlyWrapper;
|
||||
|
|
|
@ -32,7 +32,7 @@ libweb_js_wrapper(DOM/Document)
|
|||
libweb_js_wrapper(DOM/DocumentFragment)
|
||||
libweb_js_wrapper(DOM/DocumentType)
|
||||
libweb_js_wrapper(DOM/DOMException)
|
||||
libweb_js_wrapper(DOM/DOMImplementation)
|
||||
libweb_js_wrapper(DOM/DOMImplementation NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/DOMTokenList NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/Element)
|
||||
libweb_js_wrapper(DOM/Event)
|
||||
|
|
Loading…
Add table
Reference in a new issue