mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 08:57:35 +00:00
LibWeb: Make DOMImplementation GC-allocated
This commit is contained in:
parent
cfdb8f2a8e
commit
967a3e5a45
6 changed files with 47 additions and 26 deletions
|
@ -1,9 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, the SerenityOS developers.
|
* Copyright (c) 2020, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/DOMImplementationPrototype.h>
|
||||||
|
#include <LibWeb/Bindings/WindowObject.h>
|
||||||
#include <LibWeb/DOM/DOMImplementation.h>
|
#include <LibWeb/DOM/DOMImplementation.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/DocumentType.h>
|
#include <LibWeb/DOM/DocumentType.h>
|
||||||
|
@ -14,9 +17,24 @@
|
||||||
|
|
||||||
namespace Web::DOM {
|
namespace Web::DOM {
|
||||||
|
|
||||||
DOMImplementation::DOMImplementation(Document& document)
|
JS::NonnullGCPtr<DOMImplementation> DOMImplementation::create(Document& document)
|
||||||
: RefCountForwarder(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
|
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocument
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, the SerenityOS developers.
|
* Copyright (c) 2020, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -7,25 +8,20 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <AK/RefCountForwarder.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
#include <AK/RefCounted.h>
|
|
||||||
#include <AK/Weakable.h>
|
|
||||||
#include <LibWeb/Bindings/Wrappable.h>
|
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
|
|
||||||
namespace Web::DOM {
|
namespace Web::DOM {
|
||||||
|
|
||||||
class DOMImplementation final
|
class DOMImplementation final : public Bindings::PlatformObject {
|
||||||
: public RefCountForwarder<Document>
|
JS_OBJECT(DOMImplementation, Bindings::PlatformObject);
|
||||||
, public Weakable<DOMImplementation>
|
|
||||||
, public Bindings::Wrappable {
|
|
||||||
public:
|
|
||||||
using WrapperType = Bindings::DOMImplementationWrapper;
|
|
||||||
|
|
||||||
static NonnullOwnPtr<DOMImplementation> create(Badge<Document>, Document& document)
|
public:
|
||||||
{
|
static JS::NonnullGCPtr<DOMImplementation> create(Document&);
|
||||||
return adopt_own(*new DOMImplementation(document));
|
explicit DOMImplementation(Document&);
|
||||||
}
|
virtual ~DOMImplementation();
|
||||||
|
|
||||||
|
DOMImplementation& impl() { return *this; }
|
||||||
|
|
||||||
ExceptionOr<NonnullRefPtr<Document>> create_document(String const&, String const&, RefPtr<DocumentType>) const;
|
ExceptionOr<NonnullRefPtr<Document>> create_document(String const&, String const&, RefPtr<DocumentType>) const;
|
||||||
NonnullRefPtr<Document> create_html_document(String const& title) const;
|
NonnullRefPtr<Document> create_html_document(String const& title) const;
|
||||||
|
@ -35,10 +31,17 @@ public:
|
||||||
bool has_feature() const { return true; }
|
bool has_feature() const { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit DOMImplementation(Document&);
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
Document& document() { return ref_count_target(); }
|
Document& document() { return m_document; }
|
||||||
Document const& document() const { return ref_count_target(); }
|
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_style_computer(make<CSS::StyleComputer>(*this))
|
||||||
, m_url(url)
|
, m_url(url)
|
||||||
, m_window(HTML::Window::create_with_document(*this))
|
, m_window(HTML::Window::create_with_document(*this))
|
||||||
, m_implementation(DOMImplementation::create({}, *this))
|
|
||||||
, m_history(HTML::History::create(*this))
|
, m_history(HTML::History::create(*this))
|
||||||
{
|
{
|
||||||
m_style_sheets = JS::make_handle(CSS::StyleSheetList::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
|
bool Document::has_focus() const
|
||||||
|
|
|
@ -300,7 +300,7 @@ public:
|
||||||
|
|
||||||
void completely_finish_loading();
|
void completely_finish_loading();
|
||||||
|
|
||||||
NonnullRefPtr<DOMImplementation> implementation() const;
|
DOMImplementation* implementation();
|
||||||
|
|
||||||
RefPtr<HTML::HTMLScriptElement> current_script() const { return m_current_script; }
|
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); }
|
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 };
|
bool m_ready_for_post_load_tasks { false };
|
||||||
|
|
||||||
NonnullOwnPtr<DOMImplementation> m_implementation;
|
JS::Handle<DOMImplementation> m_implementation;
|
||||||
RefPtr<HTML::HTMLScriptElement> m_current_script;
|
RefPtr<HTML::HTMLScriptElement> m_current_script;
|
||||||
|
|
||||||
bool m_should_invalidate_styles_on_attribute_changes { true };
|
bool m_should_invalidate_styles_on_attribute_changes { true };
|
||||||
|
|
|
@ -464,7 +464,6 @@ class DocumentFragmentWrapper;
|
||||||
class DocumentTypeWrapper;
|
class DocumentTypeWrapper;
|
||||||
class DocumentWrapper;
|
class DocumentWrapper;
|
||||||
class DOMExceptionWrapper;
|
class DOMExceptionWrapper;
|
||||||
class DOMImplementationWrapper;
|
|
||||||
class DOMParserWrapper;
|
class DOMParserWrapper;
|
||||||
class DOMPointWrapper;
|
class DOMPointWrapper;
|
||||||
class DOMPointReadOnlyWrapper;
|
class DOMPointReadOnlyWrapper;
|
||||||
|
|
|
@ -32,7 +32,7 @@ libweb_js_wrapper(DOM/Document)
|
||||||
libweb_js_wrapper(DOM/DocumentFragment)
|
libweb_js_wrapper(DOM/DocumentFragment)
|
||||||
libweb_js_wrapper(DOM/DocumentType)
|
libweb_js_wrapper(DOM/DocumentType)
|
||||||
libweb_js_wrapper(DOM/DOMException)
|
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/DOMTokenList NO_INSTANCE)
|
||||||
libweb_js_wrapper(DOM/Element)
|
libweb_js_wrapper(DOM/Element)
|
||||||
libweb_js_wrapper(DOM/Event)
|
libweb_js_wrapper(DOM/Event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue