mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb/ServiceWorker: Immediately finish job if resources didn't change
This commit is contained in:
parent
63f17a4f12
commit
9bc022c229
Notes:
github-actions[bot]
2025-04-21 21:27:59 +00:00
Author: https://github.com/shannonbooth
Commit: 9bc022c229
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4279
Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 16 additions and 2 deletions
|
@ -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 job’s storage key and job’s 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, ®istration = *registration, &vm](GC::Ptr<HTML::Script> script) -> void {
|
||||
// If script is null or Is Async Module with script’s record, script’s base URL, and « » is true, then:
|
||||
// 8. If script is null or Is Async Module with script’s record, script’s 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 registration’s update via cache mode to job’s 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 worker’s script url to job’s script url, worker’s script resource to script, worker’s type to job’s worker type, and worker’s script resource map to updatedResourceMap.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue