LibWeb/CSS: Implement CSSNumericType.equals()

This commit is contained in:
Sam Atkins
2025-08-22 12:53:15 +01:00
committed by Andreas Kling
parent d29084997e
commit 7be645a091
Notes: github-actions[bot] 2025-08-29 09:58:23 +00:00
22 changed files with 181 additions and 16 deletions

View File

@@ -57,4 +57,26 @@ Optional<JS::Value> CSSNumericArray::item_value(size_t index) const
return {};
}
// https://drafts.css-houdini.org/css-typed-om-1/#equal-numeric-value
bool CSSNumericArray::is_equal_numeric_values(GC::Ref<CSSNumericArray> other) const
{
// NB: This is just step 3, moved here to reduce repetition.
// 3. If value1 and value2 are both CSSMathSums, CSSMathProducts, CSSMathMins, or CSSMathMaxs:
{
// 1. If value1s values and value2s values internal slots have different sizes, return false.
if (m_values.size() != other->m_values.size())
return false;
// 2. If any item in value1s values internal slot is not an equal numeric value to the item in value2s values
// internal slot at the same index, return false.
for (auto index = 0u; index < m_values.size(); ++index) {
if (!m_values[index]->is_equal_numeric_value(other->m_values[index]))
return false;
}
// 3. Return true.
return true;
}
}
}