diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index efd8d39db4..444c72571b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -373,7 +373,7 @@ ErrorOr HTMLImageElement::update_the_image_data(bool restart_animations, b key.origin = document().origin(); // 3. If the list of available images contains an entry for key, then: - if (auto entry = document().list_of_available_images().get(key)) { + if (auto* entry = document().list_of_available_images().get(key)) { // 1. Set the ignore higher-layer caching flag for that entry. entry->ignore_higher_layer_caching = true; @@ -598,7 +598,7 @@ void HTMLImageElement::add_callbacks_to_image_request(JS::NonnullGCPtrset_state(ImageRequest::State::CompletelyAvailable); // 3. Add the image to the list of available images using the key key, with the ignore higher-layer caching flag set. - document().list_of_available_images().add(key, *image_data, true).release_value_but_fixme_should_propagate_errors(); + document().list_of_available_images().add(key, *image_data, true); // 4. If maybe omit events is not set or previousURL is not equal to urlString, then fire an event named load at the img element. if (!maybe_omit_events || previous_url != url_string) @@ -731,7 +731,7 @@ void HTMLImageElement::react_to_changes_in_the_environment() image_request->set_state(ImageRequest::State::CompletelyAvailable); // 4. Add the image to the list of available images using the key key, with the ignore higher-layer caching flag set. - document().list_of_available_images().add(key, image_data, true).release_value_but_fixme_should_propagate_errors(); + document().list_of_available_images().add(key, image_data, true); // 5. Upgrade the pending request to the current request. upgrade_pending_request_to_current_request(); @@ -749,7 +749,7 @@ void HTMLImageElement::react_to_changes_in_the_environment() // 14. If the list of available images contains an entry for key, then set image request's image data to that of the entry. // Continue to the next step. - if (auto entry = document().list_of_available_images().get(key)) { + if (auto* entry = document().list_of_available_images().get(key)) { image_request->set_image_data(entry->image_data); step_15(selected_source.value(), *image_request, key, entry->image_data); } diff --git a/Userland/Libraries/LibWeb/HTML/ListOfAvailableImages.cpp b/Userland/Libraries/LibWeb/HTML/ListOfAvailableImages.cpp index c97c453aa3..b25680a77e 100644 --- a/Userland/Libraries/LibWeb/HTML/ListOfAvailableImages.cpp +++ b/Userland/Libraries/LibWeb/HTML/ListOfAvailableImages.cpp @@ -10,7 +10,6 @@ namespace Web::HTML { JS_DEFINE_ALLOCATOR(ListOfAvailableImages); -JS_DEFINE_ALLOCATOR(ListOfAvailableImages::Entry); ListOfAvailableImages::ListOfAvailableImages() = default; ListOfAvailableImages::~ListOfAvailableImages() = default; @@ -33,31 +32,16 @@ u32 ListOfAvailableImages::Key::hash() const return cached_hash.value(); } -JS::NonnullGCPtr ListOfAvailableImages::Entry::create(JS::VM& vm, JS::NonnullGCPtr image_data, bool ignore_higher_layer_caching) -{ - return vm.heap().allocate_without_realm(image_data, ignore_higher_layer_caching); -} - void ListOfAvailableImages::visit_edges(JS::Cell::Visitor& visitor) { Base::visit_edges(visitor); for (auto& it : m_images) - visitor.visit(it.value); + visitor.visit(it.value->image_data); } -ListOfAvailableImages::Entry::Entry(JS::NonnullGCPtr data, bool ignore_higher_layer_caching) - : ignore_higher_layer_caching(ignore_higher_layer_caching) - , image_data(data) +void ListOfAvailableImages::add(Key const& key, JS::NonnullGCPtr image_data, bool ignore_higher_layer_caching) { -} - -ListOfAvailableImages::Entry::~Entry() = default; - -ErrorOr ListOfAvailableImages::add(Key const& key, JS::NonnullGCPtr image_data, bool ignore_higher_layer_caching) -{ - auto entry = Entry::create(vm(), image_data, ignore_higher_layer_caching); - TRY(m_images.try_set(key, entry)); - return {}; + m_images.set(key, make(image_data, ignore_higher_layer_caching)); } void ListOfAvailableImages::remove(Key const& key) @@ -65,12 +49,12 @@ void ListOfAvailableImages::remove(Key const& key) m_images.remove(key); } -JS::GCPtr ListOfAvailableImages::get(Key const& key) const +ListOfAvailableImages::Entry* ListOfAvailableImages::get(Key const& key) { auto it = m_images.find(key); if (it == m_images.end()) return nullptr; - return it->value; + return it->value.ptr(); } } diff --git a/Userland/Libraries/LibWeb/HTML/ListOfAvailableImages.h b/Userland/Libraries/LibWeb/HTML/ListOfAvailableImages.h index b54a26b8f1..c94166a42b 100644 --- a/Userland/Libraries/LibWeb/HTML/ListOfAvailableImages.h +++ b/Userland/Libraries/LibWeb/HTML/ListOfAvailableImages.h @@ -33,32 +33,28 @@ public: mutable Optional cached_hash; }; - struct Entry final : public JS::Cell { - JS_CELL(Entry, Cell); - JS_DECLARE_ALLOCATOR(Entry); + struct Entry { + Entry(JS::NonnullGCPtr image_data, bool ignore_higher_layer_caching) + : image_data(move(image_data)) + , ignore_higher_layer_caching(ignore_higher_layer_caching) + { + } - public: - static JS::NonnullGCPtr create(JS::VM&, JS::NonnullGCPtr, bool ignore_higher_layer_caching); - ~Entry(); - - bool ignore_higher_layer_caching { false }; JS::NonnullGCPtr image_data; - - private: - Entry(JS::NonnullGCPtr, bool ignore_higher_layer_caching); + bool ignore_higher_layer_caching { false }; }; ListOfAvailableImages(); ~ListOfAvailableImages(); - ErrorOr add(Key const&, JS::NonnullGCPtr, bool ignore_higher_layer_caching); + void add(Key const&, JS::NonnullGCPtr, bool ignore_higher_layer_caching); void remove(Key const&); - [[nodiscard]] JS::GCPtr get(Key const&) const; + [[nodiscard]] Entry* get(Key const&); void visit_edges(JS::Cell::Visitor& visitor) override; private: - HashMap> m_images; + HashMap> m_images; }; }