Truly independent web browser
LibWeb: Trace the captures of Fetch's functions precisely
Andreas Klinga60cf91a125d
diff --git a/Libraries/LibWeb/Fetch/Body.cpp b/Libraries/LibWeb/Fetch/Body.cppindex 0d9b580b93b..83d80f9818a 100644--- a/Libraries/LibWeb/Fetch/Body.cpp+++ b/Libraries/LibWeb/Fetch/Body.cpp@@ -49,7 +49,7 @@ static void consume_body(BodyMixin const& object, GC::Ref<WebIDL::Promise> promi// 3. Let errorSteps given error be to reject promise with error.// NOTE: `promise` and `realm` is protected by GC::HeapFunction.- auto error_steps = GC::create_function(GC::Heap::the(), [promise, &realm](JS::Value error) {+ auto error_steps = GC::create_function(GC::Heap::the(), GC::captures(promise, realm), [](auto& promise, auto& realm, JS::Value error) {// AD-HOC: An execution context is required for Promise's reject function.HTML::TemporaryExecutionContext execution_context { realm };WebIDL::reject_promise(promise, error);@@ -58,7 +58,7 @@ static void consume_body(BodyMixin const& object, GC::Ref<WebIDL::Promise> promi// 4. Let successSteps given a byte sequence data be to resolve promise with the result of running convertBytesToJSValue// with data. If that threw an exception, then run errorSteps with that exception.// NOTE: `promise`, `realm` and `object` is protected by GC::HeapFunction.- auto success_steps = GC::create_function(GC::Heap::the(), [promise, &realm, convert_bytes_to_js_value](ByteBuffer data) {+ auto success_steps = GC::create_function(GC::Heap::the(), GC::captures(promise, realm, convert_bytes_to_js_value), [](auto& promise, auto& realm, auto& convert_bytes_to_js_value, ByteBuffer data) {auto& vm = realm.vm();// AD-HOC: An execution context is required for Promise's reject function and JSON.parse.@@ -121,7 +121,7 @@ void BodyMixin::array_buffer(GC::Ref<WebIDL::Promise> promise) constauto& realm = WebIDL::promise_realm(*promise);// The arrayBuffer() method steps are to return the result of running consume body with this and// the following step given a byte sequence bytes:- consume_body(*this, promise, GC::create_function(GC::Heap::the(), [&realm](ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {+ consume_body(*this, promise, GC::create_function(GC::Heap::the(), GC::captures(realm), [](auto& realm, ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {// return the result of creating an ArrayBuffer from bytes in this’s relevant realm.// NOTE: The above method can reject with a RangeError.return JS::ArrayBuffer::create(realm, move(bytes));@@ -134,10 +134,10 @@ void BodyMixin::blob(GC::Ref<WebIDL::Promise> promise) constauto& realm = WebIDL::promise_realm(*promise);// The blob() method steps are to return the result of running consume body with this and// the following step given a byte sequence bytes:- consume_body(*this, promise, GC::create_function(GC::Heap::the(), [&realm, this](ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {+ consume_body(*this, promise, GC::create_function(GC::Heap::the(), GC::captures(realm, this_impl()), [](auto& realm, auto& object, ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {// return a Blob whose contents are bytes and whose type attribute is the result of get the MIME type with this.// NOTE: If extracting the mime type returns failure, other browsers set it to an empty string - not sure if that's spec'd.- auto mime_type = mime_type_impl();+ auto mime_type = as<BodyMixin>(object).mime_type_impl();auto mime_type_string = mime_type.has_value() ? mime_type->serialized() : String {};auto blob = FileAPI::Blob::create(move(bytes), move(mime_type_string));return Bindings::wrap(Bindings::host_defined_wrapper_world(realm), realm, blob);@@ -150,7 +150,7 @@ void BodyMixin::bytes(GC::Ref<WebIDL::Promise> promise) constauto& realm = WebIDL::promise_realm(*promise);// The bytes() method steps are to return the result of running consume body with this and// the following step given a byte sequence bytes:- consume_body(*this, promise, GC::create_function(GC::Heap::the(), [&realm](ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {+ consume_body(*this, promise, GC::create_function(GC::Heap::the(), GC::captures(realm), [](auto& realm, ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {// return the result of creating a Uint8Array from bytes in this’s relevant realm.// NOTE: The above method can reject with a RangeError.auto bytes_length = bytes.size();@@ -165,9 +165,9 @@ void BodyMixin::form_data(GC::Ref<WebIDL::Promise> promise) constauto& realm = WebIDL::promise_realm(*promise);// The formData() method steps are to return the result of running consume body with this and// the following steps given a byte sequence bytes:- consume_body(*this, promise, GC::create_function(GC::Heap::the(), [&realm, this](ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {+ consume_body(*this, promise, GC::create_function(GC::Heap::the(), GC::captures(realm, this_impl()), [](auto& realm, auto& object, ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {// 1. Let mimeType be the result of get the MIME type with this.- auto mime_type = mime_type_impl();+ auto mime_type = as<BodyMixin>(object).mime_type_impl();// 2. If mimeType is non-null, then switch on mimeType’s essence and run the corresponding steps:if (mime_type.has_value()) {@@ -206,7 +206,7 @@ void BodyMixin::json(GC::Ref<WebIDL::Promise> promise) constauto& realm = WebIDL::promise_realm(*promise);// The json() method steps are to return the result of running consume body with this and parse JSON from bytes.// NOTE: The above method can reject with a SyntaxError.- consume_body(*this, promise, GC::create_function(GC::Heap::the(), [&realm](ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {+ consume_body(*this, promise, GC::create_function(GC::Heap::the(), GC::captures(realm), [](auto& realm, ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {return Infra::parse_json_bytes_to_javascript_value(realm, bytes);}));}@@ -216,7 +216,7 @@ void BodyMixin::text(GC::Ref<WebIDL::Promise> promise) const{auto& realm = WebIDL::promise_realm(*promise);// The text() method steps are to return the result of running consume body with this and UTF-8 decode.- consume_body(*this, promise, GC::create_function(GC::Heap::the(), [&realm](ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {+ consume_body(*this, promise, GC::create_function(GC::Heap::the(), GC::captures(realm), [](auto& realm, ByteBuffer bytes) -> WebIDL::ExceptionOr<JS::Value> {auto text = MUST(TextCodec::utf8_decode_to_utf16(bytes));return JS::PrimitiveString::create(realm.vm(), move(text));}));diff --git a/Libraries/LibWeb/Fetch/Body.h b/Libraries/LibWeb/Fetch/Body.hindex f2692ee00df..08c81b9dfea 100644--- a/Libraries/LibWeb/Fetch/Body.h+++ b/Libraries/LibWeb/Fetch/Body.h@@ -39,6 +39,7 @@ class BodyMixin {public:virtual ~BodyMixin();+ virtual GC::Cell const& this_impl() const = 0;virtual Optional<MimeSniff::MimeType> mime_type_impl() const = 0;virtual GC::Ptr<Infrastructure::Body> body_impl() = 0;virtual GC::Ptr<Infrastructure::Body const> body_impl() const = 0;diff --git a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cppindex 300800c4617..5b5cbd5ef40 100644--- a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp@@ -226,8 +226,8 @@ void BodyStreamPullSource::on_pull_wake()// 3. Queue a fetch task to run the following steps, with fetchParams’s task destination:// NB: This task stays queued when the fetch is stopped.- auto steps = GC::create_function(heap(), [this] {- run_pull_task();+ auto steps = GC::create_function(heap(), GC::captures(*this), [](BodyStreamPullSource& self) {+ self.run_pull_task();});if (m_fetch_controller) {Infrastructure::queue_fetch_task(m_fetch_controller->task_destination(), steps);@@ -375,12 +375,12 @@ GC::Ref<Infrastructure::Body> create_body_from_channel(JS::Realm& realm, GC::Ptrauto pull_source = GC::Heap::the().allocate<BodyStreamPullSource>(realm, fetch_controller, stream, move(channel), *wake_sink);// 11. Let pullAlgorithm be the following steps:- auto pull_algorithm = GC::create_function(GC::Heap::the(), [pull_source]() {+ auto pull_algorithm = GC::create_function(GC::Heap::the(), GC::captures(pull_source), [](GC::Ref<BodyStreamPullSource> pull_source) {return pull_source->pull();});// 12. Let cancelAlgorithm be an algorithm that aborts fetchParams’s controller with reason, given reason.- auto cancel_algorithm = GC::create_function(GC::Heap::the(), [pull_source](JS::Value reason) {+ auto cancel_algorithm = GC::create_function(GC::Heap::the(), GC::captures(pull_source), [](GC::Ref<BodyStreamPullSource> pull_source, JS::Value reason) {return pull_source->cancel(reason);});@@ -388,7 +388,7 @@ GC::Ref<Infrastructure::Body> create_body_from_channel(JS::Realm& realm, GC::Ptrstream->set_up_with_byte_reading_support(realm, pull_algorithm, cancel_algorithm);pull_source->watch_channel();- auto read_resource_header = GC::create_function(GC::Heap::the(), [pull_source](Infrastructure::Body::ResourceHeaderCallback on_resource_header) {+ auto read_resource_header = GC::create_function(GC::Heap::the(), GC::captures(pull_source), [](GC::Ref<BodyStreamPullSource> pull_source, Infrastructure::Body::ResourceHeaderCallback on_resource_header) {pull_source->read_resource_header(on_resource_header);});return Infrastructure::Body::create_over_arriving_bytes(stream, read_resource_header);diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cppindex 4accdc6a922..cf860e959e2 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp@@ -369,7 +369,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:// 2. Let onPreloadedResponseAvailable be an algorithm that runs the following step given a response// response: set fetchParams’s preloaded response candidate to response.- auto on_preloaded_response_available = GC::create_function(GC::Heap::the(), [fetch_params, controller](NonnullRefPtr<Infrastructure::Response> response) {+ auto on_preloaded_response_available = GC::create_function(GC::Heap::the(), GC::captures(fetch_params, controller), [](auto& fetch_params, auto& controller, NonnullRefPtr<Infrastructure::Response> response) {fetch_params->set_preloaded_response_candidate(response);// NB: main fetch may already be parked on this preload result.@@ -635,7 +635,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParamrequest->current_url().set_scheme("https"sv);}- auto get_response = GC::create_function(GC::Heap::the(), [&realm, fetch_params = NonnullRefPtr { fetch_params }, controller = fetch_params.controller(), request]() -> GC::Ref<PendingResponse> {+ auto get_response = GC::create_function<GC::Ref<PendingResponse>()>(GC::Heap::the(), GC::captures(realm, NonnullRefPtr { fetch_params }, fetch_params.controller(), request), [](auto& realm, NonnullRefPtr<Infrastructure::FetchParams const>& fetch_params, GC::Ref<Infrastructure::FetchController>& controller, NonnullRefPtr<Infrastructure::Request>& request) -> GC::Ref<PendingResponse> {dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'main fetch' get_response() function");auto const* origin = request->origin().get_pointer<URL::Origin>();@@ -769,7 +769,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam}// 11. If recursive is false, then run the remaining steps in parallel.- Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), [&realm, fetch_params = NonnullRefPtr { fetch_params }, controller = fetch_params.controller(), request, response, get_response] {+ Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function<void()>(GC::Heap::the(), GC::captures(realm, NonnullRefPtr { fetch_params }, fetch_params.controller(), request, response, get_response), [](auto& realm, NonnullRefPtr<Infrastructure::FetchParams const>& fetch_params, GC::Ref<Infrastructure::FetchController>& controller, NonnullRefPtr<Infrastructure::Request>& request, RefPtr<Infrastructure::Response>& response, GC::Ref<GC::Function<GC::Ref<PendingResponse>()>>& get_response) {// 12. If response is null, then set response to the result of running the steps corresponding to the first// matching statement:auto pending_response = PendingResponse::create(controller, Infrastructure::Response::create());@@ -897,7 +897,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParamif (!request->integrity_metadata().is_empty()) {// 1. Let processBodyError be this step: run fetch response handover given fetchParams and a network// error.- auto process_body_error = GC::create_function(GC::Heap::the(), [&realm, fetch_params, controller](JS::Value) {+ auto process_body_error = GC::create_function(GC::Heap::the(), GC::captures(realm, fetch_params, controller), [](auto& realm, auto& fetch_params, auto& controller, JS::Value) {fetch_response_handover(realm, *fetch_params, controller, Infrastructure::Response::network_error("Response body could not be processed"_string));});@@ -908,7 +908,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam}// 3. Let processBody given bytes be these steps:- auto process_body = GC::create_function(GC::Heap::the(), [&realm, request, response, fetch_params, controller, process_body_error](ByteBuffer bytes) {+ auto process_body = GC::create_function(GC::Heap::the(), GC::captures(realm, request, response, fetch_params, controller, process_body_error), [](auto& realm, auto& request, auto& response, auto& fetch_params, auto& controller, auto& process_body_error, ByteBuffer bytes) {// 1. If bytes do not match request’s integrity metadata, then run processBodyError and abort these steps.if (!TRY_OR_IGNORE(SRI::do_bytes_match_metadata_list(bytes, request->integrity_metadata()))) {process_body_error->function()({});@@ -1029,7 +1029,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// within processResponseConsumeBody. So we ensure report_timing_steps is set on error too, which allows// reportTiming to work without asserting, and still produces useful timing data for failed fetches.auto timing_reported = RefCountedFlag::create(false);- auto setup_report_timing_steps = [response = response_view->record(), fetch_params = NonnullRefPtr { fetch_params }, controller, timing_info, timing_reported] {+ auto setup_report_timing_steps = GC::create_function(GC::Heap::the(), GC::captures(response_view->record(), NonnullRefPtr { fetch_params }, controller, timing_info, timing_reported), [](auto& response, auto& fetch_params, auto& controller, auto& timing_info, auto& timing_reported) {// 1. Let unsafeEndTime be the unsafe shared current time.auto unsafe_end_time = HighResolutionTime::unsafe_shared_current_time();@@ -1090,10 +1090,10 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constResourceTiming::PerformanceResourceTiming::mark_resource_timing(timing_info, utf16_string_from_url_ascii(fetch_params->request()->url().serialize()), initiator_type, global, cache_state, body_info, response_status);}});- };+ });// NB: Share step 3 of processResponseEndOfBodyTask with the network-completion timing path.- auto report_timing_if_appropriate = [fetch_params = NonnullRefPtr { fetch_params }, controller] {+ auto report_timing_if_appropriate = GC::create_function(GC::Heap::the(), GC::captures(NonnullRefPtr { fetch_params }, controller), [](NonnullRefPtr<Infrastructure::FetchParams const>& fetch_params, GC::Ref<Infrastructure::FetchController>& controller) {// 3. If fetchParams’s request’s initiator type is non-null and fetchParams’s request’s client’s global// object is fetchParams’s task destination, then run fetchParams’s controller’s report timing steps// given fetchParams’s request’s client’s global object.@@ -1111,17 +1111,17 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constif (client_global_is_task_destination)controller->report_timing(**task_destination_global_object);}- };+ });// 4. Let processResponseEndOfBody be the following steps:- auto process_response_end_of_body = [fetch_params = NonnullRefPtr { fetch_params }, controller, response_view, setup_report_timing_steps, report_timing_if_appropriate] {+ auto process_response_end_of_body = GC::create_function(GC::Heap::the(), GC::captures(NonnullRefPtr { fetch_params }, controller, response_view, setup_report_timing_steps, report_timing_if_appropriate), [](auto& fetch_params, auto& controller, auto& response_view, auto& setup_report_timing_steps, auto& report_timing_if_appropriate) {// 1-2. (See setup_report_timing_steps above)- setup_report_timing_steps();+ setup_report_timing_steps->function()();if (WebDriver::BiDi::network_events_enabled() && !response_view->is_network_error())WebDriver::BiDi::network_response_completed(fetch_params, *response_view->record()->unsafe_response());// 3. Let processResponseEndOfBodyTask be the following steps:- auto process_response_end_of_body_task = GC::create_function(GC::Heap::the(), [fetch_params, controller, response_view, report_timing_if_appropriate] {+ auto process_response_end_of_body_task = GC::create_function(GC::Heap::the(), GC::captures(fetch_params, controller, response_view, report_timing_if_appropriate), [](auto& fetch_params, auto& controller, auto& response_view, auto& report_timing_if_appropriate) {// 1. Set fetchParams’s request’s done flag.fetch_params->request()->set_done(true);end_rendering_pending_operation(controller.ptr());@@ -1132,17 +1132,17 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constif (algorithms->process_response_end_of_body())algorithms->process_response_end_of_body()->function()(response_view);- report_timing_if_appropriate();+ report_timing_if_appropriate->function()();});// 4. Queue a fetch task to run processResponseEndOfBodyTask with fetchParams’s task destination.Infrastructure::queue_fetch_task(controller, controller->task_destination(), move(process_response_end_of_body_task));- };+ });// 5. If fetchParams’s process response is non-null, then queue a fetch task to run fetchParams’s process response// given response, with fetchParams’s task destination.if (controller->algorithms()->process_response()) {- Infrastructure::queue_fetch_task(controller, controller->task_destination(), GC::create_function(GC::Heap::the(), [controller, response_view]() {+ Infrastructure::queue_fetch_task(controller, controller->task_destination(), GC::create_function(GC::Heap::the(), GC::captures(controller, response_view), [](auto& controller, auto& response_view) {controller->algorithms()->process_response()->function()(response_view);}));}@@ -1153,9 +1153,9 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// AD-HOC: Report a body's timing once the network has delivered it. Fetch reports it from the flush of the// transform the body is piped through, which backpressure on an unread body can hold back.if (internal_body.has_value() && (fetch_params.request()->initiator_type().has_value() || (WebDriver::BiDi::network_events_enabled() && !fetch_params.request()->is_navigation_request()))) {- auto network_completion_steps = GC::create_function(GC::Heap::the(), [fetch_params = NonnullRefPtr { fetch_params }, response_view, setup_report_timing_steps, report_timing_if_appropriate] {- setup_report_timing_steps();- report_timing_if_appropriate();+ auto network_completion_steps = GC::create_function(GC::Heap::the(), GC::captures(NonnullRefPtr { fetch_params }, response_view, setup_report_timing_steps, report_timing_if_appropriate), [](auto& fetch_params, auto& response_view, auto& setup_report_timing_steps, auto& report_timing_if_appropriate) {+ setup_report_timing_steps->function()();+ report_timing_if_appropriate->function()();if (WebDriver::BiDi::network_events_enabled())WebDriver::BiDi::network_response_completed(*fetch_params, *response_view->record()->unsafe_response());});@@ -1206,7 +1206,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// 7. If internalResponse’s body is null, then run processResponseEndOfBody.if (!internal_response->body().has_value()) {- process_response_end_of_body();+ process_response_end_of_body->function()();}// 8. Otherwise:else {@@ -1222,17 +1222,17 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constif (auto stream = body_view->stream(); stream->is_readable_byte_stream() && !stream->is_locked()) {auto reader = MUST(stream->get_a_reader());auto forwarded_stream = Streams::ReadableStream::create(realm);- auto end_of_body_steps = GC::create_function(GC::Heap::the(), [process_response_end_of_body] {- process_response_end_of_body();+ auto end_of_body_steps = GC::create_function(GC::Heap::the(), GC::captures(process_response_end_of_body), [](auto& process_response_end_of_body) {+ process_response_end_of_body->function()();});- auto pull_algorithm = GC::create_function(GC::Heap::the(), [&realm, reader, forwarded_stream, end_of_body_steps] {+ auto pull_algorithm = GC::create_function(GC::Heap::the(), GC::captures(realm, reader, forwarded_stream, end_of_body_steps), [](auto& realm, auto& reader, auto& forwarded_stream, auto& end_of_body_steps) {auto promise = WebIDL::create_promise(realm);reader->read_a_chunk(*GC::Heap::the().allocate<ResponseBodyForwardingReadRequest>(forwarded_stream, promise, end_of_body_steps));return promise;});- auto cancel_algorithm = GC::create_function(GC::Heap::the(), [reader](JS::Value reason) {+ auto cancel_algorithm = GC::create_function(GC::Heap::the(), GC::captures(reader), [](auto& reader, JS::Value reason) {return reader->cancel(reason);});@@ -1243,7 +1243,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constauto transform_stream = Streams::TransformStream::create(realm);// 2. Let identityTransformAlgorithm be an algorithm which, given chunk, enqueues chunk in transformStream.- auto identity_transform_algorithm = GC::create_function(GC::Heap::the(), [&realm, transform_stream](JS::Value chunk) -> GC::Ref<WebIDL::Promise> {+ auto identity_transform_algorithm = GC::create_function(GC::Heap::the(), GC::captures(realm, transform_stream), [](auto& realm, auto& transform_stream, JS::Value chunk) -> GC::Ref<WebIDL::Promise> {if (auto result = transform_stream->enqueue(chunk); result.is_error())return WebIDL::create_rejected_promise_from_exception(realm, result.release_error());@@ -1252,8 +1252,8 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// 3. Set up transformStream with transformAlgorithm set to identityTransformAlgorithm and flushAlgorithm set// to processResponseEndOfBody.- auto flush_algorithm = GC::create_function(GC::Heap::the(), [&realm, process_response_end_of_body]() -> GC::Ref<WebIDL::Promise> {- process_response_end_of_body();+ auto flush_algorithm = GC::create_function(GC::Heap::the(), GC::captures(realm, process_response_end_of_body), [](auto& realm, auto& process_response_end_of_body) -> GC::Ref<WebIDL::Promise> {+ process_response_end_of_body->function()();return WebIDL::create_resolved_promise(realm, JS::js_undefined());});transform_stream->set_up(realm, identity_transform_algorithm, flush_algorithm);@@ -1269,8 +1269,8 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// processResponseEndOfBody as the flush would have.VERIFY(!algorithms->process_response_consume_body());auto discard_chunk = GC::create_function(GC::Heap::the(), [](ByteBuffer) { });- auto end_of_body = GC::create_function(GC::Heap::the(), [process_response_end_of_body] {- process_response_end_of_body();+ auto end_of_body = GC::create_function(GC::Heap::the(), GC::captures(process_response_end_of_body), [](auto& process_response_end_of_body) {+ process_response_end_of_body->function()();});auto discard_error = GC::create_function(GC::Heap::the(), [](JS::Value) { });body_view->incrementally_read(realm, discard_chunk, end_of_body, discard_error, controller->task_destination());@@ -1287,7 +1287,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constif (algorithms->process_response_consume_body()) {// 1. Let processBody given nullOrBytes be this step: run fetchParams’s process response consume body given// response and nullOrBytes.- auto process_body = GC::create_function(GC::Heap::the(), [algorithms, response = response_view->record(), response_view](ByteBuffer bytes) {+ auto process_body = GC::create_function(GC::Heap::the(), GC::captures(algorithms, response_view->record(), response_view), [](auto& algorithms, auto& response, auto& response_view, ByteBuffer bytes) {if (auto body = response->body(); body.has_value()) {if (auto source = body->source(); source.has_value()) {algorithms->process_response_consume_body()->function()(response_view, *source);@@ -1306,9 +1306,9 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// 2. Let processBodyError be this step: run fetchParams’s process response consume body given response and// failure.- auto process_body_error = GC::create_function(GC::Heap::the(), [algorithms, response_view, controller = fetch_params.controller(), setup_report_timing_steps](JS::Value) {+ auto process_body_error = GC::create_function(GC::Heap::the(), GC::captures(algorithms, response_view, fetch_params.controller(), setup_report_timing_steps), [](auto& algorithms, auto& response_view, auto& controller, auto& setup_report_timing_steps, JS::Value) {// AD-HOC: See comment on setup_report_timing_steps above.- setup_report_timing_steps();+ setup_report_timing_steps->function()();// NB: A failed read does not always close or error the body's stream, which would otherwise end this.end_rendering_pending_operation(controller.ptr());algorithms->process_response_consume_body()->function()(response_view, Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});@@ -1322,7 +1322,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constif (read_body_in_parallel) {algorithms->process_response_consume_body()->function()(response_view, Empty {});} else {- Infrastructure::queue_fetch_task(controller, controller->task_destination(), GC::create_function(GC::Heap::the(), [algorithms, response_view]() {+ Infrastructure::queue_fetch_task(controller, controller->task_destination(), GC::create_function(GC::Heap::the(), GC::captures(algorithms, response_view), [](auto& algorithms, auto& response_view) {// NB: We have to provide fully_read a callback which accepts a ByteBuffer. Since that's not// nullable, we just invoke process_response_consume_body with a null value manually here.algorithms->process_response_consume_body()->function()(response_view, Empty {});@@ -1336,10 +1336,10 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constelse if (read_body_in_parallel) {HTML::TemporaryExecutionContext const execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };- auto success_steps = GC::create_function(GC::Heap::the(), [process_body, process_response_end_of_body](ByteBuffer bytes) {+ auto success_steps = GC::create_function(GC::Heap::the(), GC::captures(process_body, process_response_end_of_body), [](auto& process_body, auto& process_response_end_of_body, ByteBuffer bytes) {// NB: processResponseEndOfBody runs first, as step 8's flush algorithm would have: It sets up the fetch// controller's report timing steps, which the caller may invoke as soon as processBody has run.- process_response_end_of_body();+ process_response_end_of_body->function()();process_body->function()(move(bytes));});@@ -1747,7 +1747,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam// fetch is to ensure the fetched resource is familiar with the CORS protocol. The cache is there to// minimize the number of CORS-preflight fetches.- auto fetch_main_content = GC::create_function(GC::Heap::the(), [request, realm = GC::Ref { realm }, fetch_params = NonnullRefPtr { fetch_params }]() -> GC::Ref<PendingResponse> {+ auto fetch_main_content = GC::create_function(GC::Heap::the(), GC::captures(request, GC::Ref { realm }, NonnullRefPtr { fetch_params }), [](auto& request, auto& realm, auto& fetch_params) -> GC::Ref<PendingResponse> {// 2. If request’s redirect mode is "follow", then set request’s service-workers mode to "none".// NOTE: Redirects coming from the network (as opposed to from a service worker) are not to be exposed to a// service worker.@@ -2846,7 +2846,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(// A load without a RequestServer request, such as one for a file: URL, hands over its whole body at once.auto whole_body_transport = create_whole_body_transport(*delivery_gate, *channel);- auto on_headers_received = GC::create_function(GC::Heap::the(), [fetch_params = NonnullRefPtr { fetch_params }, pending_response, request, body_pump, channel, delivery_gate, whole_body_transport, http_cache](Engine::NetworkTransportHandle* network_transport, HTTP::HeaderList const& response_headers, Optional<u32> status_code, Optional<String> const& reason_phrase, Requests::CacheState cache_state) {+ auto on_headers_received = GC::create_function(GC::Heap::the(), GC::captures(NonnullRefPtr { fetch_params }, pending_response, request, body_pump, channel, delivery_gate, whole_body_transport, http_cache), [](auto& fetch_params, auto& pending_response, auto& request, auto& body_pump, auto& channel, auto& delivery_gate, auto& whole_body_transport, auto& http_cache, Engine::NetworkTransportHandle* network_transport, HTTP::HeaderList const& response_headers, Optional<u32> status_code, Optional<String> const& reason_phrase, Requests::CacheState cache_state) {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.@@ -2919,11 +2919,11 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(});// 16. Run these steps in parallel:- auto deliver_body_data = GC::create_function(GC::Heap::the(), [body_pump](Requests::ResponseData data) {+ auto deliver_body_data = GC::create_function(GC::Heap::the(), GC::captures(body_pump), [](auto& body_pump, Requests::ResponseData data) {body_pump->handle_network_data(move(data));});- auto on_data_received = GC::create_function(GC::Heap::the(), [deliver_body_data, whole_body_transport](Requests::ResponseData data) {+ auto on_data_received = GC::create_function(GC::Heap::the(), GC::captures(deliver_body_data, whole_body_transport), [](auto& deliver_body_data, auto& whole_body_transport, Requests::ResponseData data) {if (!whole_body_transport->is_attached()) {deliver_body_data->function()(move(data));return;@@ -2935,11 +2935,11 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(whole_body_transport->set_body(move(body), move(on_body_data));});- auto on_cached_body_available = GC::create_function(GC::Heap::the(), [body_pump](Core::ImmutableBytes data) {+ auto on_cached_body_available = GC::create_function(GC::Heap::the(), GC::captures(body_pump), [](auto& body_pump, Core::ImmutableBytes data) {body_pump->set_cached_response_body(move(data));});- auto complete_load = GC::create_function(GC::Heap::the(), [&realm, pending_response, body_pump, delivery_gate, request, fetch_timing_info, cross_origin_isolated_capability](bool success, Requests::RequestTimingInfo const& timing_info, Optional<StringView> error_message) {+ auto complete_load = GC::create_function(GC::Heap::the(), GC::captures(realm, pending_response, body_pump, delivery_gate, request, fetch_timing_info, cross_origin_isolated_capability), [](auto& realm, auto& pending_response, auto& body_pump, auto& delivery_gate, auto& request, auto& fetch_timing_info, auto& cross_origin_isolated_capability, bool success, Requests::RequestTimingInfo const& timing_info, Optional<StringView> error_message) {HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };delivery_gate->detach_transport();@@ -2955,7 +2955,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(}});- auto on_complete = GC::create_function(GC::Heap::the(), [complete_load, whole_body_transport](bool success, Requests::RequestTimingInfo const& timing_info, Optional<StringView> error_message) {+ auto on_complete = GC::create_function(GC::Heap::the(), GC::captures(complete_load, whole_body_transport), [](auto& complete_load, auto& whole_body_transport, bool success, Requests::RequestTimingInfo const& timing_info, Optional<StringView> error_message) {if (!success || !whole_body_transport->is_attached()) {complete_load->function()(success, timing_info, error_message);return;@@ -2990,7 +2990,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(// fetchParams’s process request end-of-body and fetchParams’s task destination.if (request->body().has<Empty>()) {if (fetch_params.controller()->algorithms()->process_request_end_of_body()) {- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), GC::create_function(GC::Heap::the(), [fetch_params = NonnullRefPtr { fetch_params }]() {+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), GC::create_function(GC::Heap::the(), GC::captures(NonnullRefPtr { fetch_params }), [](auto& fetch_params) {fetch_params->controller()->algorithms()->process_request_end_of_body()->function()();}));}@@ -2999,7 +2999,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(else if (auto const* body = request->body().get_pointer<Infrastructure::FetchBody>()) {// 1. Let processBodyChunk given bytes be these steps:// NB: The steps read only bytes's length, so they are given it.- auto process_body_chunk = [fetch_params = NonnullRefPtr { fetch_params }, controller = fetch_params.controller()](u64 length) {+ auto process_body_chunk = GC::create_function(GC::Heap::the(), GC::captures(NonnullRefPtr { fetch_params }, fetch_params.controller()), [](auto& fetch_params, auto& controller, u64 length) {// 1. If fetchParams is canceled, then abort these steps.if (fetch_params->is_canceled())return;@@ -3011,10 +3011,10 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(// request body chunk length given bytes’s length.if (controller->algorithms()->process_request_body_chunk_length())controller->algorithms()->process_request_body_chunk_length()->function()(length);- };+ });// 2. Let processEndOfBody be these steps:- auto process_end_of_body = GC::create_function(GC::Heap::the(), [fetch_params = NonnullRefPtr { fetch_params }, controller = fetch_params.controller()]() {+ auto process_end_of_body = GC::create_function(GC::Heap::the(), GC::captures(NonnullRefPtr { fetch_params }, fetch_params.controller()), [](auto& fetch_params, auto& controller) {// 1. If fetchParams is canceled, then abort these steps.if (fetch_params->is_canceled())return;@@ -3026,7 +3026,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(});// 3. Let processBodyError given e be these steps:- auto process_body_error = GC::create_function(GC::Heap::the(), [&realm, fetch_params = NonnullRefPtr { fetch_params }, controller = fetch_params.controller()](JS::Value error) {+ auto process_body_error = GC::create_function(GC::Heap::the(), GC::captures(realm, NonnullRefPtr { fetch_params }, fetch_params.controller()), [](auto& realm, auto& fetch_params, auto& controller, JS::Value error) {// 1. If fetchParams is canceled, then abort these steps.if (fetch_params->is_canceled())return;@@ -3048,7 +3048,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(// its stream.auto const& source = body->source();if (source.has_value() && source->size() > 0 && network_transport) {- network_transport->set_on_upload_progress([fetch_params = NonnullRefPtr { fetch_params }, process_body_chunk, process_end_of_body = GC::Root { process_end_of_body }, length = source->size(), bytes_read = u64 { 0 }](u64 bytes_sent) mutable {+ network_transport->set_on_upload_progress([fetch_params = NonnullRefPtr { fetch_params }, process_body_chunk = GC::Root { process_body_chunk }, process_end_of_body = GC::Root { process_end_of_body }, length = source->size(), bytes_read = u64 { 0 }](u64 bytes_sent) mutable {bytes_sent = min(bytes_sent, length);if (bytes_sent <= bytes_read)return;@@ -3056,23 +3056,23 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(bytes_read = bytes_sent;auto controller = fetch_params->controller();- Infrastructure::queue_fetch_task(controller, controller->task_destination(), GC::create_function(GC::Heap::the(), [process_body_chunk, chunk_length] {- process_body_chunk(chunk_length);+ Infrastructure::queue_fetch_task(controller, controller->task_destination(), GC::create_function(GC::Heap::the(), GC::captures(process_body_chunk, chunk_length), [](auto& process_body_chunk, auto& chunk_length) {+ process_body_chunk->function()(chunk_length);}));if (bytes_read == length)Infrastructure::queue_fetch_task(controller, controller->task_destination(), GC::Ref { *process_end_of_body });});} else if (source.has_value()) {if (auto length = source->size(); length > 0) {- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), GC::create_function(GC::Heap::the(), [process_body_chunk, length] {- process_body_chunk(length);+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), GC::create_function(GC::Heap::the(), GC::captures(process_body_chunk, length), [](auto& process_body_chunk, auto& length) {+ process_body_chunk->function()(length);}));}Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), process_end_of_body);} else if (auto const& request_body_reader = fetch_params.controller()->algorithms()->request_body_reader(); request_body_reader.has_value()) {// FIXME: Send the bytes read here to RequestServer, which only receives a body's source.- auto process_body_chunk_bytes = GC::create_function(GC::Heap::the(), [process_body_chunk](ByteBuffer bytes) {- process_body_chunk(bytes.size());+ auto process_body_chunk_bytes = GC::create_function(GC::Heap::the(), GC::captures(process_body_chunk), [](auto& process_body_chunk, ByteBuffer bytes) {+ process_body_chunk->function()(bytes.size());});HTML::TemporaryExecutionContext const execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };request_body_reader->body->incrementally_read_loop(request_body_reader->reader, fetch_params.controller()->task_destination(), process_body_chunk_bytes, process_end_of_body, process_body_error);diff --git a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cppindex 4ec7eed5c0b..8c23b3a04d7 100644--- a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp@@ -69,16 +69,14 @@ void PendingResponse::run_callback(){VERIFY(m_callback);VERIFY(m_response);- Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), [this] {- VERIFY(m_callback);- VERIFY(m_response);+ Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), GC::captures(*this), [](PendingResponse& self) {+ VERIFY(self.m_callback);+ VERIFY(self.m_response);// NB: The callback runs only once, so let go of it as it runs. A pending response can live for as long as its- // fetch streams, and the closure would otherwise keep what it captured alive all that time, including- // anything that stale bytes in its padding happen to point to, since its captures are visited- // conservatively.- auto callback = exchange(m_callback, nullptr);- callback->function()(*m_response);- m_fetch_controller->remove_pending_response({}, *this);+ // fetch streams, and the callback would otherwise keep what it captured alive all that time.+ auto callback = exchange(self.m_callback, nullptr);+ callback->function()(*self.m_response);+ self.m_fetch_controller->remove_pending_response({}, self);}));}diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cppindex 177af52b7e7..edee441c51c 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp@@ -109,8 +109,8 @@ void Body::wait_for_sniff_bytes(SniffBytesCallback on_ready)return;auto reader = unread->reader;m_resource_header = ReadingResourceHeader {};- reader->function()(GC::create_function(heap(), [body = GC::Ref { *this }](Core::ImmutableBytes bytes, SniffOutcome outcome) {- body->did_read_resource_header(move(bytes), outcome);+ reader->function()(GC::create_function(heap(), GC::captures(*this), [](Body& body, Core::ImmutableBytes bytes, SniffOutcome outcome) {+ body.did_read_resource_header(move(bytes), outcome);}));}@@ -119,9 +119,9 @@ void Body::did_read_resource_header(Core::ImmutableBytes bytes, SniffOutcome outVERIFY(m_resource_header.has<ReadingResourceHeader>());m_resource_header = ReadResourceHeader { move(bytes), outcome };- auto steps = GC::create_function(heap(), [body = GC::Ref { *this }] {- auto callback = exchange(body->m_sniff_bytes_callback, nullptr);- callback->function()(*body->sniff_bytes_if_available());+ auto steps = GC::create_function(heap(), GC::captures(*this), [](Body& body) {+ auto callback = exchange(body.m_sniff_bytes_callback, nullptr);+ callback->function()(*body.sniff_bytes_if_available());});HTML::queue_a_task(HTML::Task::Source::Networking, HTML::current_event_loop(), nullptr, steps);}@@ -152,19 +152,19 @@ void Body::fully_read(JS::Realm& realm, Web::Fetch::Infrastructure::Body::Procestask_destination = HTML::ParallelQueue::create();// 2. Let successSteps given a byte sequence bytes be to queue a fetch task to run processBody given bytes, with taskDestination.- auto success_steps = [process_body, task_destination](ByteBuffer bytes) {- queue_fetch_task(task_destination, GC::create_function(GC::Heap::the(), [process_body, bytes = move(bytes)]() mutable {+ auto success_steps = GC::create_function(GC::Heap::the(), GC::captures(process_body, task_destination), [](ProcessBodyCallback process_body, TaskDestination const& task_destination, ByteBuffer bytes) {+ queue_fetch_task(task_destination, GC::create_function(GC::Heap::the(), GC::captures(process_body, move(bytes)), [](ProcessBodyCallback process_body, ByteBuffer& bytes) {process_body->function()(move(bytes));}));- };+ });// 3. Let errorSteps optionally given an exception exception be to queue a fetch task to run processBodyError given// exception, with taskDestination.- auto error_steps = [process_body_error, task_destination](JS::Value exception) {- queue_fetch_task(task_destination, GC::create_function(GC::Heap::the(), [process_body_error, exception]() {+ auto error_steps = GC::create_function(GC::Heap::the(), GC::captures(process_body_error, task_destination), [](ProcessBodyErrorCallback process_body_error, TaskDestination const& task_destination, JS::Value exception) {+ queue_fetch_task(task_destination, GC::create_function(GC::Heap::the(), GC::captures(process_body_error, exception), [](ProcessBodyErrorCallback process_body_error, JS::Value exception) {process_body_error->function()(exception);}));- };+ });// 4. Let reader be the result of getting a reader for body’s stream. If that threw an exception, then run errorSteps// with that exception and return.@@ -172,12 +172,12 @@ void Body::fully_read(JS::Realm& realm, Web::Fetch::Infrastructure::Body::Procesif (reader.is_exception()) {auto throw_completion = WebIDL::exception_to_throw_completion(realm.vm(), realm, reader.release_error());- error_steps(throw_completion.release_value());+ error_steps->function()(throw_completion.release_value());return;}// 5. Read all bytes from reader, given successSteps and errorSteps.- reader.value()->read_all_bytes(GC::create_function(GC::Heap::the(), move(success_steps)), GC::create_function(GC::Heap::the(), move(error_steps)));+ reader.value()->read_all_bytes(success_steps, error_steps);}// https://fetch.spec.whatwg.org/#body-incrementally-readdiff --git a/Libraries/LibWeb/Fetch/Infrastructure/IncrementalReadLoopReadRequest.cpp b/Libraries/LibWeb/Fetch/Infrastructure/IncrementalReadLoopReadRequest.cppindex d554b2f73c9..f26172ce402 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/IncrementalReadLoopReadRequest.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/IncrementalReadLoopReadRequest.cpp@@ -23,7 +23,7 @@ void IncrementalReadLoopReadRequest::on_chunk(JS::Value chunk)auto uint8_array = chunk.as_if<JS::Uint8Array>();if (!uint8_array) {- continue_algorithm = GC::create_function(GC::Heap::the(), [&realm, process_body_error = m_process_body_error] {+ continue_algorithm = GC::create_function(GC::Heap::the(), GC::captures(realm, m_process_body_error), [](auto& realm, auto& process_body_error) {process_body_error->function()(JS::TypeError::create(realm, "Chunk data is not Uint8Array"sv));});}@@ -36,7 +36,7 @@ void IncrementalReadLoopReadRequest::on_chunk(JS::Value chunk)? ByteBuffer {}: MUST(uint8_array->viewed_array_buffer()->copy_to_byte_buffer(uint8_array->byte_offset(), JS::typed_array_byte_length(record)));// 2. Set continueAlgorithm to these steps:- continue_algorithm = GC::create_function(GC::Heap::the(), [bytes = move(bytes), body = m_body, reader = m_reader, task_destination = m_task_destination, process_body_chunk = m_process_body_chunk, process_end_of_body = m_process_end_of_body, process_body_error = m_process_body_error] {+ continue_algorithm = GC::create_function<void()>(GC::Heap::the(), GC::captures(move(bytes), m_body, m_reader, m_task_destination, m_process_body_chunk, m_process_end_of_body, m_process_body_error), [](ByteBuffer& bytes, auto& body, auto& reader, auto& task_destination, auto& process_body_chunk, auto& process_end_of_body, auto& process_body_error) {HTML::TemporaryExecutionContext execution_context { reader->closed_promise_realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };// 1. Run processBodyChunk given bytes.process_body_chunk->function()(move(bytes));@@ -53,16 +53,16 @@ void IncrementalReadLoopReadRequest::on_chunk(JS::Value chunk)void IncrementalReadLoopReadRequest::on_close(){// 1. Queue a fetch task given processEndOfBody and taskDestination.- Fetch::Infrastructure::queue_fetch_task(m_task_destination, GC::create_function(GC::Heap::the(), [this] {- m_process_end_of_body->function()();+ Fetch::Infrastructure::queue_fetch_task(m_task_destination, GC::create_function(GC::Heap::the(), GC::captures(m_process_end_of_body), [](Body::ProcessEndOfBodyCallback process_end_of_body) {+ process_end_of_body->function()();}));}void IncrementalReadLoopReadRequest::on_error(JS::Value error){// 1. Queue a fetch task to run processBodyError given e, with taskDestination.- Fetch::Infrastructure::queue_fetch_task(m_task_destination, GC::create_function(GC::Heap::the(), [this, error = move(error)] {- m_process_body_error->function()(error);+ Fetch::Infrastructure::queue_fetch_task(m_task_destination, GC::create_function(GC::Heap::the(), GC::captures(m_process_body_error, error), [](Body::ProcessBodyErrorCallback process_body_error, JS::Value error) {+ process_body_error->function()(error);}));}diff --git a/Libraries/LibWeb/Fetch/Infrastructure/Task.cpp b/Libraries/LibWeb/Fetch/Infrastructure/Task.cppindex d56bbd426fc..d946e837bca 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/Task.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/Task.cpp@@ -67,7 +67,7 @@ HTML::TaskID queue_fetch_task(GC::Ref<FetchController> fetch_controller, TaskDes{auto fetch_task_id = fetch_controller->next_fetch_task_id();- auto html_task_id = queue_fetch_task(task_destination, GC::create_function(GC::Heap::the(), [fetch_controller, fetch_task_id, algorithm]() {+ auto html_task_id = queue_fetch_task(task_destination, GC::create_function<void()>(GC::Heap::the(), GC::captures(fetch_controller, fetch_task_id, algorithm), [](auto& fetch_controller, auto fetch_task_id, auto& algorithm) {fetch_controller->fetch_task_complete(fetch_task_id);algorithm->function()();}));diff --git a/Libraries/LibWeb/Fetch/Request.cpp b/Libraries/LibWeb/Fetch/Request.cppindex 226ed775e35..52fb84294c1 100644--- a/Libraries/LibWeb/Fetch/Request.cpp+++ b/Libraries/LibWeb/Fetch/Request.cpp@@ -32,7 +32,7 @@ static GC::Ref<Streams::TransformStream> create_an_identity_transform_stream(HTM// 2. Set up transformStream with transformAlgorithm set to an algorithm which, given chunk, enqueues chunk in// transformStream.- auto transform_algorithm = GC::create_function(GC::Heap::the(), [&realm, transform_stream](JS::Value chunk) -> GC::Ref<WebIDL::Promise> {+ auto transform_algorithm = GC::create_function(GC::Heap::the(), GC::captures(realm, transform_stream), [](auto& realm, auto& transform_stream, JS::Value chunk) -> GC::Ref<WebIDL::Promise> {if (auto result = transform_stream->enqueue(chunk); result.is_error())return WebIDL::create_rejected_promise_from_exception(realm, result.release_error());return WebIDL::create_resolved_promise(realm, JS::js_undefined());diff --git a/Libraries/LibWeb/Fetch/Request.h b/Libraries/LibWeb/Fetch/Request.hindex f5f3d2aadea..1d1390fb277 100644--- a/Libraries/LibWeb/Fetch/Request.h+++ b/Libraries/LibWeb/Fetch/Request.h@@ -40,6 +40,7 @@ public:virtual ~Request() override;// ^BodyMixin+ virtual GC::Cell const& this_impl() const override { return *this; }virtual Optional<MimeSniff::MimeType> mime_type_impl() const override;virtual GC::Ptr<Infrastructure::Body> body_impl() override;virtual GC::Ptr<Infrastructure::Body const> body_impl() const override;diff --git a/Libraries/LibWeb/Fetch/Response.h b/Libraries/LibWeb/Fetch/Response.hindex 72b2db3273c..8071e70f8f1 100644--- a/Libraries/LibWeb/Fetch/Response.h+++ b/Libraries/LibWeb/Fetch/Response.h@@ -37,6 +37,7 @@ public:virtual ~Response() override;// ^BodyMixin+ virtual GC::Cell const& this_impl() const override { return *this; }virtual Optional<MimeSniff::MimeType> mime_type_impl() const override;virtual GC::Ptr<Infrastructure::Body> body_impl() override;virtual GC::Ptr<Infrastructure::Body const> body_impl() const override;