mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:12:45 +00:00 
			
		
		
		
	LibWeb: Port named_item_value from DeprecatedFlyString
This commit is contained in:
		
							parent
							
								
									c7cd6f2bef
								
							
						
					
					
						commit
						b37aab1277
					
				
					 19 changed files with 33 additions and 36 deletions
				
			
		|  | @ -2589,7 +2589,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @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.
 | ||||
|  |  | |||
|  | @ -62,7 +62,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> 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<JS::Value> LegacyPlatformObject::item_value(size_t) const | |||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::Value> LegacyPlatformObject::named_item_value(DeprecatedFlyString const&) const | ||||
| WebIDL::ExceptionOr<JS::Value> LegacyPlatformObject::named_item_value(FlyString const&) const | ||||
| { | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
|  |  | |||
|  | @ -38,7 +38,7 @@ public: | |||
|     JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> legacy_platform_object_get_own_property(JS::PropertyKey const&, IgnoreNamedProps ignore_named_props) const; | ||||
| 
 | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const& name) const; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const; | ||||
|     virtual Vector<DeprecatedString> supported_property_names() const; | ||||
|     virtual bool is_supported_property_index(u32) const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -147,9 +147,9 @@ WebIDL::ExceptionOr<JS::Value> HTMLCollection::item_value(size_t index) const | |||
|     return const_cast<Element*>(element); | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::Value> HTMLCollection::named_item_value(DeprecatedFlyString const& index) const | ||||
| WebIDL::ExceptionOr<JS::Value> 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*>(element); | ||||
|  |  | |||
|  | @ -45,7 +45,7 @@ public: | |||
|     JS::MarkedVector<Element*> collect_matching_elements() const; | ||||
| 
 | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const& name) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const override; | ||||
|     virtual Vector<DeprecatedString> supported_property_names() const override; | ||||
|     virtual bool is_supported_property_index(u32) const override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -327,7 +327,7 @@ WebIDL::ExceptionOr<JS::Value> NamedNodeMap::item_value(size_t index) const | |||
|     return node; | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::Value> NamedNodeMap::named_item_value(DeprecatedFlyString const& name) const | ||||
| WebIDL::ExceptionOr<JS::Value> NamedNodeMap::named_item_value(FlyString const& name) const | ||||
| { | ||||
|     auto const* node = get_named_item(name); | ||||
|     if (!node) | ||||
|  |  | |||
|  | @ -28,7 +28,7 @@ public: | |||
|     virtual bool is_supported_property_index(u32 index) const override; | ||||
|     virtual Vector<DeprecatedString> supported_property_names() const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const& name) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> 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(); } | ||||
|  |  | |||
|  | @ -193,9 +193,9 @@ WebIDL::ExceptionOr<Bindings::LegacyPlatformObject::DidDeletionFail> DOMStringMa | |||
|     return DidDeletionFail::No; | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::Value> DOMStringMap::named_item_value(DeprecatedFlyString const& name) const | ||||
| WebIDL::ExceptionOr<JS::Value> 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())); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -35,7 +35,7 @@ private: | |||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     // ^LegacyPlatformObject
 | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const&) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const&) const override; | ||||
|     virtual Vector<DeprecatedString> supported_property_names() const override; | ||||
| 
 | ||||
|     virtual bool supports_indexed_properties() const override { return false; } | ||||
|  |  | |||
|  | @ -75,7 +75,7 @@ JS::GCPtr<MimeType> MimeTypeArray::item(u32 index) const | |||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/system-state.html#dom-mimetypearray-nameditem
 | ||||
| JS::GCPtr<MimeType> MimeTypeArray::named_item(String const& name) const | ||||
| JS::GCPtr<MimeType> 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::Window>(HTML::relevant_global_object(*this)); | ||||
|  | @ -98,10 +98,9 @@ WebIDL::ExceptionOr<JS::Value> MimeTypeArray::item_value(size_t index) const | |||
|     return return_value.ptr(); | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::Value> MimeTypeArray::named_item_value(DeprecatedFlyString const& name) const | ||||
| WebIDL::ExceptionOr<JS::Value> 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(); | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ public: | |||
| 
 | ||||
|     size_t length() const; | ||||
|     JS::GCPtr<MimeType> item(u32 index) const; | ||||
|     JS::GCPtr<MimeType> named_item(String const& name) const; | ||||
|     JS::GCPtr<MimeType> named_item(FlyString const& name) const; | ||||
| 
 | ||||
| private: | ||||
|     MimeTypeArray(JS::Realm&); | ||||
|  | @ -29,7 +29,7 @@ private: | |||
|     // ^Bindings::LegacyPlatformObject
 | ||||
|     virtual Vector<DeprecatedString> supported_property_names() const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const& name) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> 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; } | ||||
|  |  | |||
|  | @ -98,7 +98,7 @@ JS::GCPtr<MimeType> Plugin::item(u32 index) const | |||
|     return nullptr; | ||||
| } | ||||
| 
 | ||||
