LibWeb/CSS: Implement CSSNumericValue.to()
Some checks are pending
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run

Tries to convert the CSSNumericValue to a CSSUnitValue with the given
unit.

This gets us the remaining 11 WPT subtests for this method.
This commit is contained in:
Sam Atkins 2025-09-11 17:00:26 +01:00 committed by Jelle Raaijmakers
commit a139ad1c44
Notes: github-actions[bot] 2025-09-12 11:46:37 +00:00
6 changed files with 73 additions and 14 deletions

View file

@ -23,6 +23,29 @@ GC::Ref<CSSUnitValue> CSSUnitValue::create(JS::Realm& realm, double value, FlySt
return realm.create<CSSUnitValue>(realm, value, move(unit), numeric_type.release_value());
}
// https://drafts.css-houdini.org/css-typed-om-1/#create-a-cssunitvalue-from-a-sum-value-item
GC::Ptr<CSSUnitValue> CSSUnitValue::create_from_sum_value_item(JS::Realm& realm, SumValueItem const& item)
{
// 1. If item has more than one entry in its unit map, return failure.
if (item.unit_map.size() > 1)
return {};
// 2. If item has no entries in its unit map, return a new CSSUnitValue whose unit internal slot is set to
// "number", and whose value internal slot is set to items value.
if (item.unit_map.is_empty())
return CSSUnitValue::create(realm, item.value, "number"_fly_string);
// 3. Otherwise, item has a single entry in its unit map. If that entrys value is anything other than 1, return
// failure.
auto single_type_entry = item.unit_map.begin();
if (single_type_entry->value != 1)
return {};
// 4. Otherwise, return a new CSSUnitValue whose unit internal slot is set to that entrys key, and whose value
// internal slot is set to items value.
return CSSUnitValue::create(realm, item.value, single_type_entry->key);
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-cssunitvalue-cssunitvalue
WebIDL::ExceptionOr<GC::Ref<CSSUnitValue>> CSSUnitValue::construct_impl(JS::Realm& realm, double value, FlyString unit)
{