From 82f5be871aaaa6eded9940fdfb7a488fc44f75f6 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 2 Sep 2025 15:50:05 +0100 Subject: [PATCH] LibWeb: Generate the "Numeric Factory" OM methods on the CSS namespace Generating boilerplate is nice! This also has the bonus that we're more correct: I included all the units listed in the spec before, (see https://drafts.css-houdini.org/css-typed-om-1/#numeric-factory ) but we're supposed to exactly include ones for the units we support: > If an implementation supports additional CSS units that do not have a corresponding method in the above list, but that do correspond to one of the existing CSSNumericType values, it must additionally support such a method, named after the unit in its defined canonical casing, using the generic behavior defined above. > If an implementation does not support a given unit, it must not implement its corresponding method from the list above. Now, our factory functions will exactly match the units we support. The changed test result is partly the order being different, and partly that the container-query units are no longer included as we don't actually support them. --- Libraries/LibWeb/CMakeLists.txt | 2 + Libraries/LibWeb/CSS/CSS.cpp | 329 -------------- Libraries/LibWeb/CSS/CSS.h | 78 +--- Libraries/LibWeb/CSS/CSS.idl | 77 +--- Meta/CMake/libweb_generators.cmake | 13 + .../CodeGenerators/LibWeb/CMakeLists.txt | 1 + .../GenerateCSSNumericFactoryMethods.cpp | 178 ++++++++ ...ce-objects-default-property-attributes.txt | 415 ++++++++---------- 8 files changed, 394 insertions(+), 699 deletions(-) create mode 100644 Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSNumericFactoryMethods.cpp diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index be51d4b9d99..f2606377fa9 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -1072,6 +1072,8 @@ set(GENERATED_SOURCES CSS/DescriptorID.cpp CSS/Enums.cpp CSS/EnvironmentVariable.cpp + CSS/GeneratedCSSNumericFactoryMethods.cpp + CSS/GeneratedCSSNumericFactoryMethods.idl CSS/GeneratedCSSStyleProperties.cpp CSS/GeneratedCSSStyleProperties.idl CSS/Keyword.cpp diff --git a/Libraries/LibWeb/CSS/CSS.cpp b/Libraries/LibWeb/CSS/CSS.cpp index 917dc9bcb66..2e926c4a96f 100644 --- a/Libraries/LibWeb/CSS/CSS.cpp +++ b/Libraries/LibWeb/CSS/CSS.cpp @@ -144,333 +144,4 @@ WebIDL::ExceptionOr register_property(JS::VM& vm, PropertyDefinition defin return {}; } -// https://drafts.css-houdini.org/css-typed-om-1/#numeric-factory -inline GC::Ref numeric_factory(JS::VM& vm, WebIDL::Double value, FlyString unit) -{ - // All of the above methods must, when called with a double value, return a new CSSUnitValue whose value internal - // slot is set to value and whose unit internal slot is set to the name of the method as defined here. - return CSSUnitValue::create(*vm.current_realm(), value, move(unit)); -} - -GC::Ref number(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "number"_fly_string); -} - -GC::Ref percent(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "percent"_fly_string); -} - -// -GC::Ref cap(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "cap"_fly_string); -} - -GC::Ref ch(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "ch"_fly_string); -} - -GC::Ref em(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "em"_fly_string); -} - -GC::Ref ex(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "ex"_fly_string); -} - -GC::Ref ic(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "ic"_fly_string); -} - -GC::Ref lh(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "lh"_fly_string); -} - -GC::Ref rcap(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "rcap"_fly_string); -} - -GC::Ref rch(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "rch"_fly_string); -} - -GC::Ref rem(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "rem"_fly_string); -} - -GC::Ref rex(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "rex"_fly_string); -} - -GC::Ref ric(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "ric"_fly_string); -} - -GC::Ref rlh(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "rlh"_fly_string); -} - -GC::Ref vw(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "vw"_fly_string); -} - -GC::Ref vh(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "vh"_fly_string); -} - -GC::Ref vi(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "vi"_fly_string); -} - -GC::Ref vb(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "vb"_fly_string); -} - -GC::Ref vmin(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "vmin"_fly_string); -} - -GC::Ref vmax(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "vmax"_fly_string); -} - -GC::Ref svw(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "svw"_fly_string); -} - -GC::Ref svh(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "svh"_fly_string); -} - -GC::Ref svi(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "svi"_fly_string); -} - -GC::Ref svb(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "svb"_fly_string); -} - -GC::Ref svmin(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "svmin"_fly_string); -} - -GC::Ref svmax(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "svmax"_fly_string); -} - -GC::Ref lvw(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "lvw"_fly_string); -} - -GC::Ref lvh(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "lvh"_fly_string); -} - -GC::Ref lvi(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "lvi"_fly_string); -} - -GC::Ref lvb(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "lvb"_fly_string); -} - -GC::Ref lvmin(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "lvmin"_fly_string); -} - -GC::Ref lvmax(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "lvmax"_fly_string); -} - -GC::Ref dvw(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "dvw"_fly_string); -} - -GC::Ref dvh(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "dvh"_fly_string); -} - -GC::Ref dvi(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "dvi"_fly_string); -} - -GC::Ref dvb(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "dvb"_fly_string); -} - -GC::Ref dvmin(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "dvmin"_fly_string); -} - -GC::Ref dvmax(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "dvmax"_fly_string); -} - -GC::Ref cqw(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "cqw"_fly_string); -} - -GC::Ref cqh(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "cqh"_fly_string); -} - -GC::Ref cqi(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "cqi"_fly_string); -} - -GC::Ref cqb(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "cqb"_fly_string); -} - -GC::Ref cqmin(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "cqmin"_fly_string); -} - -GC::Ref cqmax(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "cqmax"_fly_string); -} - -GC::Ref cm(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "cm"_fly_string); -} - -GC::Ref mm(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "mm"_fly_string); -} - -GC::Ref q(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "q"_fly_string); -} - -GC::Ref in(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "in"_fly_string); -} - -GC::Ref pt(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "pt"_fly_string); -} - -GC::Ref pc(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "pc"_fly_string); -} - -GC::Ref px(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "px"_fly_string); -} - -// -GC::Ref deg(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "deg"_fly_string); -} - -GC::Ref grad(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "grad"_fly_string); -} - -GC::Ref rad(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "rad"_fly_string); -} - -GC::Ref turn(JS::VM& vm, WebIDL::Double value) -{ - return numeric_factory(vm, value, "turn"_fly_string); -} - -//