From b37aab1277043b60793aaad5c03e3dd134e577af Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 8 Oct 2023 13:16:50 +1300 Subject: [PATCH] LibWeb: Port named_item_value from DeprecatedFlyString --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 2 +- .../Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp | 4 ++-- Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h | 2 +- Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp | 4 ++-- Userland/Libraries/LibWeb/DOM/HTMLCollection.h | 2 +- Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp | 2 +- Userland/Libraries/LibWeb/DOM/NamedNodeMap.h | 2 +- Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/DOMStringMap.h | 2 +- Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp | 7 +++---- Userland/Libraries/LibWeb/HTML/MimeTypeArray.h | 4 ++-- Userland/Libraries/LibWeb/HTML/Plugin.cpp | 7 +++---- Userland/Libraries/LibWeb/HTML/Plugin.h | 4 ++-- Userland/Libraries/LibWeb/HTML/PluginArray.cpp | 7 +++---- Userland/Libraries/LibWeb/HTML/PluginArray.h | 4 ++-- Userland/Libraries/LibWeb/HTML/Storage.cpp | 2 +- Userland/Libraries/LibWeb/HTML/Storage.h | 2 +- Userland/Libraries/LibWeb/HTML/Window.cpp | 6 +++--- Userland/Libraries/LibWeb/HTML/Window.h | 2 +- 19 files changed, 33 insertions(+), 36 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 58e40cb637..ad60df9b32 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -2589,7 +2589,7 @@ JS::ThrowCompletionOr> @named_properties_class@ // 4. If the result of running the named property visibility algorithm with property name P and object object is true, then: if (TRY(is_named_property_exposed_on_object({ &object }, property_name))) { - auto property_name_string = property_name.to_string(); + auto property_name_string = MUST(FlyString::from_deprecated_fly_string(property_name.to_string())); // 1. Let operation be the operation used to declare the named property getter. // 2. Let value be an uninitialized variable. diff --git a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp index a531b2b870..9d95a89f06 100644 --- a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp @@ -62,7 +62,7 @@ JS::ThrowCompletionOr> LegacyPlatformObject::le // 1. If the result of running the named property visibility algorithm with property name P and object O is true, then: if (TRY(WebIDL::is_named_property_exposed_on_object({ this }, property_name))) { // FIXME: It's unfortunate that this is done twice, once in is_named_property_exposed_on_object and here. - auto property_name_string = property_name.to_string(); + auto property_name_string = MUST(FlyString::from_deprecated_fly_string(property_name.to_string())); // 1. Let operation be the operation used to declare the named property getter. // 2. Let value be an uninitialized variable. @@ -376,7 +376,7 @@ WebIDL::ExceptionOr LegacyPlatformObject::item_value(size_t) const return JS::js_undefined(); } -WebIDL::ExceptionOr LegacyPlatformObject::named_item_value(DeprecatedFlyString const&) const +WebIDL::ExceptionOr LegacyPlatformObject::named_item_value(FlyString const&) const { return JS::js_undefined(); } diff --git a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h index 700de6cd80..3316370241 100644 --- a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h +++ b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h @@ -38,7 +38,7 @@ public: JS::ThrowCompletionOr> legacy_platform_object_get_own_property(JS::PropertyKey const&, IgnoreNamedProps ignore_named_props) const; virtual WebIDL::ExceptionOr item_value(size_t index) const; - virtual WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const& name) const; + virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const; virtual Vector supported_property_names() const; virtual bool is_supported_property_index(u32) const; diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp index 93e6fc5a60..20fcc30d0c 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp @@ -147,9 +147,9 @@ WebIDL::ExceptionOr HTMLCollection::item_value(size_t index) const return const_cast(element); } -WebIDL::ExceptionOr HTMLCollection::named_item_value(DeprecatedFlyString const& index) const +WebIDL::ExceptionOr HTMLCollection::named_item_value(FlyString const& index) const { - auto* element = named_item(FlyString::from_deprecated_fly_string(index).release_value()); + auto* element = named_item(index); if (!element) return JS::js_undefined(); return const_cast(element); diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h index 1e9185078f..9e031b5850 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h @@ -45,7 +45,7 @@ public: JS::MarkedVector collect_matching_elements() const; virtual WebIDL::ExceptionOr item_value(size_t index) const override; - virtual WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const& name) const override; + virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const override; virtual Vector supported_property_names() const override; virtual bool is_supported_property_index(u32) const override; diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp index 729878bc9f..8d85ce7e7e 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp @@ -327,7 +327,7 @@ WebIDL::ExceptionOr NamedNodeMap::item_value(size_t index) const return node; } -WebIDL::ExceptionOr NamedNodeMap::named_item_value(DeprecatedFlyString const& name) const +WebIDL::ExceptionOr NamedNodeMap::named_item_value(FlyString const& name) const { auto const* node = get_named_item(name); if (!node) diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h index 61ef322fb4..82fd1d5af2 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h @@ -28,7 +28,7 @@ public: virtual bool is_supported_property_index(u32 index) const override; virtual Vector supported_property_names() const override; virtual WebIDL::ExceptionOr item_value(size_t index) const override; - virtual WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const& name) const override; + virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const override; size_t length() const { return m_attributes.size(); } bool is_empty() const { return m_attributes.is_empty(); } diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp index e452c31a19..d953fbd80d 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp @@ -193,9 +193,9 @@ WebIDL::ExceptionOr DOMStringMa return DidDeletionFail::No; } -WebIDL::ExceptionOr DOMStringMap::named_item_value(DeprecatedFlyString const& name) const +WebIDL::ExceptionOr DOMStringMap::named_item_value(FlyString const& name) const { - return JS::PrimitiveString::create(vm(), determine_value_of_named_property(name)); + return JS::PrimitiveString::create(vm(), determine_value_of_named_property(name.to_deprecated_fly_string())); } } diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.h b/Userland/Libraries/LibWeb/HTML/DOMStringMap.h index ecae5ade8e..b28a245340 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.h +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.h @@ -35,7 +35,7 @@ private: virtual void visit_edges(Cell::Visitor&) override; // ^LegacyPlatformObject - virtual WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const&) const override; + virtual WebIDL::ExceptionOr named_item_value(FlyString const&) const override; virtual Vector supported_property_names() const override; virtual bool supports_indexed_properties() const override { return false; } diff --git a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp index eb3363f06d..7800119769 100644 --- a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp +++ b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp @@ -75,7 +75,7 @@ JS::GCPtr MimeTypeArray::item(u32 index) const } // https://html.spec.whatwg.org/multipage/system-state.html#dom-mimetypearray-nameditem -JS::GCPtr MimeTypeArray::named_item(String const& name) const +JS::GCPtr MimeTypeArray::named_item(FlyString const& name) const { // 1. For each MimeType mimeType of this's relevant global object's PDF viewer mime type objects: if mimeType's type is name, then return mimeType. auto& window = verify_cast(HTML::relevant_global_object(*this)); @@ -98,10 +98,9 @@ WebIDL::ExceptionOr MimeTypeArray::item_value(size_t index) const return return_value.ptr(); } -WebIDL::ExceptionOr MimeTypeArray::named_item_value(DeprecatedFlyString const& name) const +WebIDL::ExceptionOr MimeTypeArray::named_item_value(FlyString const& name) const { - auto converted_name = TRY_OR_THROW_OOM(vm(), String::from_deprecated_string(name)); - auto return_value = named_item(converted_name); + auto return_value = named_item(name); if (!return_value) return JS::js_null(); return return_value.ptr(); diff --git a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.h b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.h index 2b3659eec4..58ab56c1a2 100644 --- a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.h +++ b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.h @@ -19,7 +19,7 @@ public: size_t length() const; JS::GCPtr item(u32 index) const; - JS::GCPtr named_item(String const& name) const; + JS::GCPtr named_item(FlyString const& name) const; private: MimeTypeArray(JS::Realm&); @@ -29,7 +29,7 @@ private: // ^Bindings::LegacyPlatformObject virtual Vector supported_property_names() const override; virtual WebIDL::ExceptionOr item_value(size_t index) const override; - virtual WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const& name) const override; + virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const override; virtual bool is_supported_property_index(u32) const override; virtual bool supports_indexed_properties() const override { return true; } diff --git a/Userland/Libraries/LibWeb/HTML/Plugin.cpp b/Userland/Libraries/LibWeb/HTML/Plugin.cpp index c57e8dd2ad..a774ce26ce 100644 --- a/Userland/Libraries/LibWeb/HTML/Plugin.cpp +++ b/Userland/Libraries/LibWeb/HTML/Plugin.cpp @@ -98,7 +98,7 @@ JS::GCPtr Plugin::item(u32 index) const return nullptr; } -JS::GCPtr Plugin::named_item(String const& name) const +JS::GCPtr Plugin::named_item(FlyString const& name) const { // 1. For each MimeType mimeType of this's relevant global object's PDF viewer mime type objects: if mimeType's type is name, then return mimeType. auto& window = verify_cast(HTML::relevant_global_object(*this)); @@ -121,10 +121,9 @@ WebIDL::ExceptionOr Plugin::item_value(size_t index) const return return_value.ptr(); } -WebIDL::ExceptionOr Plugin::named_item_value(DeprecatedFlyString const& name) const +WebIDL::ExceptionOr Plugin::named_item_value(FlyString const& name) const { - auto converted_name = TRY_OR_THROW_OOM(vm(), String::from_deprecated_string(name)); - auto return_value = named_item(converted_name); + auto return_value = named_item(name); if (!return_value) return JS::js_null(); return return_value.ptr(); diff --git a/Userland/Libraries/LibWeb/HTML/Plugin.h b/Userland/Libraries/LibWeb/HTML/Plugin.h index 38b228ec73..64df6de112 100644 --- a/Userland/Libraries/LibWeb/HTML/Plugin.h +++ b/Userland/Libraries/LibWeb/HTML/Plugin.h @@ -22,7 +22,7 @@ public: String filename() const; size_t length() const; JS::GCPtr item(u32 index) const; - JS::GCPtr named_item(String const& name) const; + JS::GCPtr named_item(FlyString const& name) const; private: Plugin(JS::Realm&, String name); @@ -35,7 +35,7 @@ private: // ^Bindings::LegacyPlatformObject virtual Vector supported_property_names() const override; virtual WebIDL::ExceptionOr item_value(size_t index) const override; - virtual WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const& name) const override; + virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const override; virtual bool is_supported_property_index(u32) const override; virtual bool supports_indexed_properties() const override { return true; } diff --git a/Userland/Libraries/LibWeb/HTML/PluginArray.cpp b/Userland/Libraries/LibWeb/HTML/PluginArray.cpp index 69fc717b8e..92c1478ecf 100644 --- a/Userland/Libraries/LibWeb/HTML/PluginArray.cpp +++ b/Userland/Libraries/LibWeb/HTML/PluginArray.cpp @@ -84,7 +84,7 @@ JS::GCPtr PluginArray::item(u32 index) const } // https://html.spec.whatwg.org/multipage/system-state.html#dom-pluginarray-nameditem -JS::GCPtr PluginArray::named_item(String const& name) const +JS::GCPtr PluginArray::named_item(FlyString const& name) const { // 1. For each Plugin plugin of this's relevant global object's PDF viewer plugin objects: if plugin's name is name, then return plugin. auto& window = verify_cast(HTML::relevant_global_object(*this)); @@ -107,10 +107,9 @@ WebIDL::ExceptionOr PluginArray::item_value(size_t index) const return return_value.ptr(); } -WebIDL::ExceptionOr PluginArray::named_item_value(DeprecatedFlyString const& name) const +WebIDL::ExceptionOr PluginArray::named_item_value(FlyString const& name) const { - auto converted_name = TRY_OR_THROW_OOM(vm(), String::from_deprecated_string(name)); - auto return_value = named_item(converted_name); + auto return_value = named_item(name); if (!return_value) return JS::js_null(); return return_value.ptr(); diff --git a/Userland/Libraries/LibWeb/HTML/PluginArray.h b/Userland/Libraries/LibWeb/HTML/PluginArray.h index 2d6739c738..d1f1afb9a7 100644 --- a/Userland/Libraries/LibWeb/HTML/PluginArray.h +++ b/Userland/Libraries/LibWeb/HTML/PluginArray.h @@ -20,7 +20,7 @@ public: void refresh() const; size_t length() const; JS::GCPtr item(u32 index) const; - JS::GCPtr named_item(String const& name) const; + JS::GCPtr named_item(FlyString const& name) const; private: PluginArray(JS::Realm&); @@ -30,7 +30,7 @@ private: // ^Bindings::LegacyPlatformObject virtual Vector supported_property_names() const override; virtual WebIDL::ExceptionOr item_value(size_t index) const override; - virtual WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const& name) const override; + virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const override; virtual bool is_supported_property_index(u32) const override; virtual bool supports_indexed_properties() const override { return true; } diff --git a/Userland/Libraries/LibWeb/HTML/Storage.cpp b/Userland/Libraries/LibWeb/HTML/Storage.cpp index 66a2124965..e681043d84 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.cpp +++ b/Userland/Libraries/LibWeb/HTML/Storage.cpp @@ -157,7 +157,7 @@ Vector Storage::supported_property_names() const return names; } -WebIDL::ExceptionOr Storage::named_item_value(DeprecatedFlyString const& name) const +WebIDL::ExceptionOr Storage::named_item_value(FlyString const& name) const { auto value = get_item(name); if (!value.has_value()) diff --git a/Userland/Libraries/LibWeb/HTML/Storage.h b/Userland/Libraries/LibWeb/HTML/Storage.h index d1a523a026..382953c908 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.h +++ b/Userland/Libraries/LibWeb/HTML/Storage.h @@ -37,7 +37,7 @@ private: virtual void initialize(JS::Realm&) override; // ^LegacyPlatformObject - virtual WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const&) const override; + virtual WebIDL::ExceptionOr named_item_value(FlyString const&) const override; virtual WebIDL::ExceptionOr delete_value(DeprecatedString const&) override; virtual Vector supported_property_names() const override; virtual WebIDL::ExceptionOr set_value_of_named_property(DeprecatedString const& key, JS::Value value) override; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 8432e5c93b..ac4a4beb17 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1481,7 +1481,7 @@ Vector Window::supported_property_names() } // https://html.spec.whatwg.org/#named-access-on-the-window-object -WebIDL::ExceptionOr Window::named_item_value(DeprecatedFlyString const& name) +WebIDL::ExceptionOr Window::named_item_value(FlyString const& name) { // To determine the value of a named property name in a Window object window, the user agent must return the value obtained using the following steps: @@ -1515,9 +1515,9 @@ WebIDL::ExceptionOr Window::named_item_value(DeprecatedFlyString cons // whose filter matches only named objects of window with the name name. (By definition, these will all be elements.) return DOM::HTMLCollection::create(associated_document(), DOM::HTMLCollection::Scope::Descendants, [name](auto& element) -> bool { if ((is(element) || is(element) || is(element) || is(element)) - && (element.attribute(AttributeNames::name) == name.view())) + && (element.attribute(AttributeNames::name) == name)) return true; - return element.attribute(AttributeNames::id) == name.view(); + return element.attribute(AttributeNames::id) == name; }); } diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 5ce5347e0f..9eeaa87335 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -194,7 +194,7 @@ public: [[nodiscard]] OrderedHashMap> document_tree_child_navigable_target_name_property_set(); [[nodiscard]] Vector supported_property_names(); - [[nodiscard]] WebIDL::ExceptionOr named_item_value(DeprecatedFlyString const&); + [[nodiscard]] WebIDL::ExceptionOr named_item_value(FlyString const&); private: explicit Window(JS::Realm&);