1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:58:11 +00:00

LibJS+LibWeb: Remove NonnullGCPtr<T>::operator=(GCPtr<T>) footgun

GCPtr can be null so it's not safe to assign it to a NonnullGCPtr unless
you know it to be non-null.

This exposed a number of wrong uses in LibWeb which had to be fixed as
part of this change.
This commit is contained in:
Andreas Kling 2022-12-14 13:43:57 +01:00
parent 4abdb68655
commit d5ed07fdc4
5 changed files with 32 additions and 39 deletions

View file

@ -116,7 +116,7 @@ RelativeBoundaryPointPosition position_of_boundary_point_relative_to_other_bound
while (!node_a.is_parent_of(child)) {
auto* parent = child->parent();
VERIFY(parent);
child = parent;
child = *parent;
}
// 3. If childs index is less than offsetA, then return after.
@ -147,12 +147,12 @@ WebIDL::ExceptionOr<void> Range::set_start_or_end(Node& node, u32 offset, StartO
// 1. If ranges root is not equal to nodes root, or if bp is after the ranges end, set ranges end to bp.
if (&root() != &node.root() || position_of_boundary_point_relative_to_other_boundary_point(node, offset, m_end_container, m_end_offset) == RelativeBoundaryPointPosition::After) {
m_end_container = &node;
m_end_container = node;
m_end_offset = offset;
}
// 2. Set ranges start to bp.
m_start_container = &node;
m_start_container = node;
m_start_offset = offset;
} else {
// -> If these steps were invoked as "set the end"
@ -160,12 +160,12 @@ WebIDL::ExceptionOr<void> Range::set_start_or_end(Node& node, u32 offset, StartO
// 1. If ranges root is not equal to nodes root, or if bp is before the ranges start, set ranges start to bp.
if (&root() != &node.root() || position_of_boundary_point_relative_to_other_boundary_point(node, offset, m_start_container, m_start_offset) == RelativeBoundaryPointPosition::Before) {
m_start_container = &node;
m_start_container = node;
m_start_offset = offset;
}
// 2. Set ranges end to bp.
m_end_container = &node;
m_end_container = node;
m_end_offset = offset;
}
@ -342,11 +342,11 @@ WebIDL::ExceptionOr<void> Range::select(Node& node)
auto index = node.index();
// 4. Set ranges start to boundary point (parent, index).
m_start_container = parent;
m_start_container = *parent;
m_start_offset = index;
// 5. Set ranges end to boundary point (parent, index plus 1).
m_end_container = parent;
m_end_container = *parent;
m_end_offset = index + 1;
return {};
@ -384,11 +384,11 @@ WebIDL::ExceptionOr<void> Range::select_node_contents(Node const& node)
auto length = node.length();
// 3. Set start to the boundary point (node, 0).
m_start_container = &node;
m_start_container = node;
m_start_offset = 0;
// 4. Set end to the boundary point (node, length).
m_end_container = &node;
m_end_container = node;
m_end_offset = length;
return {};
@ -428,7 +428,7 @@ JS::NonnullGCPtr<Node> Range::common_ancestor_container() const
// 2. While container is not an inclusive ancestor of end node, let container be containers parent.
while (!container->is_inclusive_ancestor_of(m_end_container)) {
VERIFY(container->parent());
container = container->parent();
container = *container->parent();
}
// 3. Return container.
@ -593,7 +593,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
// 6. While common ancestor is not an inclusive ancestor of original end node, set common ancestor to its own parent.
while (!common_ancestor->is_inclusive_ancestor_of(original_end_node))
common_ancestor = common_ancestor->parent_node();
common_ancestor = *common_ancestor->parent_node();
// 7. Let first partially contained child be null.
JS::GCPtr<Node> first_partially_contained_child;
@ -919,7 +919,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
// 6. While common ancestor is not an inclusive ancestor of original end node, set common ancestor to its own parent.
while (!common_ancestor->is_inclusive_ancestor_of(original_end_node))
common_ancestor = common_ancestor->parent_node();
common_ancestor = *common_ancestor->parent_node();
// 7. Let first partially contained child be null.
JS::GCPtr<Node> first_partially_contained_child;
@ -1078,7 +1078,7 @@ WebIDL::ExceptionOr<void> Range::delete_contents()
// 2. While reference nodes parent is not null and is not an inclusive ancestor of original end node, set reference node to its parent.
while (reference_node->parent_node() && !reference_node->parent_node()->is_inclusive_ancestor_of(original_end_node))
reference_node = reference_node->parent_node();
reference_node = *reference_node->parent_node();
// 3. Set new node to the parent of reference node, and new offset to one plus the index of reference node.
new_node = reference_node->parent_node();