diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
index ab116b07e7..306816133d 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
@@ -57,7 +57,14 @@ void HTMLImageElement::initialize(JS::Realm& realm)
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLImageElement"));
- m_current_request = MUST(ImageRequest::create(*document().page()));
+ m_current_request = ImageRequest::create(realm, *document().page());
+}
+
+void HTMLImageElement::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_current_request);
+ visitor.visit(m_pending_request);
}
void HTMLImageElement::apply_presentational_hints(CSS::StyleProperties& style) const
@@ -368,7 +375,7 @@ ErrorOr HTMLImageElement::update_the_image_data(bool restart_animations, b
m_pending_request = nullptr;
// 4. Let current request be a new image request whose image data is that of the entry and whose state is completely available.
- m_current_request = ImageRequest::create(*document().page()).release_value_but_fixme_should_propagate_errors();
+ m_current_request = ImageRequest::create(realm(), *document().page());
m_current_request->set_image_data(entry->image_data);
m_current_request->set_state(ImageRequest::State::CompletelyAvailable);
@@ -495,7 +502,7 @@ after_step_7:
// multiple image elements (as well as CSS background-images, etc.)
// 16. Set image request to a new image request whose current URL is urlString.
- auto image_request = ImageRequest::create(*document().page()).release_value_but_fixme_should_propagate_errors();
+ auto image_request = ImageRequest::create(realm(), *document().page());
image_request->set_current_url(url_string);
// 17. If current request's state is unavailable or broken, then set the current request to image request.
@@ -513,7 +520,7 @@ after_step_7:
if (delay_load_event)
m_load_event_delayer.emplace(document());
- add_callbacks_to_image_request(image_request, maybe_omit_events, url_string, previous_url);
+ add_callbacks_to_image_request(*image_request, maybe_omit_events, url_string, previous_url);
// AD-HOC: If the image request is already available or fetching, no need to start another fetch.
if (image_request->is_available() || image_request->is_fetching())
@@ -554,7 +561,7 @@ after_step_7:
return {};
}
-void HTMLImageElement::add_callbacks_to_image_request(NonnullRefPtr image_request, bool maybe_omit_events, AK::URL const& url_string, AK::URL const& previous_url)
+void HTMLImageElement::add_callbacks_to_image_request(JS::NonnullGCPtr image_request, bool maybe_omit_events, AK::URL const& url_string, AK::URL const& previous_url)
{
image_request->add_callbacks(
[this, image_request, maybe_omit_events, url_string, previous_url]() {
@@ -690,7 +697,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
key.origin = document().origin();
// 11. ⌛ Let image request be a new image request whose current URL is urlString
- auto image_request = ImageRequest::create(*document().page()).release_value_but_fixme_should_propagate_errors();
+ auto image_request = ImageRequest::create(realm(), *document().page());
image_request->set_current_url(url_string);
// 12. ⌛ Let the element's pending request be image request.
@@ -698,7 +705,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
// FIXME: 13. End the synchronous section, continuing the remaining steps in parallel.
- auto step_15 = [this](String const& selected_source, NonnullRefPtr const& image_request, ListOfAvailableImages::Key const& key, NonnullRefPtr const& image_data) {
+ auto step_15 = [this](String const& selected_source, JS::NonnullGCPtr image_request, ListOfAvailableImages::Key const& key, NonnullRefPtr const& image_data) {
// 15. Queue an element task on the DOM manipulation task source given the img element and the following steps:
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this, selected_source, image_request, key, image_data] {
// 1. FIXME: If the img element has experienced relevant mutations since this algorithm started, then let pending request be null and abort these steps.
@@ -734,7 +741,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
// Continue to the next step.
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);
+ step_15(selected_source.value(), *image_request, key, entry->image_data);
}
// Otherwise:
else {
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h
index a8628b67b9..6090f4d2a9 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h
@@ -91,6 +91,8 @@ public:
JS::SafeFunction take_lazy_load_resumption_steps(Badge);
+ virtual void visit_edges(Cell::Visitor&) override;
+
private:
HTMLImageElement(DOM::Document&, DOM::QualifiedName);
@@ -105,7 +107,7 @@ private:
void handle_successful_fetch(AK::URL const&, StringView mime_type, ImageRequest&, ByteBuffer, bool maybe_omit_events, AK::URL const& previous_url);
void handle_failed_fetch();
- void add_callbacks_to_image_request(NonnullRefPtr, bool maybe_omit_events, AK::URL const& url_string, AK::URL const& previous_url);
+ void add_callbacks_to_image_request(JS::NonnullGCPtr, bool maybe_omit_events, AK::URL const& url_string, AK::URL const& previous_url);
void animate();
@@ -122,10 +124,10 @@ private:
Optional m_last_selected_source;
// https://html.spec.whatwg.org/multipage/images.html#current-request
- RefPtr m_current_request;
+ JS::GCPtr m_current_request;
// https://html.spec.whatwg.org/multipage/images.html#pending-request
- RefPtr m_pending_request;
+ JS::GCPtr m_pending_request;
SourceSet m_source_set;
diff --git a/Userland/Libraries/LibWeb/HTML/ImageRequest.cpp b/Userland/Libraries/LibWeb/HTML/ImageRequest.cpp
index 399e02b454..fad3b6a1e0 100644
--- a/Userland/Libraries/LibWeb/HTML/ImageRequest.cpp
+++ b/Userland/Libraries/LibWeb/HTML/ImageRequest.cpp
@@ -19,9 +19,9 @@
namespace Web::HTML {
-ErrorOr> ImageRequest::create(Page& page)
+JS::NonnullGCPtr ImageRequest::create(JS::Realm& realm, Page& page)
{
- return adopt_nonnull_ref_or_enomem(new (nothrow) ImageRequest(page));
+ return realm.heap().allocate(realm, page);
}
ImageRequest::ImageRequest(Page& page)
diff --git a/Userland/Libraries/LibWeb/HTML/ImageRequest.h b/Userland/Libraries/LibWeb/HTML/ImageRequest.h
index 4a7c1cc9c2..cdb62c08ad 100644
--- a/Userland/Libraries/LibWeb/HTML/ImageRequest.h
+++ b/Userland/Libraries/LibWeb/HTML/ImageRequest.h
@@ -17,9 +17,12 @@
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/images.html#image-request
-class ImageRequest : public RefCounted {
+class ImageRequest final : public JS::Cell {
+ JS_CELL(ImageRequest, JS::Cell);
+
public:
- static ErrorOr> create(Page&);
+ [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, Page&);
+
~ImageRequest();
// https://html.spec.whatwg.org/multipage/images.html#img-req-state