| JS::GCPtr<MimeType> Plugin::named_item(String const& name) const | ||||
| JS::GCPtr<MimeType> 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::Window>(HTML::relevant_global_object(*this)); | ||||
|  | @ -121,10 +121,9 @@ WebIDL::ExceptionOr<JS::Value> Plugin::item_value(size_t index) const | |||
|     return return_value.ptr(); | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::Value> Plugin::named_item_value(DeprecatedFlyString const& name) const | ||||
| WebIDL::ExceptionOr<JS::Value> 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(); | ||||
|  |  | |||
|  | @ -22,7 +22,7 @@ public: | |||
|     String filename() const; | ||||
|     size_t length() const; | ||||
|     JS::GCPtr<MimeType> item(u32 index) const; | ||||
|     JS::GCPtr<MimeType> named_item(String const& name) const; | ||||
|     JS::GCPtr<MimeType> named_item(FlyString const& name) const; | ||||
| 
 | ||||
| private: | ||||
|     Plugin(JS::Realm&, String name); | ||||
|  | @ -35,7 +35,7 @@ private: | |||
|     // ^Bindings::LegacyPlatformObject
 | ||||
|     virtual Vector<DeprecatedString> supported_property_names() const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const& name) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> 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; } | ||||
|  |  | |||
|  | @ -84,7 +84,7 @@ JS::GCPtr<Plugin> PluginArray::item(u32 index) const | |||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/system-state.html#dom-pluginarray-nameditem
 | ||||
| JS::GCPtr<Plugin> PluginArray::named_item(String const& name) const | ||||
| JS::GCPtr<Plugin> 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::Window>(HTML::relevant_global_object(*this)); | ||||
|  | @ -107,10 +107,9 @@ WebIDL::ExceptionOr<JS::Value> PluginArray::item_value(size_t index) const | |||
|     return return_value.ptr(); | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::Value> PluginArray::named_item_value(DeprecatedFlyString const& name) const | ||||
| WebIDL::ExceptionOr<JS::Value> 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(); | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ public: | |||
|     void refresh() const; | ||||
|     size_t length() const; | ||||
|     JS::GCPtr<Plugin> item(u32 index) const; | ||||
|     JS::GCPtr<Plugin> named_item(String const& name) const; | ||||
|     JS::GCPtr<Plugin> named_item(FlyString const& name) const; | ||||
| 
 | ||||
| private: | ||||
|     PluginArray(JS::Realm&); | ||||
|  | @ -30,7 +30,7 @@ private: | |||
|     // ^Bindings::LegacyPlatformObject
 | ||||
|     virtual Vector<DeprecatedString> supported_property_names() const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const& name) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> 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; } | ||||
|  |  | |||
|  | @ -157,7 +157,7 @@ Vector<DeprecatedString> Storage::supported_property_names() const | |||
|     return names; | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::Value> Storage::named_item_value(DeprecatedFlyString const& name) const | ||||
| WebIDL::ExceptionOr<JS::Value> Storage::named_item_value(FlyString const& name) const | ||||
| { | ||||
|     auto value = get_item(name); | ||||
|     if (!value.has_value()) | ||||
|  |  | |||
|  | @ -37,7 +37,7 @@ private: | |||
|     virtual void initialize(JS::Realm&) override; | ||||
| 
 | ||||
|     // ^LegacyPlatformObject
 | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const&) const override; | ||||
|     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const&) const override; | ||||
|     virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(DeprecatedString const&) override; | ||||
|     virtual Vector<DeprecatedString> supported_property_names() const override; | ||||
|     virtual WebIDL::ExceptionOr<void> set_value_of_named_property(DeprecatedString const& key, JS::Value value) override; | ||||
|  |  | |||
|  | @ -1481,7 +1481,7 @@ Vector<DeprecatedString> Window::supported_property_names() | |||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/#named-access-on-the-window-object
 | ||||
| WebIDL::ExceptionOr<JS::Value> Window::named_item_value(DeprecatedFlyString const& name) | ||||
| WebIDL::ExceptionOr<JS::Value> 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<JS::Value> 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<HTMLEmbedElement>(element) || is<HTMLFormElement>(element) || is<HTMLImageElement>(element) || is<HTMLObjectElement>(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; | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -194,7 +194,7 @@ public: | |||
|     [[nodiscard]] OrderedHashMap<String, JS::NonnullGCPtr<Navigable>> document_tree_child_navigable_target_name_property_set(); | ||||
| 
 | ||||
|     [[nodiscard]] Vector<DeprecatedString> supported_property_names(); | ||||
|     [[nodiscard]] WebIDL::ExceptionOr<JS::Value> named_item_value(DeprecatedFlyString const&); | ||||
|     [[nodiscard]] WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const&); | ||||
| 
 | ||||
| private: | ||||
|     explicit Window(JS::Realm&); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Shannon Booth
						Shannon Booth