1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:17:34 +00:00

AK+Everywhere: Make Variant::visit() respect the Variant's constness

...and fix all the instances of visit() taking non-const arguments.
This commit is contained in:
Ali Mohammad Pur 2022-01-13 17:31:00 +03:30 committed by Ali Mohammad Pur
parent d55c130df5
commit 9de33629da
7 changed files with 44 additions and 31 deletions

View file

@ -2507,7 +2507,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter, GlobalObject&
// AssignmentExpression : LeftHandSideExpression = AssignmentExpression
return m_lhs.visit(
// 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then
[&](NonnullRefPtr<Expression>& lhs) -> ThrowCompletionOr<Value> {
[&](NonnullRefPtr<Expression> const& lhs) -> ThrowCompletionOr<Value> {
// a. Let lref be the result of evaluating LeftHandSideExpression.
// b. ReturnIfAbrupt(lref).
auto reference = TRY(lhs->to_reference(interpreter, global_object));
@ -2534,7 +2534,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter, GlobalObject&
return rhs_result;
},
// 2. Let assignmentPattern be the AssignmentPattern that is covered by LeftHandSideExpression.
[&](NonnullRefPtr<BindingPattern>& pattern) -> ThrowCompletionOr<Value> {
[&](NonnullRefPtr<BindingPattern> const& pattern) -> ThrowCompletionOr<Value> {
// 3. Let rref be the result of evaluating AssignmentExpression.
// 4. Let rval be ? GetValue(rref).
auto rhs_result = TRY(m_rhs->execute(interpreter, global_object)).release_value();

View file

@ -201,7 +201,7 @@ public:
views.empend(view);
return views;
},
[](Utf8View& view) {
[](Utf8View const& view) {
Vector<RegexStringView> views;
auto it = view.begin();
auto previous_newline_position_it = it;

View file

@ -123,10 +123,10 @@ static float resolve_calc_value(CalculatedStyleValue::CalcValue const& calc_valu
{
return calc_value.visit(
[](float value) { return value; },
[&](Length length) {
[&](Length const& length) {
return length.resolved_or_zero(layout_node, reference_for_percent).to_px(layout_node);
},
[&](NonnullOwnPtr<CalculatedStyleValue::CalcSum>& calc_sum) {
[&](NonnullOwnPtr<CalculatedStyleValue::CalcSum> const& calc_sum) {
return resolve_calc_sum(calc_sum, layout_node, reference_for_percent);
},
[](auto&) {
@ -173,7 +173,7 @@ static float resolve_calc_number_value(CalculatedStyleValue::CalcNumberValue con
{
return number_value.visit(
[](float number) { return number; },
[](NonnullOwnPtr<CalculatedStyleValue::CalcNumberSum>& calc_number_sum) {
[](NonnullOwnPtr<CalculatedStyleValue::CalcNumberSum> const& calc_number_sum) {
return resolve_calc_number_sum(calc_number_sum);
});
}

View file

@ -23,16 +23,16 @@ NonnullRefPtr<MediaQuery> MediaQuery::create_not_all()
String MediaFeatureValue::to_string() const
{
return m_value.visit(
[](String& ident) { return serialize_an_identifier(ident); },
[](Length& length) { return length.to_string(); },
[](String const& ident) { return serialize_an_identifier(ident); },
[](Length const& length) { return length.to_string(); },
[](double number) { return String::number(number); });
}
bool MediaFeatureValue::is_same_type(MediaFeatureValue const& other) const
{
return m_value.visit(
[&](String&) { return other.is_ident(); },
[&](Length&) { return other.is_length(); },
[&](String const&) { return other.is_ident(); },
[&](Length const&) { return other.is_length(); },
[&](double) { return other.is_number(); });
}

View file

@ -35,13 +35,13 @@ MatchResult Supports::Condition::evaluate() const
MatchResult Supports::InParens::evaluate() const
{
return value.visit(
[&](NonnullOwnPtr<Condition>& condition) {
[&](NonnullOwnPtr<Condition> const& condition) {
return condition->evaluate();
},
[&](Feature& feature) {
[&](Feature const& feature) {
return feature.evaluate();
},
[&](GeneralEnclosed& general_enclosed) {
[&](GeneralEnclosed const& general_enclosed) {
return general_enclosed.evaluate();
});
}