mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 16:16:43 +00:00
Bindings: Make item_value return an Optional<JS::Value>
This removes some ambiguity about what the return value should be if the index is out of range. Previously, we would sometimes return a JS null, and other times a JS undefined. It will also let us fold together the checks for whether an index is a supported property index, followed by getting the value just afterwards.
This commit is contained in:
parent
9b59dc5e8b
commit
c5c1a8fcc7
Notes:
github-actions[bot]
2024-07-26 12:27:19 +00:00
Author: https://github.com/shannonbooth
Commit: c5c1a8fcc7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/827
31 changed files with 53 additions and 47 deletions
|
@ -219,9 +219,11 @@ bool HTMLAllCollection::is_supported_property_index(u32 index) const
|
|||
return index < collect_matching_elements().size();
|
||||
}
|
||||
|
||||
JS::Value HTMLAllCollection::item_value(size_t index) const
|
||||
Optional<JS::Value> HTMLAllCollection::item_value(size_t index) const
|
||||
{
|
||||
return get_the_all_indexed_element(index);
|
||||
if (auto value = get_the_all_indexed_element(index))
|
||||
return value;
|
||||
return {};
|
||||
}
|
||||
|
||||
JS::Value HTMLAllCollection::named_item_value(FlyString const& name) const
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
|
||||
JS::MarkedVector<JS::NonnullGCPtr<DOM::Element>> collect_matching_elements() const;
|
||||
|
||||
virtual JS::Value item_value(size_t index) 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 Vector<FlyString> supported_property_names() const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
|
|
@ -935,11 +935,13 @@ bool HTMLFormElement::is_supported_property_index(u32 index) const
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-item
|
||||
JS::Value HTMLFormElement::item_value(size_t index) const
|
||||
Optional<JS::Value> HTMLFormElement::item_value(size_t index) const
|
||||
{
|
||||
// To determine the value of an indexed property for a form element, the user agent must return the value returned by
|
||||
// the item method on the elements collection, when invoked with the given index as its argument.
|
||||
return elements()->item(index);
|
||||
if (auto value = elements()->item(index))
|
||||
return value;
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#the-form-element:supported-property-names
|
||||
|
|
|
@ -106,7 +106,7 @@ private:
|
|||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
// ^PlatformObject
|
||||
virtual JS::Value item_value(size_t index) 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 Vector<FlyString> supported_property_names() const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
|
|
@ -97,11 +97,11 @@ JS::GCPtr<MimeType> MimeTypeArray::named_item(FlyString const& name) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
JS::Value MimeTypeArray::item_value(size_t index) const
|
||||
Optional<JS::Value> MimeTypeArray::item_value(size_t index) const
|
||||
{
|
||||
auto return_value = item(index);
|
||||
if (!return_value)
|
||||
return JS::js_null();
|
||||
return {};
|
||||
return return_value.ptr();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ private:
|
|||
|
||||
// ^Bindings::PlatformObject
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual JS::Value item_value(size_t index) 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;
|
||||
};
|
||||
|
|
|
@ -120,11 +120,11 @@ JS::GCPtr<MimeType> Plugin::named_item(FlyString const& name) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
JS::Value Plugin::item_value(size_t index) const
|
||||
Optional<JS::Value> Plugin::item_value(size_t index) const
|
||||
{
|
||||
auto return_value = item(index);
|
||||
if (!return_value)
|
||||
return JS::js_null();
|
||||
return {};
|
||||
return return_value.ptr();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ private:
|
|||
|
||||
// ^Bindings::PlatformObject
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual JS::Value item_value(size_t index) 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;
|
||||
};
|
||||
|
|
|
@ -106,11 +106,11 @@ JS::GCPtr<Plugin> PluginArray::named_item(FlyString const& name) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
JS::Value PluginArray::item_value(size_t index) const
|
||||
Optional<JS::Value> PluginArray::item_value(size_t index) const
|
||||
{
|
||||
auto return_value = item(index);
|
||||
if (!return_value)
|
||||
return JS::js_null();
|
||||
return {};
|
||||
return return_value.ptr();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ private:
|
|||
|
||||
// ^Bindings::PlatformObject
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual JS::Value item_value(size_t index) 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