mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
LibWeb: Don't use a JS::Handle for XHR response object
This commit is contained in:
parent
c7ac82ec33
commit
8f4ea4e308
2 changed files with 9 additions and 6 deletions
|
@ -60,6 +60,9 @@ void XMLHttpRequest::visit_edges(Cell::Visitor& visitor)
|
||||||
{
|
{
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
visitor.visit(m_window.ptr());
|
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)
|
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.
|
// 4. If this’s response object is non-null, then return it.
|
||||||
if (!m_response_object.has<Empty>())
|
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",
|
// 5. If this’s response type is "arraybuffer",
|
||||||
if (m_response_type == Bindings::XMLHttpRequestResponseType::Arraybuffer) {
|
if (m_response_type == Bindings::XMLHttpRequestResponseType::Arraybuffer) {
|
||||||
|
@ -126,13 +129,13 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
|
||||||
|
|
||||||
auto buffer = buffer_result.release_value();
|
auto buffer = buffer_result.release_value();
|
||||||
buffer->buffer().overwrite(0, m_received_bytes.data(), m_received_bytes.size());
|
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.
|
// 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) {
|
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_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) }));
|
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.
|
// 7. Otherwise, if this’s response type is "document", set a document response for this.
|
||||||
else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) {
|
else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) {
|
||||||
|
@ -157,11 +160,11 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
|
||||||
return JS::Value(JS::js_null());
|
return JS::Value(JS::js_null());
|
||||||
|
|
||||||
// 4. Set this’s response object to jsonObject.
|
// 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.
|
// 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
|
// https://xhr.spec.whatwg.org/#text-response
|
||||||
|
|
|
@ -106,7 +106,7 @@ private:
|
||||||
enum class Failure {
|
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
|
// https://xhr.spec.whatwg.org/#override-mime-type
|
||||||
Optional<MimeSniff::MimeType> m_override_mime_type;
|
Optional<MimeSniff::MimeType> m_override_mime_type;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue