summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/Document.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2023-03-06 22:34:48 +0000
committerLinus Groh <mail@linusgroh.de>2023-03-07 23:33:34 +0000
commit606b9ff6f33b11c19e0f2c95d5869cb67e4e53fa (patch)
tree4dbbaf91f12d0ea9d07df9e2d34087e7b4f7f579 /Userland/Libraries/LibWeb/DOM/Document.cpp
parent56550b6ec02bc9d57c76ca6cb160c530ca869ccd (diff)
downloadserenity-606b9ff6f33b11c19e0f2c95d5869cb67e4e53fa.zip
LibWeb/HTML: Port Window.getSelection() to IDL
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/Document.cpp')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 5b69601770..83556273a9 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -320,6 +320,8 @@ JS::ThrowCompletionOr<void> Document::initialize(JS::Realm& realm)
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::DocumentPrototype>(realm, "Document"));
+ m_selection = MUST_OR_THROW_OOM(heap().allocate<Selection::Selection>(realm, realm, *this));
+
return {};
}
@@ -369,17 +371,12 @@ void Document::visit_edges(Cell::Visitor& visitor)
}
// https://w3c.github.io/selection-api/#dom-document-getselection
-JS::GCPtr<Selection::Selection> Document::get_selection()
+JS::GCPtr<Selection::Selection> Document::get_selection() const
{
// The method must return the selection associated with this if this has an associated browsing context,
// and it must return null otherwise.
- if (!browsing_context()) {
- return nullptr;
- }
-
- if (!m_selection) {
- m_selection = Selection::Selection::create(realm(), *this).release_value_but_fixme_should_propagate_errors();
- }
+ if (!browsing_context())
+ return {};
return m_selection;
}