mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
LibWeb: Fix Document construction mishap in <template> element
Ref-counted objects must not be stack allocated. Make DOM::Document's constructor private to avoid this issue. (I wish we could mark classes as heap-only..)
This commit is contained in:
parent
691b105885
commit
46c15276e9
7 changed files with 11 additions and 9 deletions
|
@ -47,7 +47,7 @@ ConsoleWidget::ConsoleWidget()
|
||||||
set_layout<GUI::VerticalBoxLayout>();
|
set_layout<GUI::VerticalBoxLayout>();
|
||||||
set_fill_with_background_color(true);
|
set_fill_with_background_color(true);
|
||||||
|
|
||||||
auto base_document = adopt(*new Web::DOM::Document);
|
auto base_document = Web::DOM::Document::create();
|
||||||
base_document->append_child(adopt(*new Web::DOM::DocumentType(base_document)));
|
base_document->append_child(adopt(*new Web::DOM::DocumentType(base_document)));
|
||||||
auto html_element = base_document->create_element("html");
|
auto html_element = base_document->create_element("html");
|
||||||
base_document->append_child(html_element);
|
base_document->append_child(html_element);
|
||||||
|
|
|
@ -40,7 +40,7 @@ NonnullRefPtr<IRCLogBuffer> IRCLogBuffer::create()
|
||||||
|
|
||||||
IRCLogBuffer::IRCLogBuffer()
|
IRCLogBuffer::IRCLogBuffer()
|
||||||
{
|
{
|
||||||
m_document = adopt(*new Web::DOM::Document);
|
m_document = Web::DOM::Document::create();
|
||||||
m_document->append_child(adopt(*new Web::DOM::DocumentType(document())));
|
m_document->append_child(adopt(*new Web::DOM::DocumentType(document())));
|
||||||
auto html_element = m_document->create_element("html");
|
auto html_element = m_document->create_element("html");
|
||||||
m_document->append_child(html_element);
|
m_document->append_child(html_element);
|
||||||
|
|
|
@ -57,7 +57,7 @@ class Document
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::DocumentWrapper;
|
using WrapperType = Bindings::DocumentWrapper;
|
||||||
|
|
||||||
explicit Document(const URL& = {});
|
static NonnullRefPtr<Document> create(const URL& url = {}) { return adopt(*new Document(url)); }
|
||||||
virtual ~Document() override;
|
virtual ~Document() override;
|
||||||
|
|
||||||
void set_url(const URL& url) { m_url = url; }
|
void set_url(const URL& url) { m_url = url; }
|
||||||
|
@ -192,6 +192,8 @@ public:
|
||||||
Window& window() { return *m_window; }
|
Window& window() { return *m_window; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit Document(const URL&);
|
||||||
|
|
||||||
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||||
|
|
||||||
void tear_down_layout_tree();
|
void tear_down_layout_tree();
|
||||||
|
|
|
@ -44,8 +44,8 @@ DOM::Document& HTMLTemplateElement::appropriate_template_contents_owner_document
|
||||||
{
|
{
|
||||||
if (!document.created_for_appropriate_template_contents()) {
|
if (!document.created_for_appropriate_template_contents()) {
|
||||||
if (!document.associated_inert_template_document()) {
|
if (!document.associated_inert_template_document()) {
|
||||||
DOM::Document new_document;
|
auto new_document = DOM::Document::create();
|
||||||
new_document.set_created_for_appropriate_template_contents(true);
|
new_document->set_created_for_appropriate_template_contents(true);
|
||||||
|
|
||||||
// FIXME: If doc is an HTML document, mark new doc as an HTML document also.
|
// FIXME: If doc is an HTML document, mark new doc as an HTML document also.
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ RefPtr<DOM::Document> parse_html_document(const StringView& data, const URL& url
|
||||||
HTMLDocumentParser::HTMLDocumentParser(const StringView& input, const String& encoding)
|
HTMLDocumentParser::HTMLDocumentParser(const StringView& input, const String& encoding)
|
||||||
: m_tokenizer(input, encoding)
|
: m_tokenizer(input, encoding)
|
||||||
{
|
{
|
||||||
m_document = adopt(*new DOM::Document);
|
m_document = DOM::Document::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLDocumentParser::HTMLDocumentParser(const StringView& input, const String& encoding, DOM::Document& existing_document)
|
HTMLDocumentParser::HTMLDocumentParser(const StringView& input, const String& encoding, DOM::Document& existing_document)
|
||||||
|
|
|
@ -63,7 +63,7 @@ static RefPtr<DOM::Document> create_markdown_document(const ByteBuffer& data, co
|
||||||
|
|
||||||
static RefPtr<DOM::Document> create_text_document(const ByteBuffer& data, const URL& url)
|
static RefPtr<DOM::Document> create_text_document(const ByteBuffer& data, const URL& url)
|
||||||
{
|
{
|
||||||
auto document = adopt(*new DOM::Document(url));
|
auto document = DOM::Document::create(url);
|
||||||
|
|
||||||
auto html_element = document->create_element("html");
|
auto html_element = document->create_element("html");
|
||||||
document->append_child(html_element);
|
document->append_child(html_element);
|
||||||
|
@ -88,7 +88,7 @@ static RefPtr<DOM::Document> create_text_document(const ByteBuffer& data, const
|
||||||
|
|
||||||
static RefPtr<DOM::Document> create_image_document(const ByteBuffer& data, const URL& url)
|
static RefPtr<DOM::Document> create_image_document(const ByteBuffer& data, const URL& url)
|
||||||
{
|
{
|
||||||
auto document = adopt(*new DOM::Document(url));
|
auto document = DOM::Document::create(url);
|
||||||
|
|
||||||
auto image_decoder = Gfx::ImageDecoder::create(data.data(), data.size());
|
auto image_decoder = Gfx::ImageDecoder::create(data.data(), data.size());
|
||||||
auto bitmap = image_decoder->bitmap();
|
auto bitmap = image_decoder->bitmap();
|
||||||
|
|
|
@ -686,7 +686,7 @@ int main(int argc, char** argv)
|
||||||
main_widget.set_layout<GUI::VerticalBoxLayout>();
|
main_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||||
auto& view = main_widget.add<Web::InProcessWebView>();
|
auto& view = main_widget.add<Web::InProcessWebView>();
|
||||||
|
|
||||||
view.set_document(adopt(*new Web::DOM::Document));
|
view.set_document(Web::DOM::Document::create());
|
||||||
|
|
||||||
if (show_window) {
|
if (show_window) {
|
||||||
window->set_title("LibWeb Test Window");
|
window->set_title("LibWeb Test Window");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue