mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:07:35 +00:00
Everywhere: Prevent risky implicit casts of (Nonnull)RefPtr
Our existing implementation did not check the element type of the other pointer in the constructors and move assignment operators. This meant that some operations that would require explicit casting on raw pointers were done implicitly, such as: - downcasting a base class to a derived class (e.g. `Kernel::Inode` => `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp), - casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>` in LibIMAP/Client.cpp) This, of course, allows gross violations of the type system, and makes the need to type-check less obvious before downcasting. Luckily, while adding the `static_ptr_cast`s, only two truly incorrect usages were found; in the other instances, our casts just needed to be made explicit.
This commit is contained in:
parent
bad23e3f8c
commit
d7b6cc6421
21 changed files with 43 additions and 43 deletions
|
@ -13,7 +13,7 @@ void TextureUnit::bind_texture_to_target(GLenum texture_target, const RefPtr<Tex
|
|||
{
|
||||
switch (texture_target) {
|
||||
case GL_TEXTURE_2D:
|
||||
m_texture_target_2d = texture;
|
||||
m_texture_target_2d = static_ptr_cast<Texture2D>(texture);
|
||||
m_currently_bound_texture = texture;
|
||||
m_currently_bound_target = GL_TEXTURE_2D;
|
||||
break;
|
||||
|
|
|
@ -31,7 +31,7 @@ RefPtr<Promise<Empty>> Client::connect()
|
|||
}
|
||||
if (!success)
|
||||
return {};
|
||||
m_connect_pending = Promise<bool>::construct();
|
||||
m_connect_pending = Promise<Empty>::construct();
|
||||
return m_connect_pending;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ private:
|
|||
// Not yet sent
|
||||
Vector<Command> m_command_queue {};
|
||||
|
||||
RefPtr<Promise<bool>> m_connect_pending {};
|
||||
RefPtr<Promise<Empty>> m_connect_pending {};
|
||||
|
||||
ByteBuffer m_buffer;
|
||||
Parser m_parser;
|
||||
|
|
|
@ -1606,7 +1606,7 @@ NonnullRefPtr<Identifier> Parser::parse_identifier()
|
|||
token.value());
|
||||
}
|
||||
|
||||
NonnullRefPtr<CallExpression> Parser::parse_call_expression(NonnullRefPtr<Expression> lhs)
|
||||
NonnullRefPtr<Expression> Parser::parse_call_expression(NonnullRefPtr<Expression> lhs)
|
||||
{
|
||||
auto rule_start = push_start();
|
||||
if (!m_state.allow_super_constructor_call && is<SuperExpression>(*lhs))
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
NonnullRefPtr<StringLiteral> parse_string_literal(const Token& token, bool in_template_literal = false);
|
||||
NonnullRefPtr<TemplateLiteral> parse_template_literal(bool is_tagged);
|
||||
NonnullRefPtr<Expression> parse_secondary_expression(NonnullRefPtr<Expression>, int min_precedence, Associativity associate = Associativity::Right);
|
||||
NonnullRefPtr<CallExpression> parse_call_expression(NonnullRefPtr<Expression>);
|
||||
NonnullRefPtr<Expression> parse_call_expression(NonnullRefPtr<Expression>);
|
||||
NonnullRefPtr<NewExpression> parse_new_expression();
|
||||
NonnullRefPtr<ClassDeclaration> parse_class_declaration();
|
||||
NonnullRefPtr<ClassExpression> parse_class_expression(bool expect_class_name);
|
||||
|
|
|
@ -146,7 +146,7 @@ Value Document::resolve(Value const& value)
|
|||
auto obj = value.as_object();
|
||||
|
||||
if (obj->is_indirect_value())
|
||||
return static_cast<NonnullRefPtr<IndirectValue>>(obj)->value();
|
||||
return static_ptr_cast<IndirectValue>(obj)->value();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ template<IsObject To, IsObject From>
|
|||
# undef ENUMERATE_TYPES
|
||||
#endif
|
||||
|
||||
return static_cast<NonnullRefPtr<To>>(obj);
|
||||
return static_ptr_cast<To>(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@ NonnullRefPtr<Insert> Parser::parse_insert_statement(RefPtr<CommonTableExpressio
|
|||
if ((column_names.size() > 0) && (chained_expr->expressions().size() != column_names.size())) {
|
||||
syntax_error("Number of expressions does not match number of columns");
|
||||
} else {
|
||||
chained_expressions.append(chained_expression.release_nonnull());
|
||||
chained_expressions.append(static_ptr_cast<ChainedExpression>(chained_expression.release_nonnull()));
|
||||
}
|
||||
} else {
|
||||
expected("Chained expression");
|
||||
|
|
|
@ -72,7 +72,7 @@ NonnullRefPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
|
|||
|
||||
auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML);
|
||||
pre_insert(caption, first_child());
|
||||
return caption;
|
||||
return static_ptr_cast<HTMLTableCaptionElement>(caption);
|
||||
}
|
||||
|
||||
void HTMLTableElement::delete_caption()
|
||||
|
@ -159,7 +159,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
|
|||
|
||||
pre_insert(thead, child_to_append_after);
|
||||
|
||||
return thead;
|
||||
return static_ptr_cast<HTMLTableSectionElement>(thead);
|
||||
}
|
||||
|
||||
void HTMLTableElement::delete_t_head()
|
||||
|
@ -209,7 +209,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_foot()
|
|||
|
||||
auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML);
|
||||
append_child(tfoot);
|
||||
return tfoot;
|
||||
return static_ptr_cast<HTMLTableSectionElement>(tfoot);
|
||||
}
|
||||
|
||||
void HTMLTableElement::delete_t_foot()
|
||||
|
@ -248,7 +248,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
|
|||
|
||||
pre_insert(tbody, child_to_append_after);
|
||||
|
||||
return tbody;
|
||||
return static_ptr_cast<HTMLTableSectionElement>(tbody);
|
||||
}
|
||||
|
||||
NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::rows()
|
||||
|
@ -287,7 +287,7 @@ DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableElement::insert_ro
|
|||
if (index < -1 || index >= (long)rows_length) {
|
||||
return DOM::IndexSizeError::create("Index is negative or greater than the number of rows");
|
||||
}
|
||||
auto tr = static_cast<NonnullRefPtr<HTMLTableRowElement>>(DOM::create_element(document(), TagNames::tr, Namespace::HTML));
|
||||
auto tr = static_ptr_cast<HTMLTableRowElement>(DOM::create_element(document(), TagNames::tr, Namespace::HTML));
|
||||
if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) {
|
||||
auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML);
|
||||
tbody->append_child(tr);
|
||||
|
|
|
@ -166,7 +166,7 @@ void TreeBuilder::remove_irrelevant_boxes(NodeWithStyle& root)
|
|||
{
|
||||
// The following boxes are discarded as if they were display:none:
|
||||
|
||||
NonnullRefPtrVector<Box> to_remove;
|
||||
NonnullRefPtrVector<Node> to_remove;
|
||||
|
||||
// Children of a table-column.
|
||||
for_each_in_tree_with_display<CSS::Display::TableColumn>(root, [&](Box& table_column) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue