diff --git a/Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp b/Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp index 2f47536f3d8..8027ae84a3e 100644 --- a/Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp @@ -96,7 +96,7 @@ JS::ThrowCompletionOr> PlatformObject::legacy_p // 2. Let value be an uninitialized variable. // 3. If operation was defined without an identifier, then set value to the result of performing the steps listed in the interface description to determine the value of an indexed property with index as the index. // 4. Otherwise, operation was defined with an identifier. Set value to the result of performing the method steps of operation with O as this and « index » as the argument values. - auto value = item_value(index); + auto value = *item_value(index); // 5. Let desc be a newly created Property Descriptor with no fields. JS::PropertyDescriptor descriptor; @@ -481,9 +481,9 @@ WebIDL::ExceptionOr PlatformObject::delete_valu VERIFY_NOT_REACHED(); } -JS::Value PlatformObject::item_value(size_t) const +Optional PlatformObject::item_value(size_t) const { - return JS::js_undefined(); + return {}; } JS::Value PlatformObject::named_item_value(FlyString const&) const diff --git a/Userland/Libraries/LibWeb/Bindings/PlatformObject.h b/Userland/Libraries/LibWeb/Bindings/PlatformObject.h index aba42c0ed66..f405206904e 100644 --- a/Userland/Libraries/LibWeb/Bindings/PlatformObject.h +++ b/Userland/Libraries/LibWeb/Bindings/PlatformObject.h @@ -72,7 +72,7 @@ protected: }; JS::ThrowCompletionOr> legacy_platform_object_get_own_property(JS::PropertyKey const&, IgnoreNamedProps ignore_named_props) const; - virtual JS::Value item_value(size_t index) const; + virtual Optional item_value(size_t index) const; virtual JS::Value named_item_value(FlyString const& name) const; virtual Vector supported_property_names() const; virtual bool is_supported_property_name(FlyString const&) const; diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp index 90610ab2a7f..4b1bf4168d8 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -227,9 +227,11 @@ bool CSSRuleList::evaluate_media_queries(HTML::Window const& window) return any_media_queries_changed_match_state; } -JS::Value CSSRuleList::item_value(size_t index) const +Optional CSSRuleList::item_value(size_t index) const { - return item(index); + if (auto value = item(index)) + return value; + return {}; } } diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.h b/Userland/Libraries/LibWeb/CSS/CSSRuleList.h index 490f84b4c44..e72e7eab5a2 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.h +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.h @@ -52,7 +52,7 @@ public: auto end() { return m_rules.end(); } virtual bool is_supported_property_index(u32 index) const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; WebIDL::ExceptionOr remove_a_css_rule(u32 index); WebIDL::ExceptionOr insert_a_css_rule(Variant, u32 index); diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp index 17960fda3e2..65a6b6839f9 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp @@ -116,10 +116,10 @@ bool MediaList::matches() const return false; } -JS::Value MediaList::item_value(size_t index) const +Optional MediaList::item_value(size_t index) const { if (index >= m_media.size()) - return JS::js_undefined(); + return {}; return JS::PrimitiveString::create(vm(), m_media[index]->to_string()); } diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.h b/Userland/Libraries/LibWeb/CSS/MediaList.h index e872f6d2353..5cd6605aac3 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.h +++ b/Userland/Libraries/LibWeb/CSS/MediaList.h @@ -32,7 +32,7 @@ public: void delete_medium(StringView); virtual bool is_supported_property_index(u32 index) const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; bool evaluate(HTML::Window const&); bool matches() const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp b/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp index 9486d16cad0..0f87852260e 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp @@ -164,10 +164,10 @@ bool StyleSheetList::is_supported_property_index(u32 index) const return index < m_sheets.size(); } -JS::Value StyleSheetList::item_value(size_t index) const +Optional StyleSheetList::item_value(size_t index) const { if (index >= m_sheets.size()) - return JS::js_undefined(); + return {}; return m_sheets[index].ptr(); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheetList.h b/Userland/Libraries/LibWeb/CSS/StyleSheetList.h index 3bfb395891c..dbeaf777975 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheetList.h +++ b/Userland/Libraries/LibWeb/CSS/StyleSheetList.h @@ -36,7 +36,7 @@ public: size_t length() const { return m_sheets.size(); } virtual bool is_supported_property_index(u32 index) const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; DOM::Document& document() { return m_document; } DOM::Document const& document() const { return m_document; } diff --git a/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp b/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp index 18d38032306..7f40da16008 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp @@ -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 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()); } diff --git a/Userland/Libraries/LibWeb/DOM/DOMTokenList.h b/Userland/Libraries/LibWeb/DOM/DOMTokenList.h index cbb2dcfc917..e0946ef1b66 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMTokenList.h +++ b/Userland/Libraries/LibWeb/DOM/DOMTokenList.h @@ -31,7 +31,7 @@ public: void associated_attribute_changed(StringView value); virtual bool is_supported_property_index(u32 index) const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; size_t length() const { return m_token_set.size(); } Optional item(size_t index) const; diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp index 2b6ad82cef8..ba06296469d 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp @@ -169,11 +169,11 @@ bool HTMLCollection::is_supported_property_index(u32 index) const return index < length(); } -JS::Value HTMLCollection::item_value(size_t index) const +Optional HTMLCollection::item_value(size_t index) const { auto* element = item(index); if (!element) - return JS::js_undefined(); + return {}; return element; } diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h index b516ce1aa4b..9fa3759a468 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h @@ -40,7 +40,7 @@ public: JS::MarkedVector> collect_matching_elements() const; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; virtual JS::Value named_item_value(FlyString const& name) const override; virtual Vector supported_property_names() const override; virtual bool is_supported_property_name(FlyString const&) const override; diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp index f3f7999b7a5..30163d9df38 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp @@ -326,11 +326,11 @@ Attr const* NamedNodeMap::remove_attribute_ns(Optional const& namespa return attribute; } -JS::Value NamedNodeMap::item_value(size_t index) const +Optional NamedNodeMap::item_value(size_t index) const { auto const* node = item(index); if (!node) - return JS::js_undefined(); + return {}; return node; } diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h index 2a70da45698..c2aca66fb79 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h @@ -26,7 +26,7 @@ public: virtual bool is_supported_property_index(u32 index) const override; virtual Vector supported_property_names() const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; virtual JS::Value named_item_value(FlyString const& name) const override; size_t length() const { return m_attributes.size(); } diff --git a/Userland/Libraries/LibWeb/DOM/NodeList.cpp b/Userland/Libraries/LibWeb/DOM/NodeList.cpp index 1a01c1f7c3a..5e32e06cf76 100644 --- a/Userland/Libraries/LibWeb/DOM/NodeList.cpp +++ b/Userland/Libraries/LibWeb/DOM/NodeList.cpp @@ -25,11 +25,11 @@ void NodeList::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(NodeList); } -JS::Value NodeList::item_value(size_t index) const +Optional NodeList::item_value(size_t index) const { auto* node = item(index); if (!node) - return JS::js_undefined(); + return {}; return const_cast(node); } diff --git a/Userland/Libraries/LibWeb/DOM/NodeList.h b/Userland/Libraries/LibWeb/DOM/NodeList.h index a73cffe7846..6f7eee8a276 100644 --- a/Userland/Libraries/LibWeb/DOM/NodeList.h +++ b/Userland/Libraries/LibWeb/DOM/NodeList.h @@ -21,7 +21,7 @@ public: virtual u32 length() const = 0; virtual Node const* item(u32 index) const = 0; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; virtual bool is_supported_property_index(u32) const override; protected: diff --git a/Userland/Libraries/LibWeb/FileAPI/FileList.cpp b/Userland/Libraries/LibWeb/FileAPI/FileList.cpp index f5eec133a04..10373c4f2e8 100644 --- a/Userland/Libraries/LibWeb/FileAPI/FileList.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/FileList.cpp @@ -56,10 +56,10 @@ bool FileList::is_supported_property_index(u32 index) const return index < m_files.size(); } -JS::Value FileList::item_value(size_t index) const +Optional FileList::item_value(size_t index) const { if (index >= m_files.size()) - return JS::js_undefined(); + return {}; return m_files[index].ptr(); } diff --git a/Userland/Libraries/LibWeb/FileAPI/FileList.h b/Userland/Libraries/LibWeb/FileAPI/FileList.h index 3e36506ab41..cbde90af67a 100644 --- a/Userland/Libraries/LibWeb/FileAPI/FileList.h +++ b/Userland/Libraries/LibWeb/FileAPI/FileList.h @@ -43,7 +43,7 @@ public: } virtual bool is_supported_property_index(u32 index) const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; virtual StringView interface_name() const override { return "FileList"sv; } virtual WebIDL::ExceptionOr serialization_steps(HTML::SerializationRecord& serialized, bool for_storage, HTML::SerializationMemory&) override; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp index 02f7d63cebb..ce5b142bb34 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp @@ -66,10 +66,10 @@ bool DOMRectList::is_supported_property_index(u32 index) const return index < m_rects.size(); } -JS::Value DOMRectList::item_value(size_t index) const +Optional DOMRectList::item_value(size_t index) const { if (index >= m_rects.size()) - return JS::js_undefined(); + return {}; return m_rects[index].ptr(); } diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h index db8ed88b275..415c0a90f64 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h @@ -27,7 +27,7 @@ public: DOMRect const* item(u32 index) const; virtual bool is_supported_property_index(u32) const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; private: DOMRectList(JS::Realm&, Vector>); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.cpp index 9ce787ee9e8..d12dc6073cb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.cpp @@ -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 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 diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.h b/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.h index fcb9ce9a323..c81b64b154b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.h @@ -34,7 +34,7 @@ public: JS::MarkedVector> collect_matching_elements() const; - virtual JS::Value item_value(size_t index) const override; + virtual Optional item_value(size_t index) const override; virtual JS::Value 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/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index ca56bc337a6..8fc6283f219 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -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 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 diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h index cca12f0f46d..b8e68327db1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h @@ -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 item_value(size_t index) const override; virtual JS::Value 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/HTML/MimeTypeArray.cpp b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp index d7445065ac8..99d94dbf782 100644 --- a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp +++ b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp @@ -97,11 +97,11 @@ JS::GCPtr MimeTypeArray::named_item(FlyString const& name) const return nullptr; } -JS::Value MimeTypeArray::item_value(size_t index) const +Optional MimeTypeArray::item_value(size_t index) const { auto return_value = item(index); if (!return_value) - return JS::js_null(); + return {}; return return_value.ptr(); } diff --git a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.h b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.h index 0f7776db9ed..ea32f2bacd7 100644 --- a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.h +++ b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.h @@ -29,7 +29,7 @@ private: // ^Bindings::PlatformObject virtual Vector supported_property_names() const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional 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; }; diff --git a/Userland/Libraries/LibWeb/HTML/Plugin.cpp b/Userland/Libraries/LibWeb/HTML/Plugin.cpp index 44f6be7fba6..11cf3d32c00 100644 --- a/Userland/Libraries/LibWeb/HTML/Plugin.cpp +++ b/Userland/Libraries/LibWeb/HTML/Plugin.cpp @@ -120,11 +120,11 @@ JS::GCPtr Plugin::named_item(FlyString const& name) const return nullptr; } -JS::Value Plugin::item_value(size_t index) const +Optional Plugin::item_value(size_t index) const { auto return_value = item(index); if (!return_value) - return JS::js_null(); + return {}; return return_value.ptr(); } diff --git a/Userland/Libraries/LibWeb/HTML/Plugin.h b/Userland/Libraries/LibWeb/HTML/Plugin.h index 61b6bc1ab14..04e2793dd62 100644 --- a/Userland/Libraries/LibWeb/HTML/Plugin.h +++ b/Userland/Libraries/LibWeb/HTML/Plugin.h @@ -35,7 +35,7 @@ private: // ^Bindings::PlatformObject virtual Vector supported_property_names() const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional 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; }; diff --git a/Userland/Libraries/LibWeb/HTML/PluginArray.cpp b/Userland/Libraries/LibWeb/HTML/PluginArray.cpp index 734c2948dc5..170121cab82 100644 --- a/Userland/Libraries/LibWeb/HTML/PluginArray.cpp +++ b/Userland/Libraries/LibWeb/HTML/PluginArray.cpp @@ -106,11 +106,11 @@ JS::GCPtr PluginArray::named_item(FlyString const& name) const return nullptr; } -JS::Value PluginArray::item_value(size_t index) const +Optional PluginArray::item_value(size_t index) const { auto return_value = item(index); if (!return_value) - return JS::js_null(); + return {}; return return_value.ptr(); } diff --git a/Userland/Libraries/LibWeb/HTML/PluginArray.h b/Userland/Libraries/LibWeb/HTML/PluginArray.h index c37e93d50cc..0aba112d2db 100644 --- a/Userland/Libraries/LibWeb/HTML/PluginArray.h +++ b/Userland/Libraries/LibWeb/HTML/PluginArray.h @@ -30,7 +30,7 @@ private: // ^Bindings::PlatformObject virtual Vector supported_property_names() const override; - virtual JS::Value item_value(size_t index) const override; + virtual Optional 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; }; diff --git a/Userland/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp b/Userland/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp index a4bbb7bd9d4..274ac559af5 100644 --- a/Userland/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp +++ b/Userland/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp @@ -114,7 +114,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalEnvironmentExtensions::$$_function) auto array = TRY(JS::Array::create(*vm.current_realm(), node_list->length())); for (auto i = 0u; i < node_list->length(); ++i) { - TRY(array->create_data_property_or_throw(i, node_list->item_value(i))); + TRY(array->create_data_property_or_throw(i, *node_list->item_value(i))); } return array;