mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 22:55:23 +00:00
LibWeb: Track fetching-related tasks in FetchController for cancellation
The HTMLMediaElement, for example, contains spec text which states any
ongoing fetch process must be "stopped". The spec does not indicate how
to do this, so our implementation is rather ad-hoc.
Our current implementation may cause a crash in places that assume one
of the fetch algorithms that we set to null is *not* null. For example:
if (fetch_params.process_response) {
queue_fetch_task([]() {
fetch_params.process_response();
};
}
If the fetch process is stopped after queuing the fetch task, but not
before the fetch task is run, we will crash when running this fetch
algorithm.
We now track queued fetch tasks on the fetch controller. When the fetch
process is stopped, we cancel any such pending task.
It is a little bit awkward maintaining a fetch task ID. Ideally, we
could use the underlying task ID throughout. But we do not have access
to the underlying task nor its ID when the task is running, at which
point we need some ID to remove from the pending task list.
This commit is contained in:
committed by
Andreas Kling
parent
4806cf9527
commit
7b3ddd5e15
@@ -627,7 +627,7 @@ WebIDL::ExceptionOr<void> fetch_response_handover(JS::Realm& realm, Infrastructu
|
||||
auto task_destination = fetch_params.task_destination().get<JS::NonnullGCPtr<JS::Object>>();
|
||||
|
||||
// 5. Queue a fetch task to run processResponseEndOfBodyTask with fetchParams’s task destination.
|
||||
Infrastructure::queue_fetch_task(task_destination, move(process_response_end_of_body_task));
|
||||
Infrastructure::queue_fetch_task(fetch_params.controller(), task_destination, move(process_response_end_of_body_task));
|
||||
};
|
||||
|
||||
// FIXME: Handle 'parallel queue' task destination
|
||||
@@ -636,7 +636,7 @@ WebIDL::ExceptionOr<void> fetch_response_handover(JS::Realm& realm, Infrastructu
|
||||
// 4. 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 (fetch_params.algorithms()->process_response()) {
|
||||
Infrastructure::queue_fetch_task(task_destination, [&fetch_params, &response]() {
|
||||
Infrastructure::queue_fetch_task(fetch_params.controller(), task_destination, [&fetch_params, &response]() {
|
||||
fetch_params.algorithms()->process_response()(response);
|
||||
});
|
||||
}
|
||||
@@ -674,7 +674,7 @@ WebIDL::ExceptionOr<void> fetch_response_handover(JS::Realm& realm, Infrastructu
|
||||
// 3. If internalResponse's body is null, then queue a fetch task to run processBody given null, with
|
||||
// fetchParams’s task destination.
|
||||
if (!internal_response->body()) {
|
||||
Infrastructure::queue_fetch_task(task_destination, [process_body = move(process_body)]() {
|
||||
Infrastructure::queue_fetch_task(fetch_params.controller(), task_destination, [process_body = move(process_body)]() {
|
||||
process_body({});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user