LibWeb/ServiceWorker: Immediately finish job if resources didn't change

This commit is contained in:
Shannon Booth 2025-04-08 17:26:30 +12:00 committed by Andrew Kaster
commit 9bc022c229
Notes: github-actions[bot] 2025-04-21 21:27:59 +00:00
2 changed files with 16 additions and 2 deletions

View file

@ -171,7 +171,7 @@ private:
bool m_has_updated_resources { false };
};
// https://w3c.github.io/ServiceWorker/#update
// https://w3c.github.io/ServiceWorker/#update-algorithm
static void update(JS::VM& vm, GC::Ref<Job> job)
{
// 1. Let registration be the result of running Get Registration given jobs storage key and jobs scope url.
@ -375,7 +375,7 @@ static void update(JS::VM& vm, GC::Ref<Job> job)
// When the algorithm asynchronously completes, continue the rest of these steps, with script being the asynchronous completion value.
auto on_fetch_complete = HTML::create_on_fetch_script_complete(vm.heap(), [job, newest_worker, state, &registration = *registration, &vm](GC::Ptr<HTML::Script> script) -> void {
// If script is null or Is Async Module with scripts record, scripts base URL, and « » is true, then:
// 8. If script is null or Is Async Module with scripts record, scripts base URL, and « » is true, then:
// FIXME: Reject async modules
if (!script) {
// 1. Invoke Reject Job Promise with job and TypeError.
@ -390,6 +390,19 @@ static void update(JS::VM& vm, GC::Ref<Job> job)
return;
}
// 9. If hasUpdatedResources is false, then:
if (!state->has_updated_resources()) {
// 1. Set registrations update via cache mode to jobs update via cache mode.
registration.set_update_via_cache(job->update_via_cache);
// 2. Invoke Resolve Job Promise with job and registration.
resolve_job_promise(job, registration);
// 3. Invoke Finish Job with job and abort these steps.
finish_job(vm, job);
return;
}
// FIXME: Actually create service worker
// 10. Let worker be a new service worker.
// 11. Set workers script url to jobs script url, workers script resource to script, workers type to jobs worker type, and workers script resource map to updatedResourceMap.