Skip to content

Truly independent web browser

LibWeb: Implement CSSFontFeatureValuesMap in Rust

Andreas Kling05541c7085f9
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/interface.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/interface.rs
index 0484c07adb2..29a2835e5e2 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/interface.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/interface.rs
@@ -249,6 +249,12 @@ pub(crate) fn to_interface<T: Interface>(vm: &Vm, value: Value) -> ThrowCompleti
vm.throw_completion(ErrorKind::TypeError, ErrorType::NotAnObjectOfType, &[&T::NAME])
}
+/// The `this` value of an operation of a setlike or maplike, its implementation, and the context of its realm.
+pub(crate) fn this_implementation<T: Interface>(vm: &Vm) -> ThrowCompletionOr<(Gc<Object>, Ref<T>, CallContext<'_>)> {
+ let (wrapper, realm) = this_object(vm, T::wrapper_class(), T::NAME)?;
+ Ok((wrapper, implementation_of(wrapper), CallContext::new(vm, realm)))
+}
+
/// The wrapper of the object in the wrapper world of the realm of the call context, which the first call for that
/// world creates, as Web::Bindings::wrap() does for a C++ implementation object.
pub(crate) fn wrap<T: Interface>(cx: &CallContext, object: Ref<T>) -> Gc<Object> {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/maplike.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/maplike.rs
index f67a9a711c5..aa9e78c972d 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/maplike.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/maplike.rs
@@ -14,12 +14,18 @@ use libjs_rust::api::{
use crate::bindings::CallContext;
use crate::bindings::conversions::{ToJs, to_dom_string};
-use crate::bindings::interface::{Interface, Ref, define_attribute, define_operation, implementation_of, this_object};
+use crate::bindings::interface::{Interface, define_attribute, define_operation, this_implementation};
/// What the implementation of an interface with a maplike declaration, whose keys are strings, implements.
pub(crate) trait Maplike: Interface {
// https://webidl.spec.whatwg.org/#dfn-map-entries
fn map_entries(&self, cx: &CallContext) -> Gc<Map>;
+
+ /// The value of the entry of the key, converted to a JS value, if there is one.
+ fn map_value(&self, cx: &CallContext, key: &Utf16String) -> Option<Value> {
+ let key = key.clone().to_js(cx).expect("a string converts to a JS value");
+ self.map_entries(cx).map_get(key)
+ }
}
/// What the implementation of an interface with a read-write maplike declaration implements, for the operations that
@@ -66,9 +72,9 @@ pub(crate) fn define_maplike_properties(
define_operation(vm, realm, prototype, "has", has, 1);
}
-fn this_implementation<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<(Gc<Object>, Ref<T>, CallContext<'_>)> {
- let (wrapper, realm) = this_object(vm, T::wrapper_class(), T::NAME)?;
- Ok((wrapper, implementation_of(wrapper), CallContext::new(vm, realm)))
+/// The call context of the realm that a collection of a wrapper world lives in.
+pub(crate) fn context_of_map<'vm>(cx: &CallContext<'vm>, map: Gc<Map>) -> CallContext<'vm> {
+ CallContext::new(cx.vm(), map.upcast::<Object>().shape().realm())
}
// https://webidl.spec.whatwg.org/#js-map-size
@@ -165,15 +171,16 @@ fn entries_and_key<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<(Gc<Map>, Value)> {
// https://webidl.spec.whatwg.org/#js-map-get
pub(crate) fn map_get<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "get" and type "method".
- // 2. Let map be the map entries of the IDL value that represents a reference to O.
+ let (_, implementation, cx) = this_implementation::<T>(vm)?;
+
// 3. Let keyType be the key type specified in the maplike declaration.
// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.
// 5. Let key be keyArg converted to an IDL value of type keyType.
- let (map, key) = entries_and_key::<T>(vm)?;
+ let key = to_dom_string(vm, vm.argument(0))?;
// 7. If map[key] exists, then return map[key], converted to a JavaScript value.
// 8. Return undefined.
- Ok(map.map_get(key).unwrap_or(Value::UNDEFINED))
+ Ok(implementation.map_value(&cx, &key).unwrap_or(Value::UNDEFINED))
}
// https://webidl.spec.whatwg.org/#js-map-has
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/setlike.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/setlike.rs
index 4f075a06871..afab417ca60 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/setlike.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/setlike.rs
@@ -14,7 +14,7 @@ use libjs_rust::api::{
};
use crate::bindings::CallContext;
-use crate::bindings::interface::{Interface, Ref, define_attribute, define_operation, implementation_of, this_object};
+use crate::bindings::interface::{Interface, define_attribute, define_operation, this_implementation};
use crate::bindings::realm_data::{WrapperWorld, wrapper_world_of};
/// The JS collection of an object in each wrapper world that asked for it, as the entries of a collection hold the
@@ -111,9 +111,9 @@ pub(crate) fn define_setlike_properties(
define_operation(vm, realm, prototype, "has", has, 1);
}
-fn this_implementation<T: Setlike>(vm: &Vm) -> ThrowCompletionOr<(Gc<Object>, Ref<T>, CallContext<'_>)> {
- let (wrapper, realm) = this_object(vm, T::wrapper_class(), T::NAME)?;
- Ok((wrapper, implementation_of(wrapper), CallContext::new(vm, realm)))
+/// The call context of the realm that a collection of a wrapper world lives in.
+pub(crate) fn context_of_set<'vm>(cx: &CallContext<'vm>, set: Gc<Set>) -> CallContext<'vm> {
+ CallContext::new(cx.vm(), set.upcast::<Object>().shape().realm())
}
// https://webidl.spec.whatwg.org/#js-set-size
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_font_feature_values_map.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_font_feature_values_map.rs
new file mode 100644
index 00000000000..db9cf27546c
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_font_feature_values_map.rs
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2026, Callum Law <[email protected]>
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! CSSFontFeatureValuesMap, https://drafts.csswg.org/css-fonts-4/#cssfontfeaturevaluesmap
+
+use ak::Utf16String;
+use libjs_rust::api::{Array, Gc, Map, Object, Trace, Value, Vm};
+use libweb_rust::FontFeatureValuesRuleKind;
+
+use super::css_font_feature_values_rule::CSSFontFeatureValuesRule;
+use crate::bindings::conversions::ToJs;
+use crate::bindings::interface::{Ref, Wrappable, allocate};
+use crate::bindings::maplike::context_of_map;
+use crate::bindings::maplike::{Maplike, WritableMaplike};
+use crate::bindings::setlike::WorldEntries;
+use crate::bindings::{CallContext, Exception, WebIdlResult};
+// NB: VibratePattern is the only typedef of (unsigned long or sequence<unsigned long>), so the bindings name the union
+// after it.
+use crate::notifications_api::notification::VibratePattern;
+
+fn create_map_value(cx: &CallContext, values: &[u32]) -> Value {
+ let values: Vec<Value> = values.iter().map(|value| Value::from_f64(f64::from(*value))).collect();
+ Value::from_object(Array::create_from(cx.vm(), cx.realm(), &values).upcast::<Object>())
+}
+
+fn set_map_entry(cx: &CallContext, map: Gc<Map>, name: &Utf16String, values: &[u32]) {
+ let key = name.clone().to_js(cx).expect("a string converts to a JS value");
+ map.map_set(cx.vm(), key, create_map_value(cx, values));
+}
+
+// https://drafts.csswg.org/css-fonts-4/#cssfontfeaturevaluesmap
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct CSSFontFeatureValuesMap {
+ #[gc(untraced)]
+ kind: FontFeatureValuesRuleKind,
+ parent_rule: Ref<CSSFontFeatureValuesRule>,
+ map_entries: WorldEntries<Map>,
+}
+
+impl Wrappable for CSSFontFeatureValuesMap {}
+
+impl CSSFontFeatureValuesMap {
+ pub(crate) fn create(
+ vm: &Vm,
+ kind: FontFeatureValuesRuleKind,
+ parent_rule: Ref<CSSFontFeatureValuesRule>,
+ ) -> Ref<Self> {
+ allocate(vm, |_| Self {
+ kind,
+ parent_rule,
+ map_entries: WorldEntries::default(),
+ })
+ }
+
+ fn max_value_count(&self) -> usize {
+ match self.kind {
+ FontFeatureValuesRuleKind::CharacterVariant => 2,
+ FontFeatureValuesRuleKind::Styleset => usize::MAX,
+ _ => 1,
+ }
+ }
+
+ fn entries(&self) -> Vec<(Vec<u16>, Vec<u32>)> {
+ self.parent_rule
+ .rule()
+ .native_rule()
+ .font_feature_values_entries(self.kind)
+ }
+
+ // https://drafts.csswg.org/css-fonts-4/#cssfontfeaturevaluesmap
+ pub(crate) fn set(
+ &self,
+ cx: &mut CallContext,
+ feature_value_name: Utf16String,
+ values: VibratePattern,
+ ) -> WebIdlResult<()> {
+ // The CSSFontFeatureValuesMap interface uses the default map class methods but the set method has different
+ // behavior. It takes a sequence of unsigned integers and associates it with a given featureValueName. The
+ // method behaves the same as the default map class method except that
+
+ // A single unsigned long value is treated as a sequence of a single value.
+ let values = match values {
+ VibratePattern::UnsignedLong(value) => vec![value],
+ VibratePattern::Sequence(values) => values,
+ };
+
+ // The method throws an exception if an invalid number of values is passed in.
+ if values.is_empty() {
+ return Err(Exception::Dom(
+ "InvalidAccessError",
+ Utf16String::from_utf8("CSSFontFeatureValuesMap.set requires at least one value."),
+ ));
+ }
+
+ // If the associated feature value block only allows a limited number of values, the set method throws an
+ // InvalidAccessError exception when the input sequence to set contains more than the limited number of values.
+ // See the description of multi-valued feature value definitions for details on the maximum number of values
+ // allowed for a given type of feature value block.
+ if values.len() > self.max_value_count() {
+ return Err(Exception::Dom(
+ "InvalidAccessError",
+ Utf16String::from_utf8(&format!(
+ "CSSFontFeatureValuesMap.set only allows a maximum of {} values for the associated feature",
+ self.max_value_count()
+ )),
+ ));
+ }
+
+ self.parent_rule.rule().native_rule().set_font_feature_value(
+ self.kind,
+ &feature_value_name.to_utf16(),
+ values.clone(),
+ );
+ self.parent_rule.clear_caches();
+ for map in self.map_entries.live() {
+ set_map_entry(&context_of_map(cx, map), map, &feature_value_name, &values);
+ }
+ Ok(())
+ }
+}
+
+impl Maplike for CSSFontFeatureValuesMap {
+ fn map_entries(&self, cx: &CallContext) -> Gc<Map> {
+ self.map_entries.get_or_create(cx, || {
+ let map = Map::create(cx.vm(), cx.realm());
+ for (name, values) in self.entries() {
+ set_map_entry(cx, map, &Utf16String::from_utf16(&name), &values);
+ }
+ map
+ })
+ }
+
+ /// NB: Each get() converts the sequence of the entry to a new JS array.
+ fn map_value(&self, cx: &CallContext, key: &Utf16String) -> Option<Value> {
+ let key = key.to_utf16();
+ self.entries()
+ .into_iter()
+ .find(|(name, _)| name.as_slice() == key.as_ref())
+ .map(|(_, values)| create_map_value(cx, &values))
+ }
+}
+
+impl WritableMaplike for CSSFontFeatureValuesMap {
+ fn map_set(&self, _: &CallContext, _: Utf16String, _: Value) {
+ unreachable!("the interface declares its own set operation");
+ }
+
+ fn map_remove(&self, cx: &CallContext, key: &Utf16String) -> bool {
+ let removed = self
+ .parent_rule
+ .rule()
+ .native_rule()
+ .remove_font_feature_value(self.kind, &key.to_utf16());
+ if removed {
+ self.parent_rule.clear_caches();
+ for map in self.map_entries.live() {
+ let key = key.clone().to_js(cx).expect("a string converts to a JS value");
+ map.map_remove(cx.vm(), key);
+ }
+ }
+ removed
+ }
+
+ fn map_clear(&self, cx: &CallContext) {
+ self.parent_rule
+ .rule()
+ .native_rule()
+ .clear_font_feature_values(self.kind);
+ self.parent_rule.clear_caches();
+ for map in self.map_entries.live() {
+ map.map_clear(cx.vm());
+ }
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_font_feature_values_rule.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_font_feature_values_rule.rs
index 60c80c79c32..28a36f74d3d 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_font_feature_values_rule.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_font_feature_values_rule.rs
@@ -6,11 +6,9 @@
//! CSSFontFeatureValuesRule, https://drafts.csswg.org/css-fonts/#cssfontfeaturevaluesrule
-use super::css_rule::CSSRule;
+use super::css_font_feature_values_map::CSSFontFeatureValuesMap;
use super::css_rule::impl_rule_wrappable;
-use super::css_rule::{RuleText, wrap_cpp_cell};
-use crate::bindings::conversions::CppInterface;
-use crate::bindings::cpp_cell::CppCell;
+use super::css_rule::{AnyCSSRule, CSSRule, RuleText};
use crate::bindings::interface::{Inherits, Ref, allocate};
use crate::bindings::{CallContext, WebIdlResult};
use ak::Utf16String;
@@ -23,7 +21,7 @@ use libweb_rust::cssom::{FONT_FEATURE_VALUES_KINDS, serialize_identifier, serial
use std::rc::Rc;
unsafe extern "C" {
- fn web_css_font_feature_values_map_create(rule: *mut c_void, kind: u8) -> *mut c_void;
+ fn web_css_font_feature_values_rule_clear_caches(rule: *mut c_void);
}
/// https://infra.spec.whatwg.org/#ascii-whitespace
@@ -35,8 +33,8 @@ fn is_ascii_whitespace(unit: u16) -> bool {
#[gc(crate = libjs_rust)]
pub(crate) struct CSSFontFeatureValuesRule {
rule: CSSRule,
- /// The cells of the CSSFontFeatureValuesMaps of the rule, by the kind of its feature values.
- maps: GcRefCell<[Option<CppCell>; 7]>,
+ /// The CSSFontFeatureValuesMaps of the rule, by the kind of its feature values.
+ maps: GcRefCell<[Option<Ref<CSSFontFeatureValuesMap>>; 7]>,
}
impl_rule_wrappable!(CSSFontFeatureValuesRule);
@@ -59,18 +57,23 @@ impl CSSFontFeatureValuesRule {
&self.rule
}
- fn map(&self, cx: &CallContext, kind: FontFeatureValuesRuleKind) -> CppInterface {
+ /// Drops what the fonts of the document cached from the values of the rule.
+ pub(crate) fn clear_caches(&self) {
+ // SAFETY: The cell is that of this object, which is live.
+ unsafe { web_css_font_feature_values_rule_clear_caches(self.rule.object().cell()) };
+ }
+
+ fn map(&self, cx: &CallContext, kind: FontFeatureValuesRuleKind) -> Ref<CSSFontFeatureValuesMap> {
let index = kind as usize;
- if let Some(map) = &self.maps.borrow()[index] {
- return wrap_cpp_cell(cx, map);
+ if let Some(map) = self.maps.borrow()[index] {
+ return map;
}
- // SAFETY: The cell is that of this object, which is live.
- let map = unsafe { web_css_font_feature_values_map_create(self.rule.object().cell(), kind as u8) };
- // SAFETY: LibWeb returns a live cell.
- let map = unsafe { CppCell::from_raw(map) };
- let result = wrap_cpp_cell(cx, &map);
+ let AnyCSSRule::CSSFontFeatureValuesRule(rule) = self.rule.object() else {
+ unreachable!("this rule is a CSSFontFeatureValuesRule");
+ };
+ let map = CSSFontFeatureValuesMap::create(cx.vm(), kind, rule);
self.maps.borrow_mut(cx.vm())[index] = Some(map);
- result
+ map
}
fn serialized_font_family(&self) -> Utf16String {
@@ -123,37 +126,37 @@ impl CSSFontFeatureValuesRule {
}
// https://drafts.csswg.org/css-fonts/#dom-cssfontfeaturevaluesrule-annotation
- pub(crate) fn annotation(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
+ pub(crate) fn annotation(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSFontFeatureValuesMap>> {
Ok(self.map(cx, FontFeatureValuesRuleKind::Annotation))
}
// https://drafts.csswg.org/css-fonts/#dom-cssfontfeaturevaluesrule-ornaments
- pub(crate) fn ornaments(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
+ pub(crate) fn ornaments(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSFontFeatureValuesMap>> {
Ok(self.map(cx, FontFeatureValuesRuleKind::Ornaments))
}
// https://drafts.csswg.org/css-fonts/#dom-cssfontfeaturevaluesrule-stylistic
- pub(crate) fn stylistic(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
+ pub(crate) fn stylistic(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSFontFeatureValuesMap>> {
Ok(self.map(cx, FontFeatureValuesRuleKind::Stylistic))
}
// https://drafts.csswg.org/css-fonts/#dom-cssfontfeaturevaluesrule-swash
- pub(crate) fn swash(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
+ pub(crate) fn swash(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSFontFeatureValuesMap>> {
Ok(self.map(cx, FontFeatureValuesRuleKind::Swash))
}
// https://drafts.csswg.org/css-fonts/#dom-cssfontfeaturevaluesrule-charactervariant
- pub(crate) fn character_variant(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
+ pub(crate) fn character_variant(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSFontFeatureValuesMap>> {
Ok(self.map(cx, FontFeatureValuesRuleKind::CharacterVariant))
}
// https://drafts.csswg.org/css-fonts/#dom-cssfontfeaturevaluesrule-styleset
- pub(crate) fn styleset(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
+ pub(crate) fn styleset(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSFontFeatureValuesMap>> {
Ok(self.map(cx, FontFeatureValuesRuleKind::Styleset))
}
// https://drafts.csswg.org/css-fonts/#dom-cssfontfeaturevaluesrule-historicalforms
- pub(crate) fn historical_forms(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
+ pub(crate) fn historical_forms(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSFontFeatureValuesMap>> {
Ok(self.map(cx, FontFeatureValuesRuleKind::HistoricalForms))
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/highlight.rs b/Libraries/LibWeb/Bindings/Rust/src/css/highlight.rs
index 34338cd897e..5e705fe690f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/highlight.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/highlight.rs
@@ -10,12 +10,13 @@ use core::cell::{Cell, RefCell};
use core::ffi::c_void;
use std::collections::HashSet;
-use libjs_rust::api::{Gc, GcRefCell, MarkedVec, Object, Set, Trace, Value};
+use libjs_rust::api::{Gc, GcRefCell, MarkedVec, Set, Trace, Value};
use super::css_rule::wrap_cpp_cell;
use crate::bindings::conversions::CppInterface;
use crate::bindings::cpp_cell::CppCell;
use crate::bindings::interface::{Ref, Wrappable, allocate};
+use crate::bindings::setlike::context_of_set;
use crate::bindings::setlike::{Setlike, WorldEntries, WritableSetlike};
use crate::bindings::{CallContext, WebIdlResult};
@@ -41,11 +42,6 @@ fn range_wrapper(cx: &CallContext, range: &CppCell) -> Value {
Value::from_object(wrap_cpp_cell(cx, range).wrapper())
}
-/// The call context of the realm that a collection of a wrapper world lives in.
-fn context_of_set<'vm>(cx: &CallContext<'vm>, set: Gc<Set>) -> CallContext<'vm> {
- CallContext::new(cx.vm(), set.upcast::<Object>().shape().realm())
-}
-
// https://drafts.csswg.org/css-highlight-api-1/#highlight
#[derive(Trace)]
#[gc(crate = libjs_rust)]
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/highlight_registry.rs b/Libraries/LibWeb/Bindings/Rust/src/css/highlight_registry.rs
index fb2068637b6..c8f4979d941 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/highlight_registry.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/highlight_registry.rs
@@ -9,13 +9,14 @@
use core::ffi::c_void;
use ak::Utf16String;
-use libjs_rust::api::{Gc, GcRefCell, Map, MarkedVec, Object, Trace, Value, Vm};
+use libjs_rust::api::{Gc, GcRefCell, Map, MarkedVec, Trace, Value, Vm};
use super::css_rule::wrap_cpp_cell;
use super::highlight::Highlight;
use crate::bindings::conversions::{CppInterface, ToJs};
use crate::bindings::cpp_cell::CppCell;
use crate::bindings::interface::{Ref, Wrappable, allocate, implementation_of, wrap};
+use crate::bindings::maplike::context_of_map;
use crate::bindings::maplike::{Maplike, WritableMaplike};
use crate::bindings::setlike::WorldEntries;
use crate::bindings::{CallContext, WebIdlResult};
@@ -60,11 +61,6 @@ pub(crate) struct HighlightRegistry {
impl Wrappable for HighlightRegistry {}
-/// The call context of the realm that a collection of a wrapper world lives in.
-fn context_of_map<'vm>(cx: &CallContext<'vm>, map: Gc<Map>) -> CallContext<'vm> {
- CallContext::new(cx.vm(), map.upcast::<Object>().shape().realm())
-}
-
fn set_map_entry(cx: &CallContext, map: Gc<Map>, name: &Utf16String, highlight: Ref<Highlight>) {
let key = name.clone().to_js(cx).expect("a string converts to a JS value");
map.map_set(cx.vm(), key, Value::from_object(wrap(cx, highlight)));
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
index 120299647d2..5af4a78976f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
@@ -13,6 +13,7 @@ pub(crate) mod css_counter_style_rule;
pub(crate) mod css_descriptors;
pub(crate) mod css_font_face_descriptors;
pub(crate) mod css_font_face_rule;
+pub(crate) mod css_font_feature_values_map;
pub(crate) mod css_font_feature_values_rule;
pub(crate) mod css_function_declarations;
pub(crate) mod css_function_descriptors;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/lib.rs b/Libraries/LibWeb/Bindings/Rust/src/lib.rs
index f52d303379e..fd1efdc3008 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/lib.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/lib.rs
@@ -125,6 +125,11 @@ pub(crate) mod indexed_db;
not(web_idl_bindings),
allow(dead_code, reason = "only the generated bindings use the interfaces")
)]
+pub(crate) mod notifications_api;
+#[cfg_attr(
+ not(web_idl_bindings),
+ allow(dead_code, reason = "only the generated bindings use the interfaces")
+)]
pub(crate) mod speech;
#[cfg(not(test))]
pub(crate) mod storage_api;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/notifications_api/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/notifications_api/mod.rs
new file mode 100644
index 00000000000..55fee550d30
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/notifications_api/mod.rs
@@ -0,0 +1,9 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! The definitions of the Notifications API that the interfaces implemented in Rust use.
+
+pub(crate) mod notification;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/notifications_api/notification.rs b/Libraries/LibWeb/Bindings/Rust/src/notifications_api/notification.rs
new file mode 100644
index 00000000000..af2ecbbe0b8
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/notifications_api/notification.rs
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+/// The typedef VibratePattern of NotificationsAPI/Notification.idl, whose union (unsigned long or
+/// sequence<unsigned long>) other interfaces also name.
+pub(crate) enum VibratePattern {
+ UnsignedLong(u32),
+ Sequence(Vec<u32>),
+}
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 12c96e338c9..22e896394e0 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -82,7 +82,6 @@ set(SOURCES
CSS/CSSAnimation.cpp
CSS/CSSDescriptors.cpp
CSS/CSSFontFaceRule.cpp
- CSS/CSSFontFeatureValuesMap.cpp
CSS/CSSFontFeatureValuesRule.cpp
CSS/CSSGroupingRule.cpp
CSS/CSSImportRule.cpp
diff --git a/Libraries/LibWeb/CSS/BindingsGlue.h b/Libraries/LibWeb/CSS/BindingsGlue.h
index 3354233ab90..55c92bf4ead 100644
--- a/Libraries/LibWeb/CSS/BindingsGlue.h
+++ b/Libraries/LibWeb/CSS/BindingsGlue.h
@@ -25,7 +25,6 @@
namespace Web::CSS {
-class CSSFontFeatureValuesMap;
class FontFace;
class FontFaceState;
class FontFaceSet;
@@ -40,13 +39,6 @@ inline WebIDL::ExceptionOr<void> register_property(JS::Realm& realm, CSS::Proper
return CSS::register_property(window.associated_document(), definition);
}
-WEB_API GC::Ref<JS::Map> map_entries(JS::Realm&, CSS::CSSFontFeatureValuesMap&);
-WEB_API Optional<JS::Value> map_get(JS::Realm&, CSS::CSSFontFeatureValuesMap&, Utf16View key);
-WEB_API bool map_has(CSS::CSSFontFeatureValuesMap&, Utf16View key);
-WEB_API bool map_remove(CSS::CSSFontFeatureValuesMap&, Utf16View key);
-WEB_API void map_clear(CSS::CSSFontFeatureValuesMap&);
-WEB_API WebIDL::ExceptionOr<void> set(CSS::CSSFontFeatureValuesMap&, Utf16String const& feature_value_name, Variant<u32, Vector<u32>> const& values);
-
WEB_API void resolve_font_face_list_promise(JS::Realm&, WebIDL::Promise const&, Vector<NonnullRefPtr<CSS::FontFaceState>> const&);
WEB_API void resolve_font_face_set_promise(JS::Realm&, WebIDL::Promise const&, CSS::FontFaceSet&);
WEB_API GC::Ref<JS::Set> setlike_entries(JS::Realm&, WrapperWorld const&, CSS::FontFaceSet const&);
diff --git a/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.cpp b/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.cpp
deleted file mode 100644
index c7c636bd742..00000000000
--- a/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 2026, Callum Law <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "CSSFontFeatureValuesMap.h"
-#include <AK/NeverDestroyed.h>
-#include <LibGC/Heap.h>
-#include <LibJS/Runtime/Array.h>
-#include <LibJS/Runtime/Map.h>
-#include <LibJS/Runtime/PrimitiveString.h>
-#include <LibWeb/Bindings/WrapperWorld.h>
-#include <LibWeb/CSS/BindingsGlue.h>
-#include <LibWeb/CSS/CSSFontFeatureValuesRule.h>
-#include <LibWeb/CSS/Parser/RustSyntaxParsing.h>
-#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWeb/WebIDL/ExceptionOr.h>
-
-namespace Web::CSS {
-
-GC_DEFINE_ALLOCATOR(CSSFontFeatureValuesMap);
-
-GC::Ref<CSSFontFeatureValuesMap> CSSFontFeatureValuesMap::create(FontFeatureValuesRuleKind kind, GC::Ref<CSSFontFeatureValuesRule> parent_rule)
-{
- return GC::Heap::the().allocate<CSSFontFeatureValuesMap>(kind, parent_rule);
-}
-
-CSSFontFeatureValuesMap::CSSFontFeatureValuesMap(FontFeatureValuesRuleKind kind, GC::Ref<CSSFontFeatureValuesRule> parent_rule)
- : m_kind(kind)
- , m_parent_rule(parent_rule)
-{
-}
-
-size_t CSSFontFeatureValuesMap::map_size() const
-{
- return Parser::ValueParserFFI::rust_font_feature_values_count(&m_parent_rule->values(), m_kind);
-}
-
-Optional<Vector<u32>> CSSFontFeatureValuesMap::map_get(Utf16View key) const
-{
- auto index = Parser::ValueParserFFI::rust_font_feature_values_find(&m_parent_rule->values(), m_kind, Parser::ffi_utf16_view(key));
- if (index == NumericLimits<size_t>::max())
- return {};
- auto entry = Parser::ValueParserFFI::rust_font_feature_values_at(&m_parent_rule->values(), m_kind, index);
- return Vector<u32> { ReadonlySpan<u32> { entry.values, entry.count } };
-}
-
-bool CSSFontFeatureValuesMap::map_has(Utf16View key) const
-{
- return Parser::ValueParserFFI::rust_font_feature_values_find(&m_parent_rule->values(), m_kind, Parser::ffi_utf16_view(key)) != NumericLimits<size_t>::max();
-}
-
-void CSSFontFeatureValuesMap::map_set(Utf16View key, Vector<u32> const& values)
-{
- Parser::ValueParserFFI::rust_font_feature_values_set(&m_parent_rule->values(), m_kind, Parser::ffi_utf16_view(key), values.data(), values.size());
- m_parent_rule->clear_caches();
-}
-
-bool CSSFontFeatureValuesMap::map_remove(Utf16View key)
-{
- auto removed = Parser::ValueParserFFI::rust_font_feature_values_remove(&m_parent_rule->values(), m_kind, Parser::ffi_utf16_view(key));
- if (removed)
- m_parent_rule->clear_caches();
- return removed;
-}
-
-void CSSFontFeatureValuesMap::map_clear()
-{
- Parser::ValueParserFFI::rust_font_feature_values_clear(&m_parent_rule->values(), m_kind);
- m_parent_rule->clear_caches();
-}
-
-size_t CSSFontFeatureValuesMap::max_value_count() const
-{
- if (m_kind == FontFeatureValuesRuleKind::CharacterVariant)
- return 2;
- if (m_kind == FontFeatureValuesRuleKind::Styleset)
- return NumericLimits<size_t>::max();
- return 1;
-}
-
-OrderedHashMap<Utf16String, Vector<u32>> CSSFontFeatureValuesMap::entries() const
-{
- OrderedHashMap<Utf16String, Vector<u32>> result;
- auto count = map_size();
- for (size_t index = 0; index < count; ++index) {
- auto entry = Parser::ValueParserFFI::rust_font_feature_values_at(&m_parent_rule->values(), m_kind, index);
- result.set(Utf16String::from_utf16({ reinterpret_cast<char16_t const*>(entry.name.utf16), entry.name.length }), Vector<u32> { ReadonlySpan<u32> { entry.values, entry.count } });
- }
- return result;
-}
-
-void CSSFontFeatureValuesMap::visit_edges(GC::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_parent_rule);
-}
-
-}
-
-namespace Web::Bindings {
-
-static WrapperWorldWeakValueCacheMap<CSS::CSSFontFeatureValuesMap, JS::Map>& css_font_feature_values_map_caches()
-{
- static NeverDestroyed<WrapperWorldWeakValueCacheMap<CSS::CSSFontFeatureValuesMap, JS::Map>> caches;
- return *caches;
-}
-
-static WrapperWorldWeakValueCache<JS::Map>& entries_cache_for(CSS::CSSFontFeatureValuesMap& map)
-{
- return css_font_feature_values_map_caches().cache_for(map);
-}
-
-static GC::Ref<JS::Array> create_map_value(JS::Realm& realm, Vector<u32> const& values)
-{
- GC::RootVector<JS::Value> wrapped_values;
- wrapped_values.ensure_capacity(values.size());
-
- for (auto const& value : values)
- wrapped_values.append(JS::Value { value });
-
- return JS::Array::create_from(realm, wrapped_values.span());
-}
-
-static void set_map_entry(JS::Map& map_entries, Utf16View feature_value_name, Vector<u32> const& feature_values)
-{
- auto& map_realm = HTML::relevant_realm(map_entries);
- auto key = GC::make_root(JS::PrimitiveString::create(map_realm.vm(), feature_value_name));
- auto value = GC::make_root(create_map_value(map_realm, feature_values));
- map_entries.map_set(JS::Value { key.ptr() }, JS::Value { value.ptr() });
-}
-
-static void remove_map_entry(JS::Map& map_entries, Utf16View feature_value_name)
-{
- auto& map_realm = HTML::relevant_realm(map_entries);
- auto key = GC::make_root(JS::PrimitiveString::create(map_realm.vm(), feature_value_name));
- map_entries.map_remove(JS::Value { key.ptr() });
-}
-
-static GC::Root<JS::Map> create_map_entries(JS::Realm& realm, CSS::CSSFontFeatureValuesMap const& map)
-{
- auto map_entries = GC::make_root(JS::Map::create(realm));
- for (auto const& entry : map.entries())
- set_map_entry(*map_entries, entry.key, entry.value);
- return map_entries;
-}
-
-GC::Ref<JS::Map> map_entries(JS::Realm& realm, CSS::CSSFontFeatureValuesMap& map)
-{
- auto& wrapper_world = host_defined_wrapper_world(realm);
- auto& cache = entries_cache_for(map);
-
- if (auto map_entries = cache.get(wrapper_world))
- return *map_entries;
-
- auto map_entries = create_map_entries(realm, map);
- cache.set(wrapper_world, map_entries.ptr());
- return GC::Ref { *map_entries };
-}
-
-Optional<JS::Value> map_get(JS::Realm& realm, CSS::CSSFontFeatureValuesMap& map, Utf16View key)
-{
- auto values = map.map_get(key);
- if (!values.has_value())
- return {};
-
- return JS::Value { create_map_value(realm, *values).ptr() };
-}
-
-bool map_has(CSS::CSSFontFeatureValuesMap& map, Utf16View key)
-{
- return map.map_has(key);
-}
-
-static void update_cached_entries(CSS::CSSFontFeatureValuesMap& map, Utf16View key, Vector<u32> const& values)
-{
- entries_cache_for(map).for_each([&](auto& map_entries) {
- set_map_entry(map_entries, key, values);
- });
-}
-
-bool map_remove(CSS::CSSFontFeatureValuesMap& map, Utf16View key)
-{
- auto removed = map.map_remove(key);
- if (removed) {
- entries_cache_for(map).for_each([&](auto& map_entries) {
- remove_map_entry(map_entries, key);
- });
- }
- return removed;
-}
-
-void map_clear(CSS::CSSFontFeatureValuesMap& map)
-{
- map.map_clear();
- entries_cache_for(map).for_each([&](auto& map_entries) {
- map_entries.map_clear();
- });
-}
-
-WebIDL::ExceptionOr<void> set(CSS::CSSFontFeatureValuesMap& map, Utf16String const& feature_value_name, Variant<u32, Vector<u32>> const& values)
-{
- // https://drafts.csswg.org/css-fonts-4/#cssfontfeaturevaluesmap
- // The CSSFontFeatureValuesMap interface uses the default map class methods but the set method has different
- // behavior. It takes a sequence of unsigned integers and associates it with a given featureValueName. The method
- // behaves the same as the default map class method except that
-
- // A single unsigned long value is treated as a sequence of a single value.
- Vector<u32> value_vector = values.visit(
- [](u32 single_value) { return Vector<u32> { single_value }; },
- [](Vector<u32> value_vector) { return value_vector; });
-
- // The method throws an exception if an invalid number of values is passed in.
- if (value_vector.is_empty())
- return WebIDL::InvalidAccessError::create("CSSFontFeatureValuesMap.set requires at least one value."_utf16);
-
- // If the associated feature value block only allows a limited number of values, the set method throws an
- // InvalidAccessError exception when the input sequence to set contains more than the limited number of values. See
- // the description of multi-valued feature value definitions for details on the maximum number of values allowed for
- // a given type of feature value block.
- if (value_vector.size() > map.max_value_count())
- return WebIDL::InvalidAccessError::create(Utf16String::formatted("CSSFontFeatureValuesMap.set only allows a maximum of {} values for the associated feature", map.max_value_count()));
-
- auto key = feature_value_name.utf16_view();
- map.map_set(key, value_vector);
- update_cached_entries(map, key, value_vector);
- return {};
-}
-
-}
diff --git a/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.h b/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.h
deleted file mode 100644
index 8e6723d933c..00000000000
--- a/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2026, Callum Law <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Utf16FlyString.h>
-#include <LibJS/Runtime/MapIterator.h>
-#include <LibWeb/Bindings/CSSFontFeatureValuesMap.h>
-#include <LibWeb/Bindings/Wrappable.h>
-#include <LibWeb/CSS/RustFontFeatureValues.h>
-#include <LibWeb/Forward.h>
-
-namespace Web::CSS {
-
-class CSSFontFeatureValuesMap final : public Bindings::GCAllocatedWrappable {
- WEB_WRAPPABLE(CSSFontFeatureValuesMap, Bindings::GCAllocatedWrappable);
- GC_DECLARE_ALLOCATOR(CSSFontFeatureValuesMap);
-
-public:
- static GC::Ref<CSSFontFeatureValuesMap> create(FontFeatureValuesRuleKind, GC::Ref<CSSFontFeatureValuesRule> parent_rule);
-
- size_t map_size() const;
- OrderedHashMap<Utf16String, Vector<u32>> entries() const;
- Optional<Vector<u32>> map_get(Utf16View key) const;
- bool map_has(Utf16View key) const;
- void map_set(Utf16View key, Vector<u32> const& values);
- bool map_remove(Utf16View key);
- void map_clear();
-
- size_t max_value_count() const;
-
-private:
- CSSFontFeatureValuesMap(FontFeatureValuesRuleKind, GC::Ref<CSSFontFeatureValuesRule> parent_rule);
-
- virtual void visit_edges(GC::Cell::Visitor&) override;
-
- FontFeatureValuesRuleKind m_kind;
- GC::Ref<CSSFontFeatureValuesRule> m_parent_rule;
-};
-
-}
diff --git a/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.idl b/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.idl
index 18bbfe32097..311eac5e8f8 100644
--- a/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.idl
+++ b/Libraries/LibWeb/CSS/CSSFontFeatureValuesMap.idl
@@ -1,5 +1,5 @@
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface CSSFontFeatureValuesMap {
maplike<CSSOMString, sequence<unsigned long>>;
- [ImplementedInBindings] undefined set(CSSOMString featureValueName, (unsigned long or sequence<unsigned long>) values);
+ undefined set(CSSOMString featureValueName, (unsigned long or sequence<unsigned long>) values);
};
diff --git a/Libraries/LibWeb/CSS/CSSRule.cpp b/Libraries/LibWeb/CSS/CSSRule.cpp
index c8133e2d967..cee3e22c5d9 100644
--- a/Libraries/LibWeb/CSS/CSSRule.cpp
+++ b/Libraries/LibWeb/CSS/CSSRule.cpp
@@ -11,7 +11,6 @@
#include <LibWeb/Bindings/RustCSSDescriptors.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Bindings/WrapperWorld.h>
-#include <LibWeb/CSS/CSSFontFeatureValuesMap.h>
#include <LibWeb/CSS/CSSFontFeatureValuesRule.h>
#include <LibWeb/CSS/CSSPositionTryDescriptors.h>
#include <LibWeb/CSS/CSSRule.h>
@@ -52,7 +51,7 @@ void* web_css_style_sheet_import_rule(void* sheet, u64 identity);
void web_css_style_sheet_disconnect_font_faces(void* sheet, NativeRule const* rule);
void web_css_style_sheet_rules_changed(void* sheet);
void web_css_counter_style_rule_changed(void* rule);
-void* web_css_font_feature_values_map_create(void* rule, u8 kind);
+void web_css_font_feature_values_rule_clear_caches(void* rule);
}
static StyleSheetState& state_of_sheet(void* sheet)
@@ -189,10 +188,9 @@ void web_css_counter_style_rule_changed(void* cell)
record_style_rule_declarations_changed(rule);
}
-void* web_css_font_feature_values_map_create(void* rule, u8 kind)
+void web_css_font_feature_values_rule_clear_caches(void* rule)
{
- auto& parent_rule = *static_cast<CSSFontFeatureValuesRule*>(rule);
- return static_cast<GC::Cell*>(CSSFontFeatureValuesMap::create(static_cast<FontFeatureValuesRuleKind>(kind), parent_rule).ptr());
+ static_cast<CSSFontFeatureValuesRule*>(rule)->clear_caches();
}
}
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 3201a8d0531..e4bb22718e9 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -258,7 +258,6 @@ class CounterStyleStyleValue;
class CSSAnimation;
class CSSDescriptors;
class CSSFontFaceRule;
-class CSSFontFeatureValuesMap;
class CSSFontFeatureValuesRule;
class CSSFunctionRule;
class CSSGroupingRule;
diff --git a/Libraries/LibWeb/Rust/src/css/font_feature_values.rs b/Libraries/LibWeb/Rust/src/css/font_feature_values.rs
index 91e35f6fe16..17ed18e38d5 100644
--- a/Libraries/LibWeb/Rust/src/css/font_feature_values.rs
+++ b/Libraries/LibWeb/Rust/src/css/font_feature_values.rs
@@ -85,6 +85,33 @@ impl FontFeatureValuesRule {
Arc::make_mut(&mut self.data.borrow_mut()).families = families;
}
+ pub(crate) fn set_value(&self, kind: FontFeatureValuesRuleKind, name: &[u16], values: Vec<u32>) {
+ Arc::make_mut(&mut self.data.borrow_mut()).set(kind, name, values);
+ }
+
+ pub(crate) fn remove_value(&self, kind: FontFeatureValuesRuleKind, name: &[u16]) -> bool {
+ let mut data = self.data.borrow_mut();
+ let Some(&index) = data.maps[kind as usize].indices.get(name) else {
+ return false;
+ };
+ let map = &mut Arc::make_mut(&mut data).maps[kind as usize];
+ map.indices.remove(name);
+ map.entries.remove(index);
+ for (index, entry) in map.entries.iter().enumerate().skip(index) {
+ *map.indices.get_mut(&entry.name).unwrap() = index;
+ }
+ true
+ }
+
+ pub(crate) fn clear_values(&self, kind: FontFeatureValuesRuleKind) {
+ let mut data = self.data.borrow_mut();
+ if !data.maps[kind as usize].entries.is_empty() {
+ let map = &mut Arc::make_mut(&mut data).maps[kind as usize];
+ map.entries.clear();
+ map.indices.clear();
+ }
+ }
+
pub(crate) fn entries_of(&self, kind: FontFeatureValuesRuleKind) -> Vec<(Vec<u16>, Vec<u32>)> {
let data = self.data.borrow();
data.maps[kind as usize]
@@ -177,7 +204,7 @@ pub unsafe extern "C" fn rust_font_feature_values_set_families(
Arc::make_mut(&mut owner.data.borrow_mut()).families = families;
}
-#[unsafe(no_mangle)]
+#[cfg(test)]
pub extern "C" fn rust_font_feature_values_count(
owner: &FontFeatureValuesRule,
kind: FontFeatureValuesRuleKind,
@@ -185,7 +212,7 @@ pub extern "C" fn rust_font_feature_values_count(
owner.data.borrow().maps[kind as usize].entries.len()
}
-#[unsafe(no_mangle)]
+#[cfg(test)]
pub extern "C" fn rust_font_feature_values_find(
owner: &FontFeatureValuesRule,
kind: FontFeatureValuesRuleKind,
@@ -201,7 +228,7 @@ pub extern "C" fn rust_font_feature_values_find(
/// # Safety
/// The caller must not change the rule's values while it uses the returned entry.
-#[unsafe(no_mangle)]
+#[cfg(test)]
pub unsafe extern "C" fn rust_font_feature_values_at(
owner: &FontFeatureValuesRule,
kind: FontFeatureValuesRuleKind,
@@ -217,7 +244,7 @@ pub unsafe extern "C" fn rust_font_feature_values_at(
}
}
-#[unsafe(no_mangle)]
+#[cfg(test)]
pub unsafe extern "C" fn rust_font_feature_values_set(
owner: &FontFeatureValuesRule,
kind: FontFeatureValuesRuleKind,
@@ -230,37 +257,21 @@ pub unsafe extern "C" fn rust_font_feature_values_set(
let values = (0..count)
.map(|index| unsafe { *values.add(index) })
.collect::<Vec<_>>();
- Arc::make_mut(&mut owner.data.borrow_mut()).set(kind, &name, values);
+ owner.set_value(kind, &name, values);
}
-#[unsafe(no_mangle)]
+#[cfg(test)]
pub extern "C" fn rust_font_feature_values_remove(
owner: &FontFeatureValuesRule,
kind: FontFeatureValuesRuleKind,
name: FfiUtf16View,
) -> bool {
- let name = name.to_utf16().unwrap();
- let mut data = owner.data.borrow_mut();
- let Some(&index) = data.maps[kind as usize].indices.get(name.as_slice()) else {
- return false;
- };
- let map = &mut Arc::make_mut(&mut data).maps[kind as usize];
- map.indices.remove(name.as_slice());
- map.entries.remove(index);
- for (index, entry) in map.entries.iter().enumerate().skip(index) {
- *map.indices.get_mut(&entry.name).unwrap() = index;
- }
- true
+ owner.remove_value(kind, &name.to_utf16().unwrap())
}
-#[unsafe(no_mangle)]
+#[cfg(test)]
pub extern "C" fn rust_font_feature_values_clear(owner: &FontFeatureValuesRule, kind: FontFeatureValuesRuleKind) {
- let mut data = owner.data.borrow_mut();
- if !data.maps[kind as usize].entries.is_empty() {
- let map = &mut Arc::make_mut(&mut data).maps[kind as usize];
- map.entries.clear();
- map.indices.clear();
- }
+ owner.clear_values(kind);
}
/// The OpenType features a style asks of a font, by tag, the later setting of a tag winning.
diff --git a/Libraries/LibWeb/Rust/src/css/rule/cssom.rs b/Libraries/LibWeb/Rust/src/css/rule/cssom.rs
index f7c249a1e0f..2f67a388024 100644
--- a/Libraries/LibWeb/Rust/src/css/rule/cssom.rs
+++ b/Libraries/LibWeb/Rust/src/css/rule/cssom.rs
@@ -547,6 +547,18 @@ impl NativeRule {
values
}
+ pub fn set_font_feature_value(&self, kind: FontFeatureValuesRuleKind, name: &[u16], values: Vec<u32>) {
+ self.font_feature_values().set_value(kind, name, values);
+ }
+
+ pub fn remove_font_feature_value(&self, kind: FontFeatureValuesRuleKind, name: &[u16]) -> bool {
+ self.font_feature_values().remove_value(kind, name)
+ }
+
+ pub fn clear_font_feature_values(&self, kind: FontFeatureValuesRuleKind) {
+ self.font_feature_values().clear_values(kind);
+ }
+
/// The name and the values of each feature value of the kind, in the order of the map.
pub fn font_feature_values_entries(&self, kind: FontFeatureValuesRuleKind) -> Vec<(Vec<u16>, Vec<u32>)> {
self.font_feature_values().entries_of(kind)
diff --git a/Meta/Linters/check_libweb_realm_mentions.py b/Meta/Linters/check_libweb_realm_mentions.py
index 55c939d6222..cfe8232ccc2 100755
--- a/Meta/Linters/check_libweb_realm_mentions.py
+++ b/Meta/Linters/check_libweb_realm_mentions.py
@@ -36,7 +36,7 @@ CHECKED_SUFFIXES = {
# the same change. If it goes up, justify the architecture change here.
ALLOWED_REALM_MENTIONS = {
"Animations": (5, 14, "animation callbacks/events and CSS value materialization still pass spec-selected realms"),
- "CSS": (7, 19, "CSS Typed OM, parser-facing reification, style-value JS materialization, and setlike/maplike glue"),
+ "CSS": (6, 15, "CSS Typed OM, parser-facing reification, style-value JS materialization, and setlike/maplike glue"),
"Clipboard": (4, 16, "clipboard item/data callbacks still materialize JS values in caller-selected realms"),
"ContentSecurityPolicy": (4, 10, "CSP violation/report objects and callbacks still materialize JS-facing values"),
"CookieStore": (2, 19, "cookie-store async callbacks and promise/value materialization still thread realms"),