* @see https://w3c.github.io/ServiceWorker/#batch-cache-operations-algorithm * @param {CacheBatchOperation[]} operations * @returns {requestResponseList}
(operations)
| 62025 | }); |
| 62026 | return promise.promise; |
| 62027 | } |
| 62028 | /** |
| 62029 | * @see https://w3c.github.io/ServiceWorker/#batch-cache-operations-algorithm |
| 62030 | * @param {CacheBatchOperation[]} operations |
| 62031 | * @returns {requestResponseList} |
| 62032 | */ |
| 62033 | #batchCacheOperations(operations) { |
| 62034 | const cache = this.#relevantRequestResponseList; |
| 62035 | const backupCache = [...cache]; |
| 62036 | const addedItems = []; |
| 62037 | const resultList = []; |
| 62038 | try { |
| 62039 | for (const operation of operations) { |
| 62040 | if (operation.type !== "delete" && operation.type !== "put") { |
| 62041 | throw webidl.errors.exception({ |
| 62042 | header: "Cache.#batchCacheOperations", |
| 62043 | message: 'operation type does not match "delete" or "put"' |
| 62044 | }); |
| 62045 | } |
| 62046 | if (operation.type === "delete" && operation.response != null) { |
| 62047 | throw webidl.errors.exception({ |
| 62048 | header: "Cache.#batchCacheOperations", |
| 62049 | message: "delete operation should not have an associated response" |
| 62050 | }); |
| 62051 | } |
| 62052 | if (this.#queryCache(operation.request, operation.options, addedItems).length) { |
| 62053 | throw new DOMException("???", "InvalidStateError"); |
| 62054 | } |
| 62055 | let requestResponses; |
| 62056 | if (operation.type === "delete") { |
| 62057 | requestResponses = this.#queryCache(operation.request, operation.options); |
| 62058 | if (requestResponses.length === 0) { |
| 62059 | return []; |
| 62060 | } |
| 62061 | for (const requestResponse of requestResponses) { |
| 62062 | const idx = cache.indexOf(requestResponse); |
| 62063 | assert2(idx !== -1); |
| 62064 | cache.splice(idx, 1); |
| 62065 | } |
| 62066 | } else if (operation.type === "put") { |
| 62067 | if (operation.response == null) { |
| 62068 | throw webidl.errors.exception({ |
| 62069 | header: "Cache.#batchCacheOperations", |
| 62070 | message: "put operation should have an associated response" |
| 62071 | }); |
| 62072 | } |
| 62073 | const r3 = operation.request; |
| 62074 | if (!urlIsHttpHttpsScheme(r3.url)) { |
| 62075 | throw webidl.errors.exception({ |
| 62076 | header: "Cache.#batchCacheOperations", |
| 62077 | message: "expected http or https scheme" |
| 62078 | }); |
| 62079 | } |
| 62080 | if (r3.method !== "GET") { |
| 62081 | throw webidl.errors.exception({ |
| 62082 | header: "Cache.#batchCacheOperations", |
| 62083 | message: "not get method" |
| 62084 | }); |
no test coverage detected