mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
LibWeb/CSS: Implement rectify_a_numberish_value()
This commit is contained in:
parent
222ca9e2cd
commit
46b55f0f46
Notes:
github-actions[bot]
2025-08-29 10:00:31 +00:00
Author: https://github.com/AtkinsSJ
Commit: 46b55f0f46
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5955
Reviewed-by: https://github.com/trflynn89
2 changed files with 18 additions and 0 deletions
|
@ -112,4 +112,20 @@ String CSSNumericValue::to_string(SerializationParams const& params) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#rectify-a-numberish-value
|
||||||
|
GC::Ref<CSSNumericValue> rectify_a_numberish_value(JS::Realm& realm, CSSNumberish const& numberish, Optional<FlyString> unit)
|
||||||
|
{
|
||||||
|
// To rectify a numberish value num, optionally to a given unit unit (defaulting to "number"), perform the following steps:
|
||||||
|
return numberish.visit(
|
||||||
|
// 1. If num is a CSSNumericValue, return num.
|
||||||
|
[](GC::Root<CSSNumericValue> const& num) -> GC::Ref<CSSNumericValue> {
|
||||||
|
return GC::Ref { *num };
|
||||||
|
},
|
||||||
|
// 2. If num is a double, return a new CSSUnitValue with its value internal slot set to num and its unit
|
||||||
|
// internal slot set to unit.
|
||||||
|
[&realm, &unit](double num) -> GC::Ref<CSSNumericValue> {
|
||||||
|
return CSSUnitValue::create(realm, num, unit.value_or("number"_fly_string));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,6 @@ protected:
|
||||||
// https://drafts.css-houdini.org/css-typed-om-1/#typedefdef-cssnumberish
|
// https://drafts.css-houdini.org/css-typed-om-1/#typedefdef-cssnumberish
|
||||||
using CSSNumberish = Variant<double, GC::Root<CSSNumericValue>>;
|
using CSSNumberish = Variant<double, GC::Root<CSSNumericValue>>;
|
||||||
|
|
||||||
|
GC::Ref<CSSNumericValue> rectify_a_numberish_value(JS::Realm&, CSSNumberish const&, Optional<FlyString> unit = {});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue