diff options
author | Linus Groh <mail@linusgroh.de> | 2023-03-06 22:34:48 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-07 23:33:34 +0000 |
commit | 606b9ff6f33b11c19e0f2c95d5869cb67e4e53fa (patch) | |
tree | 4dbbaf91f12d0ea9d07df9e2d34087e7b4f7f579 /Userland/Libraries/LibWeb/DOM/Document.cpp | |
parent | 56550b6ec02bc9d57c76ca6cb160c530ca869ccd (diff) | |
download | serenity-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.cpp | 13 |
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; } |