mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 02:29:21 +00:00
Bindings: Implement is_supported_property_index in terms of item_value
Greatly simplifying the code :^)
This commit is contained in:
parent
c5c1a8fcc7
commit
9b1af542e7
Notes:
github-actions[bot]
2024-07-26 12:27:15 +00:00
Author: https://github.com/shannonbooth
Commit: 9b1af542e7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/827
34 changed files with 4 additions and 138 deletions
|
@ -501,9 +501,9 @@ bool PlatformObject::is_supported_property_name(FlyString const& name) const
|
|||
return supported_property_names().contains_slow(name);
|
||||
}
|
||||
|
||||
bool PlatformObject::is_supported_property_index(u32) const
|
||||
bool PlatformObject::is_supported_property_index(u32 index) const
|
||||
{
|
||||
return false;
|
||||
return item_value(index).has_value();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ protected:
|
|||
virtual JS::Value named_item_value(FlyString const& name) const;
|
||||
virtual Vector<FlyString> supported_property_names() const;
|
||||
virtual bool is_supported_property_name(FlyString const&) const;
|
||||
virtual bool is_supported_property_index(u32) const;
|
||||
bool is_supported_property_index(u32) const;
|
||||
|
||||
// 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.
|
||||
|
|
|
@ -51,13 +51,6 @@ void CSSRuleList::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_rules);
|
||||
}
|
||||
|
||||
bool CSSRuleList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The object’s supported property indices are the numbers in the range zero to one less than the number of CSSRule objects represented by the collection.
|
||||
// If there are no such CSSRule objects, then there are no supported property indices.
|
||||
return index < m_rules.size();
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom/#insert-a-css-rule
|
||||
WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView, CSSRule*> rule, u32 index)
|
||||
{
|
||||
|
|
|
@ -51,7 +51,6 @@ public:
|
|||
auto end() const { return m_rules.end(); }
|
||||
auto end() { return m_rules.end(); }
|
||||
|
||||
virtual bool is_supported_property_index(u32 index) const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
|
||||
WebIDL::ExceptionOr<void> remove_a_css_rule(u32 index);
|
||||
|
|
|
@ -48,15 +48,10 @@ void MediaList::set_media_text(StringView text)
|
|||
m_media = parse_media_query_list(Parser::ParsingContext { realm() }, text);
|
||||
}
|
||||
|
||||
bool MediaList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
return index < length();
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-1/#dom-medialist-item
|
||||
Optional<String> MediaList::item(u32 index) const
|
||||
{
|
||||
if (!is_supported_property_index(index))
|
||||
if (index >= m_media.size())
|
||||
return {};
|
||||
|
||||
return m_media[index]->to_string();
|
||||
|
|
|
@ -31,7 +31,6 @@ public:
|
|||
void append_medium(StringView);
|
||||
void delete_medium(StringView);
|
||||
|
||||
virtual bool is_supported_property_index(u32 index) const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
|
||||
bool evaluate(HTML::Window const&);
|
||||
|
|
|
@ -153,17 +153,6 @@ void StyleSheetList::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_sheets);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom/#ref-for-dfn-supported-property-indices%E2%91%A1
|
||||
bool StyleSheetList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The object’s supported property indices are the numbers in the range zero to one less than the number of CSS style sheets represented by the collection.
|
||||
// If there are no such CSS style sheets, then there are no supported property indices.
|
||||
if (m_sheets.is_empty())
|
||||
return false;
|
||||
|
||||
return index < m_sheets.size();
|
||||
}
|
||||
|
||||
Optional<JS::Value> StyleSheetList::item_value(size_t index) const
|
||||
{
|
||||
if (index >= m_sheets.size())
|
||||
|
|
|
@ -35,7 +35,6 @@ public:
|
|||
|
||||
size_t length() const { return m_sheets.size(); }
|
||||
|
||||
virtual bool is_supported_property_index(u32 index) const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
|
||||
DOM::Document& document() { return m_document; }
|
||||
|
|
|
@ -98,12 +98,6 @@ void DOMTokenList::associated_attribute_changed(StringView value)
|
|||
append_to_ordered_set(m_token_set, String::from_utf8(split_value).release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-indices%E2%91%A3
|
||||
bool DOMTokenList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
return index < m_token_set.size();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-item
|
||||
Optional<String> DOMTokenList::item(size_t index) const
|
||||
{
|
||||
|
|
|
@ -30,7 +30,6 @@ public:
|
|||
|
||||
void associated_attribute_changed(StringView value);
|
||||
|
||||
virtual bool is_supported_property_index(u32 index) const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
|
||||
size_t length() const { return m_token_set.size(); }
|
||||
|
|
|
@ -161,14 +161,6 @@ Vector<FlyString> HTMLCollection::supported_property_names() const
|
|||
return result;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-indices%E2%91%A1
|
||||
bool HTMLCollection::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The object’s supported property indices are the numbers in the range zero to one less than the number of elements represented by the collection.
|
||||
// If there are no such elements, then there are no supported property indices.
|
||||
return index < length();
|
||||
}
|
||||
|
||||
Optional<JS::Value> HTMLCollection::item_value(size_t index) const
|
||||
{
|
||||
auto* element = item(index);
|
||||
|
|
|
@ -44,7 +44,6 @@ public:
|
|||
virtual JS::Value named_item_value(FlyString const& name) const override;
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual bool is_supported_property_name(FlyString const&) const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
||||
protected:
|
||||
HTMLCollection(ParentNode& root, Scope, ESCAPING Function<bool(Element const&)> filter);
|
||||
|
|
|
@ -93,12 +93,4 @@ Node const* LiveNodeList::item(u32 index) const
|
|||
return nodes[index];
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-indices
|
||||
bool LiveNodeList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The object’s supported property indices are the numbers in the range zero to one less than the number of nodes represented by the collection.
|
||||
// If there are no such elements, then there are no supported property indices.
|
||||
return index < length();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ public:
|
|||
virtual u32 length() const override;
|
||||
virtual Node const* item(u32 index) const override;
|
||||
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
||||
protected:
|
||||
LiveNodeList(JS::Realm&, Node const& root, Scope, ESCAPING Function<bool(Node const&)> filter);
|
||||
|
||||
|
|
|
@ -47,12 +47,6 @@ void NamedNodeMap::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_attributes);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-indices%E2%91%A3
|
||||
bool NamedNodeMap::is_supported_property_index(u32 index) const
|
||||
{
|
||||
return index < m_attributes.size();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-names%E2%91%A0
|
||||
Vector<FlyString> NamedNodeMap::supported_property_names() const
|
||||
{
|
||||
|
|
|
@ -24,7 +24,6 @@ public:
|
|||
[[nodiscard]] static JS::NonnullGCPtr<NamedNodeMap> create(Element&);
|
||||
~NamedNodeMap() = default;
|
||||
|
||||
virtual bool is_supported_property_index(u32 index) const override;
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
virtual JS::Value named_item_value(FlyString const& name) const override;
|
||||
|
|
|
@ -33,9 +33,4 @@ Optional<JS::Value> NodeList::item_value(size_t index) const
|
|||
return const_cast<Node*>(node);
|
||||
}
|
||||
|
||||
bool NodeList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
return index < length();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ public:
|
|||
virtual Node const* item(u32 index) const = 0;
|
||||
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
||||
protected:
|
||||
explicit NodeList(JS::Realm&);
|
||||
|
|
|
@ -47,12 +47,4 @@ Node const* StaticNodeList::item(u32 index) const
|
|||
return m_static_nodes[index];
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-indices
|
||||
bool StaticNodeList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The object’s supported property indices are the numbers in the range zero to one less than the number of nodes represented by the collection.
|
||||
// If there are no such elements, then there are no supported property indices.
|
||||
return index < m_static_nodes.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ public:
|
|||
virtual u32 length() const override;
|
||||
virtual Node const* item(u32 index) const override;
|
||||
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
||||
private:
|
||||
StaticNodeList(JS::Realm&, Vector<JS::Handle<Node>>);
|
||||
|
||||
|
|
|
@ -45,17 +45,6 @@ void FileList::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(FileList);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dfn-item
|
||||
bool FileList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// Supported property indices are the numbers in the range zero to one less than the number of File objects represented by the FileList object.
|
||||
// If there are no such File objects, then there are no supported property indices.
|
||||
if (m_files.is_empty())
|
||||
return false;
|
||||
|
||||
return index < m_files.size();
|
||||
}
|
||||
|
||||
Optional<JS::Value> FileList::item_value(size_t index) const
|
||||
{
|
||||
if (index >= m_files.size())
|
||||
|
|
|
@ -42,7 +42,6 @@ public:
|
|||
return index < m_files.size() ? m_files[index].ptr() : nullptr;
|
||||
}
|
||||
|
||||
virtual bool is_supported_property_index(u32 index) const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
|
||||
virtual StringView interface_name() const override { return "FileList"sv; }
|
||||
|
|
|
@ -61,11 +61,6 @@ DOMRect const* DOMRectList::item(u32 index) const
|
|||
return m_rects[index];
|
||||
}
|
||||
|
||||
bool DOMRectList::is_supported_property_index(u32 index) const
|
||||
{
|
||||
return index < m_rects.size();
|
||||
}
|
||||
|
||||
Optional<JS::Value> DOMRectList::item_value(size_t index) const
|
||||
{
|
||||
if (index >= m_rects.size())
|
||||
|
|
|
@ -26,7 +26,6 @@ public:
|
|||
u32 length() const;
|
||||
DOMRect const* item(u32 index) const;
|
||||
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -214,11 +214,6 @@ Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, E
|
|||
return get_the_all_named_elements(MUST(FlyString::from_deprecated_fly_string(name_or_index.as_string())));
|
||||
}
|
||||
|
||||
bool HTMLAllCollection::is_supported_property_index(u32 index) const
|
||||
{
|
||||
return index < collect_matching_elements().size();
|
||||
}
|
||||
|
||||
Optional<JS::Value> HTMLAllCollection::item_value(size_t index) const
|
||||
{
|
||||
if (auto value = get_the_all_indexed_element(index))
|
||||
|
|
|
@ -37,7 +37,6 @@ public:
|
|||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
virtual JS::Value named_item_value(FlyString const& name) const override;
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
||||
protected:
|
||||
HTMLAllCollection(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter);
|
||||
|
|
|
@ -927,13 +927,6 @@ void HTMLFormElement::plan_to_navigate_to(URL::URL url, Variant<Empty, String, P
|
|||
VERIFY(m_planned_navigation);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#the-form-element:supported-property-indices
|
||||
bool HTMLFormElement::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The supported property indices at any instant are the indices supported by the object returned by the elements attribute at that instant.
|
||||
return index < elements()->length();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-item
|
||||
Optional<JS::Value> HTMLFormElement::item_value(size_t index) const
|
||||
{
|
||||
|
|
|
@ -109,7 +109,6 @@ private:
|
|||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
virtual JS::Value named_item_value(FlyString const& name) const override;
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
||||
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
|
||||
|
||||
|
|
|
@ -50,14 +50,6 @@ Vector<FlyString> MimeTypeArray::supported_property_names() const
|
|||
return mime_types;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewing-support:supports-indexed-properties-2
|
||||
bool MimeTypeArray::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The MimeTypeArray interface supports indexed properties. The supported property indices are the indices of this's relevant global object's PDF viewer mime type objects.
|
||||
auto& window = verify_cast<HTML::Window>(HTML::relevant_global_object(*this));
|
||||
return index < window.pdf_viewer_mime_type_objects().size();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-mimetypearray-length
|
||||
size_t MimeTypeArray::length() const
|
||||
{
|
||||
|
|
|
@ -31,7 +31,6 @@ private:
|
|||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
virtual JS::Value named_item_value(FlyString const& name) const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -74,14 +74,6 @@ Vector<FlyString> Plugin::supported_property_names() const
|
|||
return mime_types;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewing-support:supports-indexed-properties-3
|
||||
bool Plugin::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The Plugin interface supports indexed properties. The supported property indices are the indices of this's relevant global object's PDF viewer mime type objects.
|
||||
auto& window = verify_cast<HTML::Window>(HTML::relevant_global_object(*this));
|
||||
return index < window.pdf_viewer_mime_type_objects().size();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-plugin-length
|
||||
size_t Plugin::length() const
|
||||
{
|
||||
|
|
|
@ -37,7 +37,6 @@ private:
|
|||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
virtual JS::Value named_item_value(FlyString const& name) const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -59,14 +59,6 @@ Vector<FlyString> PluginArray::supported_property_names() const
|
|||
return plugin_names;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewing-support:supports-indexed-properties
|
||||
bool PluginArray::is_supported_property_index(u32 index) const
|
||||
{
|
||||
// The PluginArray interface supports indexed properties. The supported property indices are the indices of this's relevant global object's PDF viewer plugin objects.
|
||||
auto& window = verify_cast<HTML::Window>(HTML::relevant_global_object(*this));
|
||||
return index < window.pdf_viewer_plugin_objects().size();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-pluginarray-length
|
||||
size_t PluginArray::length() const
|
||||
{
|
||||
|
|
|
@ -32,7 +32,6 @@ private:
|
|||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
virtual JS::Value named_item_value(FlyString const& name) const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue