mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Make ResourceLoader callbacks HeapFunctions
This commit is contained in:
parent
1c18b900e2
commit
e6d1123ce8
Notes:
github-actions[bot]
2024-10-30 19:56:55 +00:00
Author: https://github.com/shannonbooth
Commit: e6d1123ce8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2062
Reviewed-by: https://github.com/kalenikaliaksandr ✅
3 changed files with 65 additions and 62 deletions
|
@ -2260,7 +2260,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_load
|
|||
// 13. Set up stream with byte reading support with pullAlgorithm set to pullAlgorithm, cancelAlgorithm set to cancelAlgorithm.
|
||||
Streams::set_up_readable_stream_controller_with_byte_reading_support(stream, pull_algorithm, cancel_algorithm);
|
||||
|
||||
auto on_headers_received = [&vm, request, pending_response, stream](auto const& response_headers, Optional<u32> status_code) {
|
||||
auto on_headers_received = JS::create_heap_function(vm.heap(), [&vm, request, pending_response, stream](HTTP::HeaderMap const& response_headers, Optional<u32> status_code) {
|
||||
(void)request;
|
||||
if (pending_response->is_resolved()) {
|
||||
// RequestServer will send us the response headers twice, the second time being for HTTP trailers. This
|
||||
// fetch algorithm is not interested in trailers, so just drop them here.
|
||||
|
@ -2290,11 +2291,11 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_load
|
|||
// 17. Return response.
|
||||
// NOTE: Typically response’s body’s stream is still being enqueued to after returning.
|
||||
pending_response->resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
// 16. Run these steps in parallel:
|
||||
// FIXME: 1. Run these steps, but abort when fetchParams is canceled:
|
||||
auto on_data_received = [fetched_data_receiver](auto bytes) {
|
||||
auto on_data_received = JS::create_heap_function(vm.heap(), [fetched_data_receiver](ReadonlyBytes bytes) {
|
||||
// 1. If one or more bytes have been transmitted from response’s message body, then:
|
||||
if (!bytes.is_empty()) {
|
||||
// 1. Let bytes be the transmitted bytes.
|
||||
|
@ -2311,9 +2312,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_load
|
|||
// FIXME: 8. If the size of buffer is larger than an upper limit chosen by the user agent, ask the user agent
|
||||
// to suspend the ongoing fetch.
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
auto on_complete = [&vm, &realm, pending_response, stream](auto success, auto error_message) {
|
||||
auto on_complete = JS::create_heap_function(vm.heap(), [&vm, &realm, pending_response, stream](bool success, Optional<StringView> error_message) {
|
||||
HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
|
||||
// 16.1.1.2. Otherwise, if the bytes transmission for response’s message body is done normally and stream is readable,
|
||||
|
@ -2332,11 +2333,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_load
|
|||
if (!pending_response->is_resolved())
|
||||
pending_response->resolve(Infrastructure::Response::network_error(vm, error));
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
ResourceLoader::the().load_unbuffered(load_request, move(on_headers_received), move(on_data_received), move(on_complete));
|
||||
ResourceLoader::the().load_unbuffered(load_request, on_headers_received, on_data_received, on_complete);
|
||||
} else {
|
||||
auto on_load_success = [&realm, &vm, request, pending_response](auto data, auto& response_headers, auto status_code) {
|
||||
auto on_load_success = JS::create_heap_function(vm.heap(), [&realm, &vm, request, pending_response](ReadonlyBytes data, HTTP::HeaderMap const& response_headers, Optional<u32> status_code) {
|
||||
(void)request;
|
||||
dbgln_if(WEB_FETCH_DEBUG, "Fetch: ResourceLoader load for '{}' complete", request->url());
|
||||
if constexpr (WEB_FETCH_DEBUG)
|
||||
log_response(status_code, response_headers, data);
|
||||
|
@ -2350,9 +2352,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_load
|
|||
}
|
||||
// FIXME: Set response status message
|
||||
pending_response->resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
auto on_load_error = [&realm, &vm, request, pending_response](auto& error, auto status_code, auto data, auto& response_headers) {
|
||||
auto on_load_error = JS::create_heap_function(vm.heap(), [&realm, &vm, request, pending_response](ByteString const& error, Optional<u32> status_code, ReadonlyBytes data, HTTP::HeaderMap const& response_headers) {
|
||||
(void)request;
|
||||
dbgln_if(WEB_FETCH_DEBUG, "Fetch: ResourceLoader load for '{}' failed: {} (status {})", request->url(), error, status_code.value_or(0));
|
||||
if constexpr (WEB_FETCH_DEBUG)
|
||||
log_response(status_code, response_headers, data);
|
||||
|
@ -2372,9 +2375,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_load
|
|||
// FIXME: Set response status message
|
||||
}
|
||||
pending_response->resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
ResourceLoader::the().load(load_request, move(on_load_success), move(on_load_error));
|
||||
ResourceLoader::the().load(load_request, on_load_success, on_load_error);
|
||||
}
|
||||
|
||||
return pending_response;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue