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 }; 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) 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. // 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. // 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 { 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 // FIXME: Reject async modules
if (!script) { if (!script) {
// 1. Invoke Reject Job Promise with job and TypeError. // 1. Invoke Reject Job Promise with job and TypeError.
@ -390,6 +390,19 @@ static void update(JS::VM& vm, GC::Ref<Job> job)
return; 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 // FIXME: Actually create service worker
// 10. Let worker be a new 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. // 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.

View file

@ -41,6 +41,7 @@ public:
StorageAPI::StorageKey const& storage_key() const { return m_storage_key; } StorageAPI::StorageKey const& storage_key() const { return m_storage_key; }
URL::URL const& scope_url() const { return m_scope_url; } URL::URL const& scope_url() const { return m_scope_url; }
Bindings::ServiceWorkerUpdateViaCache update_via_cache() const { return m_update_via_cache_mode; } Bindings::ServiceWorkerUpdateViaCache update_via_cache() const { return m_update_via_cache_mode; }
void set_update_via_cache(Bindings::ServiceWorkerUpdateViaCache update_visa_cache_mode) { m_update_via_cache_mode = update_visa_cache_mode; }
void set_last_update_check_time(MonotonicTime time) { m_last_update_check_time = time; } void set_last_update_check_time(MonotonicTime time) { m_last_update_check_time = time; }