mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibWeb: Make HTML::Task IDs a sequential, distinct numeric type
This also fixes a bug where task IDs were being deallocated from the wrong IDAllocator. I don't know if it was actually possible to cause any real trouble with that mistake, nor do I know how to write a test for it, but this makes the bug go away.
This commit is contained in:
parent
0e1256e5a4
commit
08d60d7521
Notes:
github-actions[bot]
2024-08-05 07:12:59 +00:00
Author: https://github.com/awesomekling
Commit: 08d60d7521
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/962
12 changed files with 33 additions and 29 deletions
|
@ -110,7 +110,7 @@ void FetchController::stop_fetch()
|
|||
auto ongoing_fetch_tasks = move(m_ongoing_fetch_tasks);
|
||||
|
||||
HTML::main_thread_event_loop().task_queue().remove_tasks_matching([&](auto const& task) {
|
||||
return ongoing_fetch_tasks.remove_all_matching([&](u64, int task_id) {
|
||||
return ongoing_fetch_tasks.remove_all_matching([&](u64, HTML::TaskID task_id) {
|
||||
return task.id() == task_id;
|
||||
});
|
||||
});
|
||||
|
@ -121,7 +121,7 @@ void FetchController::stop_fetch()
|
|||
}
|
||||
}
|
||||
|
||||
void FetchController::fetch_task_queued(u64 fetch_task_id, int event_id)
|
||||
void FetchController::fetch_task_queued(u64 fetch_task_id, HTML::TaskID event_id)
|
||||
{
|
||||
m_ongoing_fetch_tasks.set(fetch_task_id, event_id);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibJS/SafeFunction.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/EventLoop/Task.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
|
@ -50,7 +51,7 @@ public:
|
|||
void stop_fetch();
|
||||
|
||||
u64 next_fetch_task_id() { return m_next_fetch_task_id++; }
|
||||
void fetch_task_queued(u64 fetch_task_id, int event_id);
|
||||
void fetch_task_queued(u64 fetch_task_id, HTML::TaskID event_id);
|
||||
void fetch_task_complete(u64 fetch_task_id);
|
||||
|
||||
private:
|
||||
|
@ -84,7 +85,7 @@ private:
|
|||
|
||||
JS::GCPtr<FetchParams> m_fetch_params;
|
||||
|
||||
HashMap<u64, int> m_ongoing_fetch_tasks;
|
||||
HashMap<u64, HTML::TaskID> m_ongoing_fetch_tasks;
|
||||
u64 m_next_fetch_task_id { 0 };
|
||||
};
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
// https://fetch.spec.whatwg.org/#queue-a-fetch-task
|
||||
int queue_fetch_task(JS::Object& task_destination, JS::NonnullGCPtr<JS::HeapFunction<void()>> algorithm)
|
||||
HTML::TaskID queue_fetch_task(JS::Object& task_destination, JS::NonnullGCPtr<JS::HeapFunction<void()>> algorithm)
|
||||
{
|
||||
// FIXME: 1. If taskDestination is a parallel queue, then enqueue algorithm to taskDestination.
|
||||
|
||||
|
@ -21,18 +21,18 @@ int queue_fetch_task(JS::Object& task_destination, JS::NonnullGCPtr<JS::HeapFunc
|
|||
|
||||
// AD-HOC: This overload allows tracking the queued task within the fetch controller so that we may cancel queued tasks
|
||||
// when the spec indicates that we must stop an ongoing fetch.
|
||||
int queue_fetch_task(JS::NonnullGCPtr<FetchController> fetch_controller, JS::Object& task_destination, JS::NonnullGCPtr<JS::HeapFunction<void()>> algorithm)
|
||||
HTML::TaskID queue_fetch_task(JS::NonnullGCPtr<FetchController> fetch_controller, JS::Object& task_destination, JS::NonnullGCPtr<JS::HeapFunction<void()>> algorithm)
|
||||
{
|
||||
auto fetch_task_id = fetch_controller->next_fetch_task_id();
|
||||
|
||||
auto& heap = task_destination.heap();
|
||||
int event_id = queue_fetch_task(task_destination, JS::create_heap_function(heap, [fetch_controller, fetch_task_id, algorithm]() {
|
||||
auto html_task_id = queue_fetch_task(task_destination, JS::create_heap_function(heap, [fetch_controller, fetch_task_id, algorithm]() {
|
||||
fetch_controller->fetch_task_complete(fetch_task_id);
|
||||
algorithm->function()();
|
||||
}));
|
||||
|
||||
fetch_controller->fetch_task_queued(fetch_task_id, event_id);
|
||||
return event_id;
|
||||
fetch_controller->fetch_task_queued(fetch_task_id, html_task_id);
|
||||
return html_task_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,13 +11,14 @@
|
|||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibJS/SafeFunction.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/EventLoop/Task.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
// FIXME: 'or a parallel queue'
|
||||
using TaskDestination = Variant<Empty, JS::NonnullGCPtr<JS::Object>>;
|
||||
|
||||
int queue_fetch_task(JS::Object&, JS::NonnullGCPtr<JS::HeapFunction<void()>>);
|
||||
int queue_fetch_task(JS::NonnullGCPtr<FetchController>, JS::Object&, JS::NonnullGCPtr<JS::HeapFunction<void()>>);
|
||||
HTML::TaskID queue_fetch_task(JS::Object&, JS::NonnullGCPtr<JS::HeapFunction<void()>>);
|
||||
HTML::TaskID queue_fetch_task(JS::NonnullGCPtr<FetchController>, JS::Object&, JS::NonnullGCPtr<JS::HeapFunction<void()>>);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue