summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2023-02-15 07:26:32 +0100
committerLinus Groh <mail@linusgroh.de>2023-02-18 00:52:47 +0100
commit07911958432249b4b435082be301fabc55766486 (patch)
tree3a7e180788292570d01ad4c6538b5f733ae49386
parente3e281adddb0c2a515078851f3ea63f94929289f (diff)
downloadserenity-07911958432249b4b435082be301fabc55766486.zip
LibWeb: Make factory methods of DOM::Range fallible
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp2
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.cpp20
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.h8
-rw-r--r--Userland/Libraries/LibWeb/Selection/Selection.cpp12
4 files changed, 21 insertions, 21 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 0afe2b1391..2489aec6f4 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1256,7 +1256,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> Document::create_pr
JS::NonnullGCPtr<Range> Document::create_range()
{
- return Range::create(*this);
+ return Range::create(*this).release_value_but_fixme_should_propagate_errors();
}
// https://dom.spec.whatwg.org/#dom-document-createevent
diff --git a/Userland/Libraries/LibWeb/DOM/Range.cpp b/Userland/Libraries/LibWeb/DOM/Range.cpp
index b77d973f4a..4f2a6e35ac 100644
--- a/Userland/Libraries/LibWeb/DOM/Range.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Range.cpp
@@ -27,24 +27,24 @@ HashTable<Range*>& Range::live_ranges()
return ranges;
}
-JS::NonnullGCPtr<Range> Range::create(HTML::Window& window)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> Range::create(HTML::Window& window)
{
return Range::create(window.associated_document());
}
-JS::NonnullGCPtr<Range> Range::create(Document& document)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> Range::create(Document& document)
{
auto& realm = document.realm();
- return realm.heap().allocate<Range>(realm, document).release_allocated_value_but_fixme_should_propagate_errors();
+ return MUST_OR_THROW_OOM(realm.heap().allocate<Range>(realm, document));
}
-JS::NonnullGCPtr<Range> Range::create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> Range::create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset)
{
auto& realm = start_container.realm();
- return realm.heap().allocate<Range>(realm, start_container, start_offset, end_container, end_offset).release_allocated_value_but_fixme_should_propagate_errors();
+ return MUST_OR_THROW_OOM(realm.heap().allocate<Range>(realm, start_container, start_offset, end_container, end_offset));
}
-JS::NonnullGCPtr<Range> Range::construct_impl(JS::Realm& realm)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> Range::construct_impl(JS::Realm& realm)
{
auto& window = verify_cast<HTML::Window>(realm.global_object());
return Range::create(window);
@@ -715,7 +715,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
TRY(fragment->append_child(clone));
// 3. Let subrange be a new live range whose start is (original start node, original start offset) and whose end is (first partially contained child, first partially contained child’s length).
- auto subrange = Range::create(original_start_node, original_start_offset, *first_partially_contained_child, first_partially_contained_child->length());
+ auto subrange = TRY(Range::create(original_start_node, original_start_offset, *first_partially_contained_child, first_partially_contained_child->length()));
// 4. Let subfragment be the result of extracting subrange.
auto subfragment = TRY(subrange->extract());
@@ -753,7 +753,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
TRY(fragment->append_child(clone));
// 3. Let subrange be a new live range whose start is (last partially contained child, 0) and whose end is (original end node, original end offset).
- auto subrange = Range::create(*last_partially_contained_child, 0, original_end_node, original_end_offset);
+ auto subrange = TRY(Range::create(*last_partially_contained_child, 0, original_end_node, original_end_offset));
// 4. Let subfragment be the result of extracting subrange.
auto subfragment = TRY(subrange->extract());
@@ -1016,7 +1016,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
TRY(fragment->append_child(clone));
// 3. Let subrange be a new live range whose start is (original start node, original start offset) and whose end is (first partially contained child, first partially contained child’s length).
- auto subrange = Range::create(original_start_node, original_start_offset, *first_partially_contained_child, first_partially_contained_child->length());
+ auto subrange = TRY(Range::create(original_start_node, original_start_offset, *first_partially_contained_child, first_partially_contained_child->length()));
// 4. Let subfragment be the result of cloning the contents of subrange.
auto subfragment = TRY(subrange->clone_the_contents());
@@ -1055,7 +1055,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
TRY(fragment->append_child(clone));
// 3. Let subrange be a new live range whose start is (last partially contained child, 0) and whose end is (original end node, original end offset).
- auto subrange = Range::create(*last_partially_contained_child, 0, original_end_node, original_end_offset);
+ auto subrange = TRY(Range::create(*last_partially_contained_child, 0, original_end_node, original_end_offset));
// 4. Let subfragment be the result of cloning the contents of subrange.
auto subfragment = TRY(subrange->clone_the_contents());
diff --git a/Userland/Libraries/LibWeb/DOM/Range.h b/Userland/Libraries/LibWeb/DOM/Range.h
index 480cdb3a4e..1f046b75e4 100644
--- a/Userland/Libraries/LibWeb/DOM/Range.h
+++ b/Userland/Libraries/LibWeb/DOM/Range.h
@@ -26,10 +26,10 @@ class Range final : public AbstractRange {
WEB_PLATFORM_OBJECT(Range, AbstractRange);
public:
- static JS::NonnullGCPtr<Range> create(Document&);
- static JS::NonnullGCPtr<Range> create(HTML::Window&);
- static JS::NonnullGCPtr<Range> create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
- static JS::NonnullGCPtr<Range> construct_impl(JS::Realm&);
+ static WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> create(Document&);
+ static WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> create(HTML::Window&);
+ static WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
+ static WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> construct_impl(JS::Realm&);
virtual ~Range() override;
diff --git a/Userland/Libraries/LibWeb/Selection/Selection.cpp b/Userland/Libraries/LibWeb/Selection/Selection.cpp
index 45297716f1..77c050a246 100644
--- a/Userland/Libraries/LibWeb/Selection/Selection.cpp
+++ b/Userland/Libraries/LibWeb/Selection/Selection.cpp
@@ -187,7 +187,7 @@ WebIDL::ExceptionOr<void> Selection::collapse(JS::GCPtr<DOM::Node> node, unsigne
return {};
// 4. Otherwise, let newRange be a new range.
- auto new_range = DOM::Range::create(*m_document);
+ auto new_range = TRY(DOM::Range::create(*m_document));
// 5. Set the start the start and the end of newRange to (node, offset).
TRY(new_range->set_start(*node, offset));
@@ -214,7 +214,7 @@ WebIDL::ExceptionOr<void> Selection::collapse_to_start()
}
// 2. Otherwise, it must create a new range
- auto new_range = DOM::Range::create(*m_document);
+ auto new_range = TRY(DOM::Range::create(*m_document));
// 3. Set the start both its start and end to the start of this's range
TRY(new_range->set_start(*anchor_node(), m_range->start_offset()));
@@ -234,7 +234,7 @@ WebIDL::ExceptionOr<void> Selection::collapse_to_end()
}
// 2. Otherwise, it must create a new range
- auto new_range = DOM::Range::create(*m_document);
+ auto new_range = TRY(DOM::Range::create(*m_document));
// 3. Set the start both its start and end to the start of this's range
TRY(new_range->set_start(*anchor_node(), m_range->end_offset()));
@@ -266,7 +266,7 @@ WebIDL::ExceptionOr<void> Selection::extend(JS::NonnullGCPtr<DOM::Node> node, un
auto new_focus_offset = offset;
// 4. Let newRange be a new range.
- auto new_range = DOM::Range::create(*m_document);
+ auto new_range = TRY(DOM::Range::create(*m_document));
// 5. If node's root is not the same as the this's range's root, set the start newRange's start and end to newFocus.
if (&node->root() != &m_range->start_container()->root()) {
@@ -315,7 +315,7 @@ WebIDL::ExceptionOr<void> Selection::set_base_and_extent(JS::NonnullGCPtr<DOM::N
// 3. Let anchor be the boundary point (anchorNode, anchorOffset) and let focus be the boundary point (focusNode, focusOffset).
// 4. Let newRange be a new range.
- auto new_range = DOM::Range::create(*m_document);
+ auto new_range = TRY(DOM::Range::create(*m_document));
// 5. If anchor is before focus, set the start the newRange's start to anchor and its end to focus. Otherwise, set the start them to focus and anchor respectively.
auto position_of_anchor_relative_to_focus = DOM::position_of_boundary_point_relative_to_other_boundary_point(anchor_node, anchor_offset, focus_node, focus_offset);
@@ -348,7 +348,7 @@ WebIDL::ExceptionOr<void> Selection::select_all_children(JS::NonnullGCPtr<DOM::N
return {};
// 2. Let newRange be a new range and childCount be the number of children of node.
- auto new_range = DOM::Range::create(*m_document);
+ auto new_range = TRY(DOM::Range::create(*m_document));
auto child_count = node->child_count();
// 3. Set newRange's start to (node, 0).