diff --git a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp index 77072b20cc..95f2ee7f08 100644 --- a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp @@ -123,11 +123,11 @@ WebIDL::ExceptionOr LegacyPlatformObject::invoke_indexed_property_setter(J } // https://webidl.spec.whatwg.org/#invoke-named-setter -WebIDL::ExceptionOr LegacyPlatformObject::invoke_named_property_setter(DeprecatedString const& property_name, JS::Value value) +WebIDL::ExceptionOr LegacyPlatformObject::invoke_named_property_setter(String const& property_name, JS::Value value) { // 1. Let creating be true if P is not a supported property name, and false otherwise. Vector supported_property_names = this->supported_property_names(); - bool creating = !supported_property_names.contains_slow(MUST(String::from_deprecated_string(property_name))); + bool creating = !supported_property_names.contains_slow(property_name); // FIXME: We do not have this information at this point, so converting the value is left as an exercise to the inheritor of LegacyPlatformObject. // 2. Let operation be the operation used to declare the indexed property setter. @@ -174,7 +174,7 @@ JS::ThrowCompletionOr LegacyPlatformObject::internal_set(JS::PropertyKey c // 2. If O implements an interface with a named property setter and Type(P) is String, then: if (has_named_property_setter() && property_name.is_string()) { // 1. Invoke the named property setter on O with P and V. - TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(property_name.as_string(), value); })); + TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(MUST(String::from_deprecated_string(property_name.as_string())), value); })); // 2. Return true. return true; @@ -236,7 +236,7 @@ JS::ThrowCompletionOr LegacyPlatformObject::internal_define_own_property(J return false; // 2. Invoke the named property setter on O with P and Desc.[[Value]]. - TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(property_name_as_string, property_descriptor.value.value()); })); + TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(MUST(String::from_deprecated_string(property_name_as_string)), property_descriptor.value.value()); })); // 3. Return true. return true; @@ -291,7 +291,7 @@ JS::ThrowCompletionOr LegacyPlatformObject::internal_delete(JS::PropertyKe // 4. Otherwise, operation was defined with an identifier: // 1. Perform method steps of operation with O as this and « P » as the argument values. // 2. If operation was declared with a return type of boolean and the steps returned false, then return false. - auto did_deletion_fail = TRY(throw_dom_exception_if_needed(vm, [&] { return delete_value(property_name_string); })); + auto did_deletion_fail = TRY(throw_dom_exception_if_needed(vm, [&] { return delete_value(MUST(String::from_deprecated_string(property_name_string))); })); if (!named_property_deleter_has_identifier()) VERIFY(did_deletion_fail != DidDeletionFail::NotRelevant); @@ -339,7 +339,7 @@ JS::ThrowCompletionOr> LegacyPlatformObject::interna if (supports_indexed_properties()) { for (u64 index = 0; index <= NumericLimits::max(); ++index) { if (is_supported_property_index(index)) - keys.append(JS::PrimitiveString::create(vm, DeprecatedString::number(index))); + keys.append(JS::PrimitiveString::create(vm, MUST(String::number(index)))); else break; } diff --git a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h index 5139c0006b..7e43d6b74b 100644 --- a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h +++ b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h @@ -42,12 +42,12 @@ public: // NOTE: These will crash if you make has_named_property_setter return true but do not override these methods. // NOTE: This is only used if named_property_setter_has_identifier returns false, otherwise set_value_of_named_property is used instead. - virtual WebIDL::ExceptionOr set_value_of_new_named_property(DeprecatedString const&, JS::Value) { VERIFY_NOT_REACHED(); } - virtual WebIDL::ExceptionOr set_value_of_existing_named_property(DeprecatedString const&, JS::Value) { VERIFY_NOT_REACHED(); } + virtual WebIDL::ExceptionOr set_value_of_new_named_property(String const&, JS::Value) { VERIFY_NOT_REACHED(); } + virtual WebIDL::ExceptionOr set_value_of_existing_named_property(String const&, JS::Value) { VERIFY_NOT_REACHED(); } // NOTE: These will crash if you make has_named_property_setter return true but do not override these methods. // NOTE: This is only used if you make named_property_setter_has_identifier return true, otherwise set_value_of_{new,existing}_named_property is used instead. - virtual WebIDL::ExceptionOr set_value_of_named_property(DeprecatedString const&, JS::Value) { VERIFY_NOT_REACHED(); } + virtual WebIDL::ExceptionOr set_value_of_named_property(String const&, JS::Value) { VERIFY_NOT_REACHED(); } // NOTE: These will crash if you make has_indexed_property_setter return true but do not override these methods. // NOTE: This is only used if indexed_property_setter_has_identifier returns false, otherwise set_value_of_indexed_property is used instead. @@ -67,7 +67,7 @@ public: }; // NOTE: This will crash if you make has_named_property_deleter return true but do not override this method. - virtual WebIDL::ExceptionOr delete_value(DeprecatedString const&) { VERIFY_NOT_REACHED(); } + virtual WebIDL::ExceptionOr delete_value(String const&) { VERIFY_NOT_REACHED(); } protected: explicit LegacyPlatformObject(JS::Realm& realm); @@ -90,7 +90,7 @@ protected: private: WebIDL::ExceptionOr invoke_indexed_property_setter(JS::PropertyKey const&, JS::Value); - WebIDL::ExceptionOr invoke_named_property_setter(DeprecatedString const&, JS::Value); + WebIDL::ExceptionOr invoke_named_property_setter(String const&, JS::Value); }; } diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp index 1fc599eb11..4502eca601 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp @@ -119,24 +119,26 @@ DeprecatedString DOMStringMap::determine_value_of_named_property(DeprecatedStrin } // https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-setitem -WebIDL::ExceptionOr DOMStringMap::set_value_of_new_named_property(DeprecatedString const& name, JS::Value unconverted_value) +WebIDL::ExceptionOr DOMStringMap::set_value_of_new_named_property(String const& name, JS::Value unconverted_value) { // NOTE: Since LegacyPlatformObject does not know the type of value, we must convert it ourselves. // The type of `value` is `DOMString`. auto value = TRY(unconverted_value.to_string(vm())); - AK::StringBuilder builder; + StringBuilder builder; // 3. Insert the string data- at the front of name. // NOTE: This is done out of order because StringBuilder doesn't have prepend. builder.append("data-"sv); - for (size_t character_index = 0; character_index < name.length(); ++character_index) { - // 1. If name contains a U+002D HYPHEN-MINUS character (-) followed by an ASCII lower alpha, then throw a "SyntaxError" DOMException. - auto current_character = name[character_index]; + auto name_view = name.bytes_as_string_view(); - if (current_character == '-' && character_index + 1 < name.length()) { - auto next_character = name[character_index + 1]; + for (size_t character_index = 0; character_index < name_view.length(); ++character_index) { + // 1. If name contains a U+002D HYPHEN-MINUS character (-) followed by an ASCII lower alpha, then throw a "SyntaxError" DOMException. + auto current_character = name_view[character_index]; + + if (current_character == '-' && character_index + 1 < name_view.length()) { + auto next_character = name_view[character_index + 1]; if (is_ascii_lower_alpha(next_character)) return WebIDL::SyntaxError::create(realm(), "Name cannot contain a '-' followed by a lowercase character."_fly_string); } @@ -162,21 +164,21 @@ WebIDL::ExceptionOr DOMStringMap::set_value_of_new_named_property(Deprecat } // https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-setitem -WebIDL::ExceptionOr DOMStringMap::set_value_of_existing_named_property(DeprecatedString const& name, JS::Value value) +WebIDL::ExceptionOr DOMStringMap::set_value_of_existing_named_property(String const& name, JS::Value value) { return set_value_of_new_named_property(name, value); } // https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-removeitem -WebIDL::ExceptionOr DOMStringMap::delete_value(DeprecatedString const& name) +WebIDL::ExceptionOr DOMStringMap::delete_value(String const& name) { - AK::StringBuilder builder; + StringBuilder builder; // 2. Insert the string data- at the front of name. // NOTE: This is done out of order because StringBuilder doesn't have prepend. builder.append("data-"sv); - for (auto character : name) { + for (auto character : name.bytes_as_string_view()) { // 1. For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase. if (is_ascii_upper_alpha(character)) { builder.append('-'); diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.h b/Userland/Libraries/LibWeb/HTML/DOMStringMap.h index 5ca4398411..a857a1fbb5 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.h +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.h @@ -24,10 +24,10 @@ public: DeprecatedString determine_value_of_named_property(DeprecatedString const&) const; - virtual WebIDL::ExceptionOr set_value_of_new_named_property(DeprecatedString const&, JS::Value) override; - virtual WebIDL::ExceptionOr set_value_of_existing_named_property(DeprecatedString const&, JS::Value) override; + virtual WebIDL::ExceptionOr set_value_of_new_named_property(String const&, JS::Value) override; + virtual WebIDL::ExceptionOr set_value_of_existing_named_property(String const&, JS::Value) override; - virtual WebIDL::ExceptionOr delete_value(DeprecatedString const&) override; + virtual WebIDL::ExceptionOr delete_value(String const&) override; private: explicit DOMStringMap(DOM::Element&); diff --git a/Userland/Libraries/LibWeb/HTML/Storage.cpp b/Userland/Libraries/LibWeb/HTML/Storage.cpp index d428fdf7f8..7c635c87b4 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.cpp +++ b/Userland/Libraries/LibWeb/HTML/Storage.cpp @@ -167,18 +167,18 @@ WebIDL::ExceptionOr Storage::named_item_value(FlyString const& name) return JS::PrimitiveString::create(vm(), value.release_value()); } -WebIDL::ExceptionOr Storage::delete_value(DeprecatedString const& name) +WebIDL::ExceptionOr Storage::delete_value(String const& name) { remove_item(name); return DidDeletionFail::NotRelevant; } -WebIDL::ExceptionOr Storage::set_value_of_named_property(DeprecatedString const& key, JS::Value unconverted_value) +WebIDL::ExceptionOr Storage::set_value_of_named_property(String const& key, JS::Value unconverted_value) { // NOTE: Since LegacyPlatformObject does not know the type of value, we must convert it ourselves. // The type of `value` is `DOMString`. auto value = TRY(unconverted_value.to_string(vm())); - return set_item(String::from_deprecated_string(key).release_value(), value); + return set_item(key, value); } void Storage::dump() const diff --git a/Userland/Libraries/LibWeb/HTML/Storage.h b/Userland/Libraries/LibWeb/HTML/Storage.h index d5096867df..b13f632a5a 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.h +++ b/Userland/Libraries/LibWeb/HTML/Storage.h @@ -39,9 +39,9 @@ private: // ^LegacyPlatformObject virtual WebIDL::ExceptionOr named_item_value(FlyString const&) const override; - virtual WebIDL::ExceptionOr delete_value(DeprecatedString const&) override; + virtual WebIDL::ExceptionOr delete_value(String const&) override; virtual Vector supported_property_names() const override; - virtual WebIDL::ExceptionOr set_value_of_named_property(DeprecatedString const& key, JS::Value value) override; + virtual WebIDL::ExceptionOr set_value_of_named_property(String const& key, JS::Value value) override; virtual bool supports_indexed_properties() const override { return false; } virtual bool supports_named_properties() const override { return true; }