mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Userland: Replace VERIFY(is<T>) with verify_cast<T>
Instead of doing a VERIFY(is<T>(x)) and *then* casting it to T, we can just do the cast right away with verify_cast<T>. :^)
This commit is contained in:
parent
7fef8c5648
commit
e59bf87374
Notes:
sideshowbarker
2024-07-18 11:34:05 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e59bf87374f
10 changed files with 26 additions and 43 deletions
|
@ -63,8 +63,7 @@ void MallocTracer::target_did_malloc(Badge<Emulator>, FlatPtr address, size_t si
|
|||
return;
|
||||
auto* region = m_emulator.mmu().find_region({ 0x23, address });
|
||||
VERIFY(region);
|
||||
VERIFY(is<MmapRegion>(*region));
|
||||
auto& mmap_region = static_cast<MmapRegion&>(*region);
|
||||
auto& mmap_region = verify_cast<MmapRegion>(*region);
|
||||
|
||||
auto* shadow_bits = mmap_region.shadow_data() + address - mmap_region.base();
|
||||
memset(shadow_bits, 0, size);
|
||||
|
@ -93,8 +92,7 @@ void MallocTracer::target_did_change_chunk_size(Badge<Emulator>, FlatPtr block,
|
|||
return;
|
||||
auto* region = m_emulator.mmu().find_region({ 0x23, block });
|
||||
VERIFY(region);
|
||||
VERIFY(is<MmapRegion>(*region));
|
||||
auto& mmap_region = static_cast<MmapRegion&>(*region);
|
||||
auto& mmap_region = verify_cast<MmapRegion>(*region);
|
||||
update_metadata(mmap_region, chunk_size);
|
||||
}
|
||||
|
||||
|
@ -153,8 +151,7 @@ void MallocTracer::target_did_realloc(Badge<Emulator>, FlatPtr address, size_t s
|
|||
return;
|
||||
auto* region = m_emulator.mmu().find_region({ 0x23, address });
|
||||
VERIFY(region);
|
||||
VERIFY(is<MmapRegion>(*region));
|
||||
auto& mmap_region = static_cast<MmapRegion&>(*region);
|
||||
auto& mmap_region = verify_cast<MmapRegion>(*region);
|
||||
|
||||
VERIFY(mmap_region.is_malloc_block());
|
||||
|
||||
|
|
|
@ -61,8 +61,7 @@ void SoftMMU::ensure_split_at(X86::LogicalAddress address)
|
|||
|
||||
// If we get here, we know that the page exists and belongs to a region, that there is
|
||||
// a previous page, and that it belongs to the same region.
|
||||
VERIFY(is<MmapRegion>(m_page_to_region_map[page_index]));
|
||||
auto* old_region = static_cast<MmapRegion*>(m_page_to_region_map[page_index]);
|
||||
auto* old_region = verify_cast<MmapRegion>(m_page_to_region_map[page_index]);
|
||||
|
||||
//dbgln("splitting at {:p}", address.offset());
|
||||
//dbgln(" old region: {:p}-{:p}", old_region->base(), old_region->end() - 1);
|
||||
|
|
|
@ -244,8 +244,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
|
|||
return {};
|
||||
|
||||
auto& this_er = get_this_environment(interpreter.vm());
|
||||
VERIFY(is<FunctionEnvironmentRecord>(this_er));
|
||||
static_cast<FunctionEnvironmentRecord&>(this_er).bind_this_value(global_object, result);
|
||||
verify_cast<FunctionEnvironmentRecord>(this_er).bind_this_value(global_object, result);
|
||||
} else {
|
||||
result = vm.call(function, this_value, move(arguments));
|
||||
}
|
||||
|
@ -1776,10 +1775,9 @@ void MemberExpression::dump(int indent) const
|
|||
|
||||
PropertyName MemberExpression::computed_property_name(Interpreter& interpreter, GlobalObject& global_object) const
|
||||
{
|
||||
if (!is_computed()) {
|
||||
VERIFY(is<Identifier>(*m_property));
|
||||
return static_cast<Identifier const&>(*m_property).string();
|
||||
}
|
||||
if (!is_computed())
|
||||
return verify_cast<Identifier>(*m_property).string();
|
||||
|
||||
auto value = m_property->execute(interpreter, global_object);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
@ -1794,8 +1792,7 @@ String MemberExpression::to_string_approximation() const
|
|||
object_string = static_cast<Identifier const&>(*m_object).string();
|
||||
if (is_computed())
|
||||
return String::formatted("{}[<computed>]", object_string);
|
||||
VERIFY(is<Identifier>(*m_property));
|
||||
return String::formatted("{}.{}", object_string, static_cast<Identifier const&>(*m_property).string());
|
||||
return String::formatted("{}.{}", object_string, verify_cast<Identifier>(*m_property).string());
|
||||
}
|
||||
|
||||
Value MemberExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const
|
||||
|
|
|
@ -390,9 +390,8 @@ void AssignmentExpression::generate_bytecode(Bytecode::Generator& generator) con
|
|||
m_rhs->generate_bytecode(generator);
|
||||
generator.emit<Bytecode::Op::PutByValue>(object_reg, property_reg);
|
||||
} else {
|
||||
VERIFY(is<Identifier>(expression.property()));
|
||||
m_rhs->generate_bytecode(generator);
|
||||
auto identifier_table_ref = generator.intern_string(static_cast<Identifier const&>(expression.property()).string());
|
||||
auto identifier_table_ref = generator.intern_string(verify_cast<Identifier>(expression.property()).string());
|
||||
generator.emit<Bytecode::Op::PutById>(object_reg, identifier_table_ref);
|
||||
}
|
||||
return;
|
||||
|
@ -628,8 +627,7 @@ void MemberExpression::generate_bytecode(Bytecode::Generator& generator) const
|
|||
property().generate_bytecode(generator);
|
||||
generator.emit<Bytecode::Op::GetByValue>(object_reg);
|
||||
} else {
|
||||
VERIFY(is<Identifier>(property()));
|
||||
auto identifier_table_ref = generator.intern_string(static_cast<Identifier const&>(property()).string());
|
||||
auto identifier_table_ref = generator.intern_string(verify_cast<Identifier>(property()).string());
|
||||
generator.emit<Bytecode::Op::GetById>(identifier_table_ref);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,8 +200,7 @@ Value Interpreter::execute_statement(GlobalObject& global_object, const Statemen
|
|||
|
||||
FunctionEnvironmentRecord* Interpreter::current_function_environment_record()
|
||||
{
|
||||
VERIFY(is<FunctionEnvironmentRecord>(vm().running_execution_context().lexical_environment));
|
||||
return static_cast<FunctionEnvironmentRecord*>(vm().running_execution_context().lexical_environment);
|
||||
return verify_cast<FunctionEnvironmentRecord>(vm().running_execution_context().lexical_environment);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -193,8 +193,7 @@ EnvironmentRecord& get_this_environment(VM& vm)
|
|||
Object* get_super_constructor(VM& vm)
|
||||
{
|
||||
auto& env = get_this_environment(vm);
|
||||
VERIFY(is<FunctionEnvironmentRecord>(env));
|
||||
auto& active_function = static_cast<FunctionEnvironmentRecord&>(env).function_object();
|
||||
auto& active_function = verify_cast<FunctionEnvironmentRecord>(env).function_object();
|
||||
auto* super_constructor = active_function.prototype();
|
||||
return super_constructor;
|
||||
}
|
||||
|
|
|
@ -459,8 +459,7 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
|
|||
// set the prototype on objects created by constructors that return an object (i.e. NativeFunction subclasses).
|
||||
if (function.constructor_kind() == Function::ConstructorKind::Base && new_target.constructor_kind() == Function::ConstructorKind::Derived && result.is_object()) {
|
||||
if (environment) {
|
||||
VERIFY(is<FunctionEnvironmentRecord>(lexical_environment()));
|
||||
static_cast<FunctionEnvironmentRecord*>(lexical_environment())->replace_this_binding(result);
|
||||
verify_cast<FunctionEnvironmentRecord>(lexical_environment())->replace_this_binding(result);
|
||||
}
|
||||
auto prototype = new_target.get(names.prototype);
|
||||
if (exception())
|
||||
|
@ -502,8 +501,7 @@ String VM::join_arguments(size_t start_index) const
|
|||
Value VM::get_new_target()
|
||||
{
|
||||
auto& env = get_this_environment(*this);
|
||||
VERIFY(is<FunctionEnvironmentRecord>(env));
|
||||
return static_cast<FunctionEnvironmentRecord&>(env).new_target();
|
||||
return verify_cast<FunctionEnvironmentRecord>(env).new_target();
|
||||
}
|
||||
|
||||
Value VM::call_internal(Function& function, Value this_value, Optional<MarkedValueList> arguments)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
|
@ -720,31 +721,27 @@ ALWAYS_INLINE bool is<OpCode_Compare>(const OpCode& opcode)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE const T& to(const OpCode& opcode)
|
||||
ALWAYS_INLINE T const& to(OpCode const& opcode)
|
||||
{
|
||||
VERIFY(is<T>(opcode));
|
||||
return static_cast<const T&>(opcode);
|
||||
return verify_cast<T>(opcode);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE T* to(OpCode* opcode)
|
||||
{
|
||||
VERIFY(is<T>(opcode));
|
||||
return static_cast<T*>(opcode);
|
||||
return verify_cast<T>(opcode);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE const T* to(const OpCode* opcode)
|
||||
ALWAYS_INLINE T const* to(OpCode const* opcode)
|
||||
{
|
||||
VERIFY(is<T>(opcode));
|
||||
return static_cast<const T*>(opcode);
|
||||
return verify_cast<T>(opcode);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE T& to(OpCode& opcode)
|
||||
{
|
||||
VERIFY(is<T>(opcode));
|
||||
return static_cast<T&>(opcode);
|
||||
return verify_cast<T>(opcode);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -450,13 +450,13 @@ void dump_sheet(const CSS::StyleSheet& sheet)
|
|||
dbgln("{}", builder.string_view());
|
||||
}
|
||||
|
||||
void dump_sheet(StringBuilder& builder, const CSS::StyleSheet& sheet)
|
||||
void dump_sheet(StringBuilder& builder, CSS::StyleSheet const& sheet)
|
||||
{
|
||||
VERIFY(is<CSS::CSSStyleSheet>(sheet));
|
||||
auto& css_stylesheet = verify_cast<CSS::CSSStyleSheet>(sheet);
|
||||
|
||||
builder.appendff("CSSStyleSheet{{{}}}: {} rule(s)\n", &sheet, static_cast<const CSS::CSSStyleSheet&>(sheet).rules().size());
|
||||
builder.appendff("CSSStyleSheet{{{}}}: {} rule(s)\n", &sheet, css_stylesheet.rules().size());
|
||||
|
||||
for (auto& rule : static_cast<const CSS::CSSStyleSheet&>(sheet).rules()) {
|
||||
for (auto& rule : css_stylesheet.rules()) {
|
||||
dump_rule(builder, rule);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,7 +276,6 @@ void FrameLoader::resource_did_load()
|
|||
|
||||
if (auto* host_element = browsing_context().host_element()) {
|
||||
// FIXME: Perhaps in the future we'll have a better common base class for <frame> and <iframe>
|
||||
VERIFY(is<HTML::HTMLIFrameElement>(*host_element));
|
||||
verify_cast<HTML::HTMLIFrameElement>(*host_element).nested_browsing_context_did_load({});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue