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:
Shannon Booth 2024-07-25 18:15:51 +12:00 committed by Andreas Kling
commit c5c1a8fcc7
Notes: github-actions[bot] 2024-07-26 12:27:19 +00:00
31 changed files with 53 additions and 47 deletions

View file

@ -302,11 +302,11 @@ void DOMTokenList::run_update_steps()
MUST(associated_element->set_attribute(m_associated_attribute, serialize_ordered_set()));
}
JS::Value DOMTokenList::item_value(size_t index) const
Optional<JS::Value> DOMTokenList::item_value(size_t index) const
{
auto string = item(index);
if (!string.has_value())
return JS::js_undefined();
return {};
return JS::PrimitiveString::create(vm(), string.release_value());
}