mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:57:35 +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
10 changed files with 26 additions and 43 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue