Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/CSS/Parser/DescriptorParsing.cpp (C++)

Code before:
                        // invalid and must be ignored.
                        i64 first_int;
                        if (first_value->is_integer()) {
                            first_int = first_value->as_integer().integer();
                        } else if (first_value->is_keyword() && first_value->as_keyword().to_keyword() == Keyword::Infinite) {
                            first_int = NumericLimits<i64>::min();
                        } else {
                            // FIXME: How should we actually handle calc() when we have no document to absolutize against
                            if (!computation_context.has_value())
                                return nullptr;

                            first_int = first_value->absolutized(computation_context.value())->as_calculated().resolve_integer({}).value();
                        }

                        i64 second_int;
                        if (second_value->is_integer()) {
                            second_int = second_value->as_integer().integer();
                        } else if (second_value->is_keyword() && second_value->as_keyword().to_keyword() == Keyword::Infinite) {
                            second_int = NumericLimits<i64>::max();
                        } else {
                            // FIXME: How should we actually handle calc() when we have no document to absolutize against
                            if (!computation_context.has_value())
                                return nullptr;

                            second_int = second_value->absolutized(computation_context.value())->as_calculated().resolve_integer({}).value();
                        }

                        if (first_int > second_int)
                            return nullptr;

                        return StyleValueList::create({ first_value.release_nonnull(), second_value.release_nonnull() }, StyleValueList::Separator::Space, StyleValueList::Collapsible::No);
                    });
                }
                case DescriptorMetadata::ValueType::CropOrCross: {
                    // crop || cross
                    auto first = parse_keyword_value(tokens);
                    tokens.discard_whitespace();
                    auto second = parse_keyword_value(tokens);

                    if (!first)
                        return nullptr;

                    RefPtr<StyleValue const> crop;
                    RefPtr<StyleValue const> cross;

                    if (first->to_keyword() == Keyword::Crop)
                        crop = first;
                    else if (first->to_keyword() == Keyword::Cross)
                        cross = first;
                    else
                        return nullptr;

Review comment (suggestion):
These two code blocks probably look better put in a lambda with an `infinite_value` argument for `::min()` and `::max()`

Code after:
                            // FIXME: How should we actually handle calc() when we have no document to absolutize against
                            if (!computation_context.has_value())
                                return {};

                            return value.absolutized(computation_context.value())->as_calculated().resolve_integer({}).value();
                        };

                        auto first_value = parse_value();
                        auto second_value = parse_value();

                        if (!first_value || !second_value)
                            return nullptr;

                        // If the lower bound of any range is higher than the upper bound, the entire descriptor is
                        // invalid and must be ignored.
                        auto first_int = resolve_value(*first_value, NumericLimits<i64>::min());
                        auto second_int = resolve_value(*second_value, NumericLimits<i64>::max());

                        if (!first_int.has_value() || !second_int.has_value() || first_int.value() > second_int.value())
                            return nullptr;

                        return StyleValueList::create({ first_value.release_nonnull(), second_value.release_nonnull() }, StyleValueList::Separator::Space, StyleValueList::Collapsible::No);
                    });
                }
                case DescriptorMetadata::ValueType::CropOrCross: {
                    // crop || cross
                    auto first = parse_keyword_value(tokens);
                    tokens.discard_whitespace();
                    auto second = parse_keyword_value(tokens);

                    if (!first)
                        return nullptr;

                    RefPtr<StyleValue const> crop;
                    RefPtr<StyleValue const> cross;

                    if (first->to_keyword() == Keyword::Crop)
                        crop = first;
                    else if (first->to_keyword() == Keyword::Cross)
                        cross = first;
                    else
                        return nullptr;

                    if (!second)
                        return first.release_nonnull();

                    if (crop.is_null() && second->to_keyword() == Keyword::Crop)
                        crop = second.release_nonnull();
                    else if (cross.is_null() && second->to_keyword() == Keyword::Cross)
                        cross = second.release_nonnull();
                    else