diff options
author | Andreas Kling <kling@serenityos.org> | 2022-09-01 12:49:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-06 00:27:09 +0200 |
commit | 8f4ea4e308ff8c3e89d99a24721df37af25895d1 (patch) | |
tree | a7233ad0611362f582c69f6ad79886b63d48028a | |
parent | c7ac82ec3335f5d285a660fd1164f50a523f2d67 (diff) | |
download | serenity-8f4ea4e308ff8c3e89d99a24721df37af25895d1.zip |
LibWeb: Don't use a JS::Handle for XHR response object
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index c2738a4ba1..a8886eac58 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -60,6 +60,9 @@ void XMLHttpRequest::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_window.ptr()); + + if (auto* value = m_response_object.get_pointer<JS::Value>()) + visitor.visit(*value); } void XMLHttpRequest::set_ready_state(ReadyState ready_state) @@ -113,7 +116,7 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response() // 4. If this’s response object is non-null, then return it. if (!m_response_object.has<Empty>()) - return m_response_object.get<JS::Handle<JS::Value>>().value(); + return m_response_object.get<JS::Value>(); // 5. If this’s response type is "arraybuffer", if (m_response_type == Bindings::XMLHttpRequestResponseType::Arraybuffer) { @@ -126,13 +129,13 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response() auto buffer = buffer_result.release_value(); buffer->buffer().overwrite(0, m_received_bytes.data(), m_received_bytes.size()); - m_response_object = JS::make_handle(JS::Value(buffer)); + m_response_object = JS::Value(buffer); } // 6. Otherwise, if this’s response type is "blob", set this’s response object to a new Blob object representing this’s received bytes with type set to the result of get a final MIME type for this. else if (m_response_type == Bindings::XMLHttpRequestResponseType::Blob) { auto blob_part = TRY_OR_RETURN_OOM(try_make_ref_counted<FileAPI::Blob>(m_received_bytes, get_final_mime_type().type())); auto blob = TRY(FileAPI::Blob::create(Vector<FileAPI::BlobPart> { move(blob_part) })); - m_response_object = JS::make_handle(JS::Value(wrap(realm(), *blob))); + m_response_object = JS::Value(wrap(realm(), *blob)); } // 7. Otherwise, if this’s response type is "document", set a document response for this. else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) { @@ -157,11 +160,11 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response() return JS::Value(JS::js_null()); // 4. Set this’s response object to jsonObject. - m_response_object = JS::make_handle(json_object_result.release_value()); + m_response_object = json_object_result.release_value(); } // 9. Return this’s response object. - return m_response_object.get<JS::Handle<JS::Value>>().value(); + return m_response_object.get<JS::Value>(); } // https://xhr.spec.whatwg.org/#text-response diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index efd29f8cf8..7c47eb404f 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -106,7 +106,7 @@ private: enum class Failure { /// ???? }; - Variant<JS::Handle<JS::Value>, Failure, Empty> m_response_object; + Variant<JS::Value, Failure, Empty> m_response_object; // https://xhr.spec.whatwg.org/#override-mime-type Optional<MimeSniff::MimeType> m_override_mime_type; |