Truly independent web browser
LibWeb: Intern custom function parameter names
Callum Law44f62cef5f43
diff --git a/Libraries/LibWeb/CSS/CSSFunctionRule.cpp b/Libraries/LibWeb/CSS/CSSFunctionRule.cppindex eff015e50bf..fb1217774e7 100644--- a/Libraries/LibWeb/CSS/CSSFunctionRule.cpp+++ b/Libraries/LibWeb/CSS/CSSFunctionRule.cpp@@ -23,6 +23,8 @@ GC_DEFINE_ALLOCATOR(CSSFunctionRule);static Utf16View parameter_name(Parser::ValueParserFFI::FfiFunctionParameterView const& parameter){+ if (parameter.name.ascii)+ return StringView { reinterpret_cast<char const*>(parameter.name.ascii), parameter.name.length };return { reinterpret_cast<char16_t const*>(parameter.name.utf16), parameter.name.length };}diff --git a/Libraries/LibWeb/Rust/src/css/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/custom_properties.rsindex b94617e29aa..4acee8437f2 100644--- a/Libraries/LibWeb/Rust/src/css/custom_properties.rs+++ b/Libraries/LibWeb/Rust/src/css/custom_properties.rs@@ -2582,11 +2582,11 @@ fn split_function_arguments(tokens: &[ComponentValue]) -> Vec<&[ComponentValue]>}// https://drafts.csswg.org/css-mixins/#resolve-function-styles-fn resolve_function_styles<'a, 'names>(+fn resolve_function_styles<'a>(store: Option<&CustomPropertyStore>,registry: Option<&CustomPropertyRegistry>,local_scope: FunctionLocalScope<'a>,- property_names: impl IntoIterator<Item = &'names [u16]>,+ property_names: impl IntoIterator<Item = impl AsRef<[u16]>>,context: &mut ASFResolutionContext<'a>,recursion_depth: u32,) -> HashMap<Vec<u16>, TokenResolution> {@@ -2622,6 +2622,7 @@ fn resolve_function_styles<'a, 'names>(let mut computed_values = HashMap::new();for name in property_names {+ let name = name.as_ref();let value = resolve_custom_property(store, registry, name, context, recursion_depth + 1);// FIXME: Duplicate parameter names make an @function rule invalid, but the parser currently accepts them. Keep// the pre-refactor behavior where a later failed resolution does not replace an earlier successful one.@@ -2677,7 +2678,7 @@ fn evaluate_a_custom_function<'a>(// registrations.for parameter in &custom_function.signature.parameters {registrations.insert(- parameter.name.units().to_vec(),+ parameter.name.to_utf16().into_owned(),FunctionLocalRegistration {syntax: ¶meter.syntax,initial_tokens: None,@@ -2744,7 +2745,7 @@ fn evaluate_a_custom_function<'a>(// NB: If neither value is valid, the missing declaration represents the guaranteed-invalid value: the// parameter's registration has no initial value, so resolve_function_local_property() returns Invalid.if let Some(value) = value {- argument_rule.insert(parameter.name.units().to_vec(), value);+ argument_rule.insert(parameter.name.to_utf16().into_owned(), value);}}@@ -2764,7 +2765,7 @@ fn evaluate_a_custom_function<'a>(.signature.parameters.iter()- .map(|parameter| parameter.name.units()),+ .map(|parameter| parameter.name.to_utf16()),context,recursion_depth,);diff --git a/Libraries/LibWeb/Rust/src/css/function_signature.rs b/Libraries/LibWeb/Rust/src/css/function_signature.rsindex 2d89c7f6e89..bdaf359c165 100644--- a/Libraries/LibWeb/Rust/src/css/function_signature.rs+++ b/Libraries/LibWeb/Rust/src/css/function_signature.rs@@ -12,7 +12,7 @@ use std::ffi::c_void;use std::sync::Arc;pub(crate) struct FunctionParameterData {- pub(crate) name: CssString,+ pub(crate) name: ak::Utf16FlyString,pub(crate) syntax: Arc<SyntaxNode>,pub(crate) default_value: Option<Arc<StyleValueData>>,}@@ -58,9 +58,9 @@ pub extern "C" fn rust_function_signature_parameter(index: usize,) -> FfiFunctionParameterView<'_> {let parameter = &signature.parameters[index];- let name = parameter.name.units();+ let name = parameter.name.as_units();FfiFunctionParameterView {- name: FfiUtf16View::from_utf16(name),+ name: FfiUtf16View::from_input(name.into()),syntax: Arc::as_ptr(¶meter.syntax).cast(),default_value: parameter.default_valuediff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rsindex e03e5abb3f3..3568ed697e4 100644--- a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs@@ -3584,7 +3584,7 @@ impl<'a> SyntaxParseBuilder<'a> {parameters: parameters.into_iter().map(|parameter| FunctionParameterData {- name: CssString::from_utf16(¶meter.name),+ name: ak::Utf16FlyString::from_utf16(¶meter.name),syntax: parameter.syntax,default_value: parameter.default_value.map(|value| value.0),})diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rsindex 8eacdad75ab..cfbf5b6df9b 100644--- a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs@@ -601,7 +601,7 @@ fn function_signatures_own_parameters_after_the_sheet_is_dropped() {assert_eq!(*signature.parameters[2].syntax, SyntaxNode::Universal);assert!(signature.parameters[2].default_value.is_none());let parameter = &signature.parameters[1];- assert_eq!(parameter.name.units(), utf16("--名"));+ assert_eq!(parameter.name.to_utf16().as_ref(), utf16("--名"));assert_eq!(serialize_style_value_to_utf16(parameter.default_value.as_ref().unwrap()),utf16("\"雪\"")