diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cpp index 2812a2578ec..7acb71c74c3 100644 --- a/Libraries/LibWeb/ServiceWorker/Job.cpp +++ b/Libraries/LibWeb/ServiceWorker/Job.cpp @@ -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) { // 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) // 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 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) 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. diff --git a/Libraries/LibWeb/ServiceWorker/Registration.h b/Libraries/LibWeb/ServiceWorker/Registration.h index f9ef66c7d1a..ce4c4c6ed17 100644 --- a/Libraries/LibWeb/ServiceWorker/Registration.h +++ b/Libraries/LibWeb/ServiceWorker/Registration.h @@ -41,6 +41,7 @@ public: StorageAPI::StorageKey const& storage_key() const { return m_storage_key; } URL::URL const& scope_url() const { return m_scope_url; } 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; }