mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 01:59:31 +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 };
|
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 job’s storage key and job’s scope url.
|
// 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.
|
// 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 {
|
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
|
// 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 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
|
// FIXME: Actually create service worker
|
||||||
// 10. Let worker be a new 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.
|
// 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.
|
||||||
|
|
|
@ -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; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue