Truly independent web browser
LibWeb: Release strings that the Rust CSSOM hands to C++
Andreas Kling37e00f230b5a
diff --git a/Libraries/LibWeb/CSS/CSS.cpp b/Libraries/LibWeb/CSS/CSS.cppindex 9a8153df8a9..2daa081d09c 100644--- a/Libraries/LibWeb/CSS/CSS.cpp+++ b/Libraries/LibWeb/CSS/CSS.cpp@@ -45,26 +45,26 @@ void* web_css_namespace_highlight_registry(void* document)bool web_css_namespace_is_registered(void* document, FlatPtr name){- return document_from_abi(document).registered_property_set().contains(Utf16FlyString { Utf16String::from_raw(name) });+ return document_from_abi(document).registered_property_set().contains(Utf16FlyString { Utf16String::adopt_raw(name) });}StyleValueData const* web_css_namespace_parse_initial_value_descriptor(void* document, FlatPtr value){Parser::ParsingParams parsing_params { document_from_abi(document) };- return into_rust(parse_css_descriptor(parsing_params, AtRuleID::Property, DescriptorNameAndID::from_id(DescriptorID::InitialValue), Utf16String::from_raw(value)));+ return into_rust(parse_css_descriptor(parsing_params, AtRuleID::Property, DescriptorNameAndID::from_id(DescriptorID::InitialValue), Utf16String::adopt_raw(value)));}StyleValueData const* web_css_namespace_parse_with_a_syntax(void* document, FlatPtr value, void const* syntax){Parser::ParsingParams parsing_params { document_from_abi(document) };Parser::RustSyntaxHandle handle { Parser::ValueParserFFI::rust_syntax_retain(syntax) };- return into_rust(Parser::parse_with_a_syntax(parsing_params, Utf16String::from_raw(value), handle));+ return into_rust(Parser::parse_with_a_syntax(parsing_params, Utf16String::adopt_raw(value), handle));}void web_css_namespace_register(void* raw_document, FlatPtr name, void const* syntax, bool inherits, StyleValueData const* initial_value){auto& document = document_from_abi(raw_document);- auto property_name = Utf16FlyString { Utf16String::from_raw(name) };+ auto property_name = Utf16FlyString { Utf16String::adopt_raw(name) };CustomPropertyRegistration registered_property {.property_name = property_name,.syntax = Parser::RustSyntaxHandle { syntax },diff --git a/Libraries/LibWeb/CSS/CSSGroupingRule.cpp b/Libraries/LibWeb/CSS/CSSGroupingRule.cppindex 16307896276..83ad3c29cd1 100644--- a/Libraries/LibWeb/CSS/CSSGroupingRule.cpp+++ b/Libraries/LibWeb/CSS/CSSGroupingRule.cpp@@ -50,7 +50,7 @@ static Vector<Parser::RuleContext> rule_context(CSSRule& owner_rule)NativeRule const* web_css_grouping_rule_parse_rule(void* cell, FlatPtr raw_text, bool* declarations_failed){auto& owner_rule = rule_from_cell(cell);- auto text = Utf16String::from_raw(raw_text);+ auto text = Utf16String::adopt_raw(raw_text);auto rule = text.utf16_view();// AD-HOC: The spec doesn't include a declared_namespaces parameter, but we need it to handle parsing of namespaceddiff --git a/Libraries/LibWeb/CSS/CSSKeyframesRule.cpp b/Libraries/LibWeb/CSS/CSSKeyframesRule.cppindex aac13dd82b7..63132c78633 100644--- a/Libraries/LibWeb/CSS/CSSKeyframesRule.cpp+++ b/Libraries/LibWeb/CSS/CSSKeyframesRule.cpp@@ -50,7 +50,7 @@ void web_css_keyframes_rule_renamed(void* cell)NativeRule const* web_css_parse_keyframe_rule(FlatPtr text){- auto parsed_rule = Parser::parse_keyframe_rule(Parser::ParsingParams {}, Utf16String::from_raw(text));+ auto parsed_rule = Parser::parse_keyframe_rule(Parser::ParsingParams {}, Utf16String::adopt_raw(text));if (!parsed_rule.has_value())return nullptr;return Parser::ValueParserFFI::rust_rule_retain(parsed_rule->handle());diff --git a/Libraries/LibWeb/CSS/CSSRule.cpp b/Libraries/LibWeb/CSS/CSSRule.cppindex 4c314d90212..997906d8795 100644--- a/Libraries/LibWeb/CSS/CSSRule.cpp+++ b/Libraries/LibWeb/CSS/CSSRule.cpp@@ -93,7 +93,7 @@ Optional<SourcePosition> CSSRule::source_location() constUtf16String CSSRule::serialized() const{- return Utf16String::from_raw(web_css_rule_serialized(JS::HostABI::vm_to_abi(JS::VM::the()), const_cast<CSSRule*>(this)));+ return Utf16String::adopt_raw(web_css_rule_serialized(JS::HostABI::vm_to_abi(JS::VM::the()), const_cast<CSSRule*>(this)));}GC::Ref<CSSStyleDeclaration> CSSRule::declarations() constdiff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cppindex 7ac35c6e2d1..c231463a9c1 100644--- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp+++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp@@ -153,7 +153,7 @@ static Utf16FlyString property_name_from_utf8(u8 const* name, size_t name_lengthstatic Utf16FlyString property_name_from_raw(FlatPtr property){- return Utf16FlyString { Utf16String::from_raw(property) };+ return Utf16FlyString { Utf16String::adopt_raw(property) };}// NB: Every step that throws throws a NoModificationAllowedError, which the Rust bindings recreate from its message.@@ -183,7 +183,7 @@ FlatPtr web_css_declaration_get_by_name(void* declaration, u8 const* name, size_bool web_css_declaration_set_by_name(void* declaration, u8 const* name, size_t name_length, FlatPtr value, FlatPtr* error_message){- auto text = Utf16String::from_raw(value);+ auto text = Utf16String::adopt_raw(value);return succeeded_or_store_message(declaration_from_cell(declaration).set_property(property_name_from_utf8(name, name_length), text.utf16_view(), u""sv), error_message);}@@ -194,7 +194,7 @@ FlatPtr web_css_declaration_css_text(void* declaration)bool web_css_declaration_set_css_text(void* declaration, FlatPtr text, FlatPtr* error_message){- auto css_text = Utf16String::from_raw(text);+ auto css_text = Utf16String::adopt_raw(text);return succeeded_or_store_message(declaration_from_cell(declaration).set_css_text(css_text.utf16_view()), error_message);}@@ -220,8 +220,8 @@ FlatPtr web_css_declaration_get_property_priority(void* declaration, FlatPtr probool web_css_declaration_set_property(void* declaration, FlatPtr property, FlatPtr value, FlatPtr priority, FlatPtr* error_message){- auto value_text = Utf16String::from_raw(value);- auto priority_text = Utf16String::from_raw(priority);+ auto value_text = Utf16String::adopt_raw(value);+ auto priority_text = Utf16String::adopt_raw(priority);return succeeded_or_store_message(declaration_from_cell(declaration).set_property(property_name_from_raw(property), value_text.utf16_view(), priority_text.utf16_view()), error_message);}diff --git a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Libraries/LibWeb/CSS/CSSStyleSheet.cppindex 1a70a1ce4ab..d6f1d2e7531 100644--- a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp+++ b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp@@ -142,8 +142,8 @@ GC::Ref<StyleSheetList> StyleSheetList::create(StyleScope& scope)void* web_css_style_sheet_construct(void* document, bool has_base_url, FlatPtr base_url, void* media_list, FlatPtr media_text, bool disabled){- auto base_url_text = Utf16String::from_raw(base_url);- auto media_text_string = Utf16String::from_raw(media_text);+ auto base_url_text = Utf16String::adopt_raw(base_url);+ auto media_text_string = Utf16String::adopt_raw(media_text);CSSStyleSheetOptions options;if (has_base_url)@@ -222,7 +222,7 @@ void* web_css_sheet_state_rule_list(void* state)Parser::ValueParserFFI::NativeRule const* web_css_sheet_state_parse_rule(void* state, FlatPtr rule){- auto text = Utf16String::from_raw(rule);+ auto text = Utf16String::adopt_raw(rule);auto parsed_rule = state_of(state).parse_rule(text.utf16_view());if (!parsed_rule.has_value())return nullptr;@@ -241,12 +241,12 @@ void web_css_sheet_state_remove_rule(void* state, u32 index)void* web_css_sheet_state_replace(void* state, FlatPtr text){- return state_of(state).replace(Utf16String::from_raw(text)).ptr();+ return state_of(state).replace(Utf16String::adopt_raw(text)).ptr();}void web_css_sheet_state_replace_rules(void* state, FlatPtr text){- state_of(state).replace_rules(Utf16String::from_raw(text));+ state_of(state).replace_rules(Utf16String::adopt_raw(text));}u32 web_css_style_sheet_list_length(void* scope)diff --git a/Libraries/LibWeb/CSS/FontFaceSet.cpp b/Libraries/LibWeb/CSS/FontFaceSet.cppindex c56fdbd5151..c0cb42302d2 100644--- a/Libraries/LibWeb/CSS/FontFaceSet.cpp+++ b/Libraries/LibWeb/CSS/FontFaceSet.cpp@@ -178,7 +178,7 @@ FlatPtr web_css_font_face_family_name(void* font_face)bool web_css_font_face_unicode_ranges_include_any_of(void* font_face, FlatPtr raw_text){- auto text = Utf16String::from_raw(raw_text);+ auto text = Utf16String::adopt_raw(raw_text);auto const& ranges = state_from_abi(font_face).unicode_ranges();for (auto code_point : text.utf16_view()) {for (auto const& range : ranges) {diff --git a/Libraries/LibWeb/CSS/Serialize.cpp b/Libraries/LibWeb/CSS/Serialize.cppindex 6644b3c94bc..2673052d28a 100644--- a/Libraries/LibWeb/CSS/Serialize.cpp+++ b/Libraries/LibWeb/CSS/Serialize.cpp@@ -21,22 +21,22 @@ static StyleValueFFI::FfiUtf16View ffi_view(Utf16View view)Utf16String serialize_an_identifier_to_utf16(Utf16View ident){- return Utf16String::from_raw(StyleValueFFI::rust_serialize_an_identifier(ffi_view(ident)));+ return Utf16String::adopt_raw(StyleValueFFI::rust_serialize_an_identifier(ffi_view(ident)));}static Utf16String serialize_a_string_to_utf16(Utf16View string){- return Utf16String::from_raw(StyleValueFFI::rust_serialize_a_string(ffi_view(string)));+ return Utf16String::adopt_raw(StyleValueFFI::rust_serialize_a_string(ffi_view(string)));}static Utf16String serialize_a_url_to_utf16(Utf16View url){- return Utf16String::from_raw(StyleValueFFI::rust_serialize_a_url(ffi_view(url)));+ return Utf16String::adopt_raw(StyleValueFFI::rust_serialize_a_url(ffi_view(url)));}static Utf16String serialize_a_number_to_utf16(double value){- return Utf16String::from_raw(StyleValueFFI::rust_serialize_a_number(value));+ return Utf16String::adopt_raw(StyleValueFFI::rust_serialize_a_number(value));}void serialize_an_identifier(StringBuilder& builder, Utf16View ident)diff --git a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cppindex e6e0b142886..5e00ab2dc69 100644--- a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp+++ b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp@@ -108,7 +108,7 @@ static StyleValueData const* into_rust(StyleValue const& value)static PropertyNameAndID property_from_abi(FlatPtr name){- return PropertyNameAndID::from_name(Utf16FlyString { Utf16String::from_raw(name) }).release_value();+ return PropertyNameAndID::from_name(Utf16FlyString { Utf16String::adopt_raw(name) }).release_value();}// A computed style map describes an element's computed style, and a disconnected element has none.@@ -214,7 +214,7 @@ GC::Ref<StylePropertyMap> StylePropertyMap::create(GC::Ref<CSSStyleDeclaration>bool web_css_style_map_property(FlatPtr raw_name, u16* id, FlatPtr* canonical_name){- auto property = PropertyNameAndID::from_name(Utf16FlyString { Utf16String::from_raw(raw_name) });+ auto property = PropertyNameAndID::from_name(Utf16FlyString { Utf16String::adopt_raw(raw_name) });if (!property.has_value())return false;*id = to_underlying(property->id());@@ -327,7 +327,7 @@ bool web_css_style_map_property_is_list_valued(u16 property_id)StyleValueData const* web_css_style_map_parse(void* raw_declaration, u16 property_id, FlatPtr css_text){- auto text = Utf16String::from_raw(css_text);+ auto text = Utf16String::adopt_raw(css_text);auto parsing_params = Parser::ParsingParams {};if (raw_declaration) {if (auto owner_node = declaration_from_abi(raw_declaration).owner_node(); owner_node.has_value())@@ -350,7 +350,7 @@ u8 web_css_style_map_set_value(void* declaration, FlatPtr name, StyleValueData cu8 web_css_style_map_remove(void* declaration, FlatPtr name, FlatPtr* message){- return change_result(declaration_from_abi(declaration).remove_property(Utf16FlyString { Utf16String::from_raw(name) }), message);+ return change_result(declaration_from_abi(declaration).remove_property(Utf16FlyString { Utf16String::adopt_raw(name) }), message);}u8 web_css_style_map_clear(void* declaration, FlatPtr* message)diff --git a/Libraries/LibWeb/CSS/TypedOM.cpp b/Libraries/LibWeb/CSS/TypedOM.cppindex 4a4e3a0b79c..5741a609711 100644--- a/Libraries/LibWeb/CSS/TypedOM.cpp+++ b/Libraries/LibWeb/CSS/TypedOM.cpp@@ -73,7 +73,7 @@ WebIDL::ExceptionOr<GC::Ref<CSSStyleValue>> CSSStyleValue::parse_a_css_style_valFlatPtr error = 0;auto* value = web_css_style_value_parse(vm_abi(), property.to_utf16_string().into_raw(), Utf16String::from_utf16(css_text).into_raw(), &error);if (!value)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, Utf16String::from_raw(error) };+ return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, Utf16String::adopt_raw(error) };return GC::Ref { *static_cast<CSSStyleValue*>(value) };}@@ -82,7 +82,7 @@ Optional<Utf16FlyString> CSSStyleValue::associated_property() constFlatPtr associated_property = 0;if (!web_css_style_value_associated_property(const_cast<CSSStyleValue*>(this), &associated_property))return {};- return Utf16FlyString { Utf16String::from_raw(associated_property) };+ return Utf16FlyString { Utf16String::adopt_raw(associated_property) };}WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> CSSStyleValue::create_an_internal_representation(PropertyNameAndID const& property, PerformTypeCheck perform_type_check) const@@ -90,7 +90,7 @@ WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> CSSStyleValue::create_an_inFlatPtr error = 0;auto const* value = web_css_style_value_create_an_internal_representation(vm_abi(), const_cast<CSSStyleValue*>(this), to_underlying(property.id()), property.name().to_utf16_string().into_raw(), perform_type_check == PerformTypeCheck::Yes, &error);if (!value)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, Utf16String::from_raw(error) };+ return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, Utf16String::adopt_raw(error) };return NonnullRefPtr<StyleValue const> { *StyleValue::adopt_rust_style_value_data(value) };}@@ -122,7 +122,7 @@ NumericType CSSNumericValue::type() constUtf16String CSSNumericValue::to_string() const{- return Utf16String::from_raw(web_css_numeric_value_to_string(const_cast<CSSNumericValue*>(this)));+ return Utf16String::adopt_raw(web_css_numeric_value_to_string(const_cast<CSSNumericValue*>(this)));}Optional<CalcNodeRef> CSSNumericValue::create_calculation_node() const@@ -145,12 +145,12 @@ double CSSUnitValue::value() constUtf16FlyString CSSUnitValue::unit() const{- return Utf16FlyString { Utf16String::from_raw(web_css_unit_value_unit(const_cast<CSSUnitValue*>(this))) };+ return Utf16FlyString { Utf16String::adopt_raw(web_css_unit_value_unit(const_cast<CSSUnitValue*>(this))) };}Utf16String CSSKeywordValue::value() const{- return Utf16String::from_raw(web_css_keyword_value_value(const_cast<CSSKeywordValue*>(this)));+ return Utf16String::adopt_raw(web_css_keyword_value_value(const_cast<CSSKeywordValue*>(this)));}}