Truly independent web browser
LibWeb: Remove unused unresolved value constructor arguments
Callum Laweb974f5a3ca5
diff --git a/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp b/Libraries/LibWeb/CSS/CSSUnparsedValue.cppindex 8af3449be58..48518a45105 100644--- a/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp+++ b/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp@@ -166,7 +166,7 @@ WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> CSSUnparsedValue::create_anif (Parser::Parser::collect_arbitrary_substitution_function_presence(utf16_string, substitution_presence).is_error())return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid arbitrary substitution function syntax"_utf16 };- return UnresolvedStyleValue::create(move(utf16_string), substitution_presence, {}, UnresolvedStyleValue::SourceTextMode::Preserve);+ return UnresolvedStyleValue::create(move(utf16_string), substitution_presence, UnresolvedStyleValue::SourceTextMode::Preserve);}}diff --git a/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cppindex af0353889e5..bc14bee60f4 100644--- a/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp+++ b/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp@@ -14,20 +14,13 @@namespace Web::CSS {-static StyleValueFFI::StyleValueData const* create_rust_style_value_from_source(Utf16String const& token_source, Parser::SubstitutionFunctionsPresence substitution_presence, Optional<Utf16String> const& original_source_text, UnresolvedStyleValue::SourceTextMode source_text_mode, bool contains_attr_tainted_values, StyleValue const* parsed_value)+static StyleValueFFI::StyleValueData const* create_rust_style_value_from_source(Utf16String const& token_source, Parser::SubstitutionFunctionsPresence substitution_presence, UnresolvedStyleValue::SourceTextMode source_text_mode, bool contains_attr_tainted_values, StyleValue const* parsed_value){auto token_source_view = token_source.utf16_view();- Utf16View original_source_text_view;- if (original_source_text.has_value())- original_source_text_view = original_source_text->utf16_view();return StyleValueFFI::rust_style_value_create_unresolved_from_source(token_source_view.has_ascii_storage() ? reinterpret_cast<u8 const*>(token_source_view.ascii_span().data()) : nullptr,token_source_view.has_ascii_storage() ? nullptr : reinterpret_cast<u16 const*>(token_source_view.utf16_span().data()),token_source_view.length_in_code_units(),- original_source_text.has_value(),- original_source_text_view.has_ascii_storage() ? reinterpret_cast<u8 const*>(original_source_text_view.ascii_span().data()) : nullptr,- original_source_text_view.has_ascii_storage() ? nullptr : reinterpret_cast<u16 const*>(original_source_text_view.utf16_span().data()),- original_source_text_view.length_in_code_units(),to_underlying(source_text_mode),substitution_presence.attr,substitution_presence.dashed_function,@@ -47,21 +40,21 @@ Utf16String UnresolvedStyleValue::comparison_text() constreturn source_text().trim_ascii_whitespace();}-ValueComparingNonnullRefPtr<UnresolvedStyleValue const> UnresolvedStyleValue::create_internal(Utf16String token_source, Parser::SubstitutionFunctionsPresence substitution_presence, Optional<Utf16String> original_source_text, SourceTextMode source_text_mode, bool contains_attr_tainted_values, RefPtr<StyleValue const> parsed_value)+ValueComparingNonnullRefPtr<UnresolvedStyleValue const> UnresolvedStyleValue::create_internal(Utf16String token_source, Parser::SubstitutionFunctionsPresence substitution_presence, SourceTextMode source_text_mode, bool contains_attr_tainted_values, RefPtr<StyleValue const> parsed_value){- auto* data = create_rust_style_value_from_source(token_source, substitution_presence, original_source_text, source_text_mode, contains_attr_tainted_values, parsed_value.ptr());+ auto* data = create_rust_style_value_from_source(token_source, substitution_presence, source_text_mode, contains_attr_tainted_values, parsed_value.ptr());return adopt_ref(*new (nothrow) UnresolvedStyleValue(data));}-ValueComparingNonnullRefPtr<UnresolvedStyleValue const> UnresolvedStyleValue::create(Utf16String token_source, Parser::SubstitutionFunctionsPresence substitution_presence, Optional<Utf16String> original_source_text, SourceTextMode source_text_mode, bool contains_attr_tainted_values)+ValueComparingNonnullRefPtr<UnresolvedStyleValue const> UnresolvedStyleValue::create(Utf16String token_source, Parser::SubstitutionFunctionsPresence substitution_presence, SourceTextMode source_text_mode, bool contains_attr_tainted_values){- return create_internal(move(token_source), substitution_presence, move(original_source_text), source_text_mode, contains_attr_tainted_values, nullptr);+ return create_internal(move(token_source), substitution_presence, source_text_mode, contains_attr_tainted_values, nullptr);}-ValueComparingNonnullRefPtr<UnresolvedStyleValue const> UnresolvedStyleValue::create_attr_tainted_with_parsed_value(Utf16String token_source, Parser::SubstitutionFunctionsPresence substitution_presence, Optional<Utf16String> original_source_text, SourceTextMode source_text_mode, NonnullRefPtr<StyleValue const> parsed_value)+ValueComparingNonnullRefPtr<UnresolvedStyleValue const> UnresolvedStyleValue::create_attr_tainted_with_parsed_value(Utf16String token_source, Parser::SubstitutionFunctionsPresence substitution_presence, SourceTextMode source_text_mode, NonnullRefPtr<StyleValue const> parsed_value){VERIFY(!parsed_value->is_unresolved());- return create_internal(move(token_source), substitution_presence, move(original_source_text), source_text_mode, true, move(parsed_value));+ return create_internal(move(token_source), substitution_presence, source_text_mode, true, move(parsed_value));}bool UnresolvedStyleValue::equals(StyleValue const& other) constdiff --git a/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.hindex 0bb83dab9fb..96c1ac05e7b 100644--- a/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h+++ b/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h@@ -25,8 +25,8 @@ public:Preserve,};- static ValueComparingNonnullRefPtr<UnresolvedStyleValue const> create(Utf16String token_source, Parser::SubstitutionFunctionsPresence, Optional<Utf16String> original_source_text = {}, SourceTextMode = SourceTextMode::Trim, bool contains_attr_tainted_values = false);- static ValueComparingNonnullRefPtr<UnresolvedStyleValue const> create_attr_tainted_with_parsed_value(Utf16String token_source, Parser::SubstitutionFunctionsPresence, Optional<Utf16String> original_source_text, SourceTextMode, NonnullRefPtr<StyleValue const> parsed_value);+ static ValueComparingNonnullRefPtr<UnresolvedStyleValue const> create(Utf16String token_source, Parser::SubstitutionFunctionsPresence, SourceTextMode = SourceTextMode::Trim, bool contains_attr_tainted_values = false);+ static ValueComparingNonnullRefPtr<UnresolvedStyleValue const> create_attr_tainted_with_parsed_value(Utf16String token_source, Parser::SubstitutionFunctionsPresence, SourceTextMode, NonnullRefPtr<StyleValue const> parsed_value);virtual ~UnresolvedStyleValue() override = default;bool contains_attr_tainted_values() const { return m_value->unresolved.contains_attr_tainted_values; }@@ -44,7 +44,7 @@ private:{}- static ValueComparingNonnullRefPtr<UnresolvedStyleValue const> create_internal(Utf16String token_source, Parser::SubstitutionFunctionsPresence, Optional<Utf16String> original_source_text, SourceTextMode, bool contains_attr_tainted_values, RefPtr<StyleValue const> parsed_value);+ static ValueComparingNonnullRefPtr<UnresolvedStyleValue const> create_internal(Utf16String token_source, Parser::SubstitutionFunctionsPresence, SourceTextMode, bool contains_attr_tainted_values, RefPtr<StyleValue const> parsed_value);Utf16String comparison_text() const;diff --git a/Libraries/LibWeb/Rust/src/css/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/custom_properties.rsindex c1a54ec585a..768437330c9 100644--- a/Libraries/LibWeb/Rust/src/css/custom_properties.rs+++ b/Libraries/LibWeb/Rust/src/css/custom_properties.rs@@ -543,7 +543,6 @@ impl CustomPropertyRegistry {let source = crate::css::serialize::serialize_resolved_style_value_to_utf16(computed.data());let mut wrapped = crate::css::parser::value_parser::unresolved_value_from_string(&source,- &[],crate::css::parser::arbitrary_substitution::SubstitutionFunctionsPresence::default(),);let StyleValueData::Unresolved {diff --git a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rsindex 6057deb3ee1..f1331fbad7b 100644--- a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs@@ -27,7 +27,8 @@ use crate::css::parser::arbitrary_substitution::{use crate::css::parser::calc_parser::{CalcParseError, parse_a_calc_function_node};use crate::css::parser::color_parser::{is_color_function_name, parse_color_value};use crate::css::parser::component_value::{- ComponentKind, ComponentValue, consume_a_list_of_component_values, consume_a_small_list_of_component_values,+ ComponentKind, ComponentValue, ComponentValueList, consume_a_counted_list_of_component_values,+ consume_a_list_of_component_values, consume_a_small_list_of_component_values,};use crate::css::parser::fonts_parser::parse_font_property;use crate::css::parser::grid_parser::parse_grid_property;@@ -5815,25 +5816,17 @@ fn trim_ascii_whitespace(code_units: &[u16]) -> &[u16] {pub(crate) fn unresolved_value_from_string(unresolved_source: &[u16],- comparison_source: &[u16],presence: SubstitutionFunctionsPresence,) -> StyleValueData {let source_text = trim_ascii_whitespace(unresolved_source);- let component_source = if comparison_source.is_empty() {- source_text- } else {- comparison_source- };- let values =- super::component_value::consume_a_counted_list_of_component_values(tokenize_for_parser(component_source))- .unwrap_or_default();- unresolved_value(source_text, comparison_source, values, presence)+ let values = consume_a_counted_list_of_component_values(tokenize_for_parser(source_text)).unwrap_or_default();+ unresolved_value(source_text, &[], values, presence)}pub(crate) fn unresolved_value(unresolved_source: &[u16],comparison_source: &[u16],- values: impl Into<super::component_value::ComponentValueList>,+ values: impl Into<ComponentValueList>,presence: SubstitutionFunctionsPresence,) -> StyleValueData {let source_text = trim_ascii_whitespace(unresolved_source);diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rsindex 300166ac5ed..2466f116a66 100644--- a/Libraries/LibWeb/Rust/src/css/style_value.rs+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs@@ -19,6 +19,10 @@ use crate::css::css_tokenizer::{ParserSource, ParserTokenKind, SourcePosition, Tuse crate::css::parser::component_value::{ComponentKind, ComponentSerializationMode, ComponentValue, ComponentValueList, ComponentValueSlice,};+use crate::css::serialize::{+ original_component_values_source, serialize_component_values_to_utf16, trim_ascii_whitespace,+ trim_ascii_whitespace_start,+};pub(crate) use crate::css::css_string::{CssString, CssStringList};@@ -3325,8 +3329,8 @@ pub extern "C" fn rust_style_value_create_display(raw: u32) -> *const StyleValueArc::into_raw(Arc::new(StyleValueData::Display { raw }))}-/// Creates an unresolved value from borrowed token source. Rust derives the source and comparison-/// strings according to the requested SourceTextMode and retains the component tree.+/// Creates an unresolved value from borrowed token source, deriving its source text according to+/// the requested SourceTextMode and retaining the component tree.////// Takes ownership of one strong reference to `parsed_value` when it is non-null.#[unsafe(no_mangle)]@@ -3334,10 +3338,6 @@ pub unsafe extern "C" fn rust_style_value_create_unresolved_from_source(token_source_ascii_units: *const u8,token_source_code_units: *const u16,token_source_length: usize,- has_original_source_text: bool,- original_source_text_ascii_units: *const u8,- original_source_text_code_units: *const u16,- original_source_text_length: usize,source_text_mode: u8,presence_attr: bool,presence_dashed_function: bool,@@ -3356,57 +3356,27 @@ pub unsafe extern "C" fn rust_style_value_create_unresolved_from_source(crate::css::css_tokenizer::tokenize_for_parser(token_source),).unwrap_or_default();- let normalized = crate::css::serialize::serialize_component_values_to_utf16(- &components,- crate::css::parser::component_value::ComponentSerializationMode::Normalized,- );- let (source_text, value_comparison_text) = if has_original_source_text {- let original_source_text = unsafe {- TokenizerInput::from_raw_parts(- original_source_text_ascii_units,- original_source_text_code_units,- original_source_text_length,- )- }- .unwrap_or_default();- let mut source_text = Vec::with_capacity(original_source_text.len());- original_source_text.append_to(&mut source_text);- (- crate::css::serialize::trim_ascii_whitespace(&source_text).to_vec(),- crate::css::serialize::trim_ascii_whitespace(&normalized).to_vec(),- )- } else {- let source_text = match source_text_mode {- 0 | 1 => crate::css::serialize::serialize_component_values_to_utf16(- &components,- crate::css::parser::component_value::ComponentSerializationMode::PreserveNumericSource,- ),- 2 => crate::css::serialize::original_component_values_source(&components)- .unwrap_or_else(|| normalized.clone()),- _ => unreachable!("unknown unresolved source text mode"),- };- let source_text = if source_text_mode == 0 {- crate::css::serialize::trim_ascii_whitespace(&source_text)- } else if source_text_mode == 1 {- crate::css::serialize::trim_ascii_whitespace_start(&source_text)- } else {- &source_text- };- (source_text.to_vec(), Vec::new())+ let normalized = serialize_component_values_to_utf16(&components, ComponentSerializationMode::Normalized);+ let source_text = match source_text_mode {+ 0 | 1 => serialize_component_values_to_utf16(&components, ComponentSerializationMode::PreserveNumericSource),+ 2 => original_component_values_source(&components).unwrap_or(normalized),+ _ => unreachable!("unknown unresolved source text mode"),};- let component_source = if value_comparison_text.is_empty() {- &source_text+ let source_text = if source_text_mode == 0 {+ trim_ascii_whitespace(&source_text)+ } else if source_text_mode == 1 {+ trim_ascii_whitespace_start(&source_text)} else {- &value_comparison_text+ &source_text};- let components = RetainedComponentValueList::from_source(component_source);+ let components = RetainedComponentValueList::from_source(source_text);if presence_attr {crate::css::parser::arbitrary_substitution::note_attr_names_read_by(components.as_slice());}Arc::into_raw(Arc::new(StyleValueData::Unresolved {components,- source_text: CssString::from_utf16(&source_text),- value_comparison_text: CssString::from_utf16(&value_comparison_text),+ source_text: CssString::from_utf16(source_text),+ value_comparison_text: CssString::from_utf16(&[]),presence_attr,presence_dashed_function,presence_env,diff --git a/Tests/LibWeb/TestStyleValueEquality.cpp b/Tests/LibWeb/TestStyleValueEquality.cppindex a370e98b4e3..628bf8e971b 100644--- a/Tests/LibWeb/TestStyleValueEquality.cpp+++ b/Tests/LibWeb/TestStyleValueEquality.cpp@@ -159,7 +159,7 @@ TEST_CASE(rust_unresolved_value_retains_cached_parsed_value){RefPtr<StyleValue const> parsed_value = NumberStyleValue::create(42);auto unresolved_value = UnresolvedStyleValue::create_attr_tainted_with_parsed_value(- {}, {}, {}, UnresolvedStyleValue::SourceTextMode::Trim, parsed_value.release_nonnull());+ {}, {}, UnresolvedStyleValue::SourceTextMode::Trim, parsed_value.release_nonnull());auto restored_parsed_value = unresolved_value->parsed_value();EXPECT(restored_parsed_value);@@ -1480,7 +1480,7 @@ TEST_CASE(counter_definitions_equality_is_deep)TEST_CASE(unresolved_equality_trims_only_ascii_whitespace){auto make_unresolved = [](Utf16String source_text) {- return UnresolvedStyleValue::create({}, {}, move(source_text));+ return UnresolvedStyleValue::create(move(source_text), {});};// U+00A0 has the Unicode White_Space property but is not ASCII whitespace; values differing