1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:17:35 +00:00

LibJS: Convert Heap::allocate{,_without_realm}() to NonnullGCPtr

This commit is contained in:
Linus Groh 2022-12-14 17:40:33 +00:00 committed by Tim Flynn
parent 2a66fc6cae
commit 22089436ed
161 changed files with 367 additions and 370 deletions

View file

@ -34,13 +34,13 @@ JS::NonnullGCPtr<Range> Range::create(HTML::Window& window)
JS::NonnullGCPtr<Range> Range::create(Document& document)
{
auto& realm = document.realm();
return *realm.heap().allocate<Range>(realm, document);
return realm.heap().allocate<Range>(realm, document);
}
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);
return realm.heap().allocate<Range>(realm, start_container, start_offset, end_container, end_offset);
}
JS::NonnullGCPtr<Range> Range::construct_impl(JS::Realm& realm)
@ -396,12 +396,12 @@ WebIDL::ExceptionOr<void> Range::select_node_contents(Node const& node)
JS::NonnullGCPtr<Range> Range::clone_range() const
{
return *heap().allocate<Range>(shape().realm(), const_cast<Node&>(*m_start_container), m_start_offset, const_cast<Node&>(*m_end_container), m_end_offset);
return heap().allocate<Range>(shape().realm(), const_cast<Node&>(*m_start_container), m_start_offset, const_cast<Node&>(*m_end_container), m_end_offset);
}
JS::NonnullGCPtr<Range> Range::inverted() const
{
return *heap().allocate<Range>(shape().realm(), const_cast<Node&>(*m_end_container), m_end_offset, const_cast<Node&>(*m_start_container), m_start_offset);
return heap().allocate<Range>(shape().realm(), const_cast<Node&>(*m_end_container), m_end_offset, const_cast<Node&>(*m_start_container), m_start_offset);
}
JS::NonnullGCPtr<Range> Range::normalized() const
@ -555,11 +555,11 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract_contents(
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
{
// 1. Let fragment be a new DocumentFragment node whose node document is ranges start nodes node document.
auto* fragment = heap().allocate<DOM::DocumentFragment>(realm(), const_cast<Document&>(start_container()->document()));
auto fragment = heap().allocate<DOM::DocumentFragment>(realm(), const_cast<Document&>(start_container()->document()));
// 2. If range is collapsed, then return fragment.
if (collapsed())
return JS::NonnullGCPtr(*fragment);
return fragment;
// 3. Let original start node, original start offset, original end node, and original end offset
// be ranges start node, start offset, end node, and end offset, respectively.
@ -585,7 +585,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
TRY(static_cast<CharacterData&>(*original_start_node).replace_data(original_start_offset, original_end_offset - original_start_offset, ""));
// 5. Return fragment.
return JS::NonnullGCPtr(*fragment);
return fragment;
}
// 5. Let common ancestor be original start node.
@ -735,7 +735,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
TRY(set_end(*new_node, new_offset));
// 21. Return fragment.
return JS::NonnullGCPtr(*fragment);
return fragment;
}
// https://dom.spec.whatwg.org/#contained
@ -884,11 +884,11 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_contents()
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_contents()
{
// 1. Let fragment be a new DocumentFragment node whose node document is ranges start nodes node document.
auto* fragment = heap().allocate<DOM::DocumentFragment>(realm(), const_cast<Document&>(start_container()->document()));
auto fragment = heap().allocate<DOM::DocumentFragment>(realm(), const_cast<Document&>(start_container()->document()));
// 2. If range is collapsed, then return fragment.
if (collapsed())
return JS::NonnullGCPtr(*fragment);
return fragment;
// 3. Let original start node, original start offset, original end node, and original end offset
// be ranges start node, start offset, end node, and end offset, respectively.
@ -911,7 +911,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
TRY(fragment->append_child(clone));
// 4. Return fragment.
return JS::NonnullGCPtr(*fragment);
return fragment;
}
// 5. Let common ancestor be original start node.
@ -1033,7 +1033,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
}
// 18. Return fragment.
return JS::NonnullGCPtr(*fragment);
return fragment;
}
// https://dom.spec.whatwg.org/#dom-range-deletecontents